Last updated
Building a simple transaction from the contract
Take a look at https://github.com/kadena-community/kadena.js/blob/main/packages/libs/client-examples/src/example-contract/simple-transfer.ts for a complete example.
Now that everything is bootstrapped, we can start building transactions.
Create a new file and name it transfer.ts (or .js):
ts
import { Pact } from '@kadena/client'; const unsignedTransaction = Pact.builder .execution( Pact.modules.coin.transfer('k:your-pubkey', 'k:receiver-pubkey', { decimal: '231', }), ) .addSigner('your-pubkey', (withCapability) => [ // add necessary coin.GAS capability (this defines who pays the gas) withCapability('coin.GAS'), // add necessary coin.TRANSFER capability withCapability('coin.TRANSFER', 'k:your-pubkey', 'k:receiver-pubkey', { decimal: '231', }), ]) .setMeta({ chainId: '1', senderAccount: 'your-pubkey' }) .setNetworkId('mainnet01') .createTransaction(); ts
import { Pact } from '@kadena/client'; const unsignedTransaction = Pact.builder .execution( Pact.modules.coin.transfer('k:your-pubkey', 'k:receiver-pubkey', { decimal: '231', }), ) .addSigner('your-pubkey', (withCapability) => [ // add necessary coin.GAS capability (this defines who pays the gas) withCapability('coin.GAS'), // add necessary coin.TRANSFER capability withCapability('coin.TRANSFER', 'k:your-pubkey', 'k:receiver-pubkey', { decimal: '231', }), ]) .setMeta({ chainId: '1', senderAccount: 'your-pubkey' }) .setNetworkId('mainnet01') .createTransaction();Notes
- Namespaced arguments (
k:,w:etc) are account names, where non-namespaced arguments are assumed to be public keys. - The contract doesn't specify whether you need to pass an account name or public key. This is knowledge that can be obtained by inspecting the contract downloaded earlier or consulting the documentation for the contract.
- The
addSignerfunction accepts thepublic-keyof the signer and let signer add the capabilities they want to sign for. Note thatcoin.GASdoesn't have any arguments, butcoin.TRANSFERdoes. - The
setMetaargument object has asenderAccountproperty. This is anaccountand could begas stationaccount in some scenarios. - To add an Unrestricted Signer (Unscoped Signature ), call
addSignerwithout extra arguments