SpireKey SDK
The SpireKey SDK allows your dApp to seamlessly integrate with SpireKey.
Quick start
Install the sdk with:
pnpm add @kadena/spirekey-sdk
Connect an account to your dApp:
import { connect } from '@kadena/spirekey-sdk';
const someHandler = async () => {
try {
const account = await connect('testnet04', '5');
} catch (error) {
console.warn('User canceled signin', error);
}
await account.isReady();
};
Sign for an transaction:
import { connect } from '@kadena/spirekey-sdk';
const someHandler = async () => {
const account = yourConnectedAccount;
const tx = yourTransaction;
try {
const { transactions, isReady } = await sign(
[tx],
[
{
accountName: account.accountName,
networkId: account.networkId,
chainIds: account.chainIds,
requestedFungibles: [
{
fungible: 'coin',
amount: amount,
target: '5',
},
],
},
],
);
} catch (error) {
console.warn('User canceled signing');
}
await isReady();
transactions.map(async (tx) => {
const res = await client.submit(tx);
client.pollOne(res);
});
};
connect(networkId: string, chainId: ChainId)
To connect an account you need to provide the networkId and chainId.
SpireKey will then take care of making the account available on that networkId
and chainId. If your dApp relies on the account existing on the provided
networkId and chainId combination, you can wait for the account to be ready
before continuing.
import { connect } from '@kadena/spirekey-sdk';
const someHandler = async () => {
try {
const account = await connect('testnet04', '5');
} catch (error) {
console.warn('User canceled signin', error);
}
await account.isReady();
};
sign(transactionList: IUnsignedCommand[], accounts?: Account[])
You can sign one or more transactions using the sign function. Additionally if
your dApp requires the user(s) to have fungible tokens available for the
transaction, you can provide an array with the required fungible tokens
requirements. SpireKey will then prepare the account to have the tokens
transfered to the chain your dApp operates on and allow your dApp to be notified
when the transaction is ready.
import { connect } from '@kadena/spirekey-sdk';
const someHandler = async () => {
const account = yourConnectedAccount;
const tx = yourTransaction;
const { transactions, isReady } = await sign(
[tx],
[
{
accountName: account.accountName,
networkId: account.networkId,
chainIds: account.chainIds,
requestedFungibles: [
{
fungible: 'coin',
amount: amount,
target: '5',
},
],
},
],
);
await isReady();
transactions.map(async (tx) => {
const res = await client.submit(tx);
client.pollOne(res);
});
};
initSpireKey(config?: InitConfig)
The initSpireKey function is optional and can be used to configure the SDK to
target a different wallet using a config object. When omitted the SDK will
will use https://chainweaver.kadena.io.
If you do want to use a different host, you can provide it via the config:
InitConfig
Terms and Conditions
You are not required to accept this License, since you have not signed it.
However, nothing else grants you permission to modify or distribute the Program
or its derivative works. These actions are prohibited by law if you do not
accept this License. Therefore, by modifying or distributing the Program (or any
work based on the Program), you indicate your acceptance of this License to do
so, and all its terms and conditions for copying, distributing or modifying the
Program or works based on it.
Kadena Spirekey terms and conditions