Skip to main content

Building a simple transaction from the contract

Now that everything is bootstrapped, we can start building transactions.

Create a new file and name it transfer.ts (or .js):

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', sender: 'your-pubkey' })  .setNetworkId('mainnet01')  .createTransaction();
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', sender: '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 addSigner function accepts the public-key of the signer and let signer add the capabilities they want to sign for. Note that coin.GAS doesn't have any arguments, but coin.TRANSFER does.
  • The setMeta argument object has a sender property. This is a public-key and could be gas station address in some scenarios.
  • To add an Unrestricted Signer (Unscoped Signature ), call addSigner without extra arguments

Receive important developer updates