Skip to main content

Common task quick reference

This guide provides a quick reference for the most common API calls:

  • Check account balances
  • Transfer coins
  • Deploy smart contracts

Regardless of the method you choose, each task requires you to connect to an appropriate network endpoint with a payload in the expected format. The payload contains all of the information required to complete the task. The difference between using the API directly or the abstraction provided by the Kadena CLI or Kadena.js libraries is simply in how you deliver the request.

Check account balances

Call the coin.get-balance function with the account name string as an argument using curl and a JSON object. For principal accounts, the account name starts with a prefix. For example, the k: prefix for single key accounts or the w: prefix for accounts with multiple keys.

curl -X POST "https://api.chainweb.com/chainweb/0.0/testnet04/chain/1/pact/api/v1/local" \
-H "Content-Type: application/json" \
-d '{
"exec": {
"data": {},
"code": "(coin.get-balance \"k:<account-public-key>\")"
},
"meta": {
"chainId": "1",
"sender": "k:<account-public-key>",
"gasLimit": 100000,
"gasPrice": 0.0000001,
"ttl": 7200
}
}'

Transfer coins

Call the coin.transfer function with the sender, receiver, and amount as arguments using curl and a JSON object.

  curl -X POST "https://api.chainweb.com/chainweb/0.0/testnet04/chain/1/pact/api/v1/send" \
-H "Content-Type: application/json" \
-d '{
"cmds": [{
"hash": "<transaction-hash>",
"sigs": ["<your-signature>"],
"cmd": "{\"networkId\":\"testnet04\",\"payload\":{\"exec\":{\"data\":{\"amount\":10.0,\"receiver\":\"k:<receiver-public-key>\"},\
"code\":\"(coin.transfer \\\"k:<sender-public-key>\",\"clist\":
[{\"args\":[\"k:<sender-public-key>\",\"k:<receiver-public-key>\",10.0],\"name\":
\"coin.TRANSFER\"}]}],\"meta\":{\"creationTime\":1724384042,\"ttl\":7200,\"gasLimit\":100000,\"chainId\":\"1\",\"gasPrice\":
1.0e-7,\"sender\":\"k:<sender-public-key>\"},\"nonce\":\"2024-08-23 03:34:02.198258 UTC\"}"
}]
}'

Deploy smart contracts

Connect to the Pact API send endpoint to submit a transaction that deploys a smart contract.

curl -X POST "https://api.chainweb.com/chainweb/0.0/testnet04/chain/1/pact/api/v1/send" \
-H "Content-Type: application/json" \
-d '{
"cmds": [{
"hash": "<transaction-hash>",
"sigs": ["<your-signature>"],
"cmd": "{\"networkId\":\"testnet04\",\"payload\":{\"exec\":{\"data\":{},\"code\":\"(namespace \'free)\n(define-keyset \'free.vote-testing-keyset
(read-keyset \'vote))\n(module vote-testing \'free.vote-testing-keyset\n (defschema vote\n voter:string\n option:string)\n (deftable votes:{vote})\n
(defun vote (poll-id:string option:string)\n (insert votes (format \"{}-{}\" [poll-id (at \'sender (chain-data))])\n { \"voter\": (at \'sender (chain-data))\n
\"option\": option\n }\n )\n )\n)\"}},\"signers\":[{\"pubKey\":\"f1e12312e4ee8c156b041c3bcc7e422e7d15cb2ddce58c6ff16742770916cfaa\",\
"clist\":[{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":1724384042,\"ttl\":7200,\"gasLimit\":100000,\"chainId\":\"1\",\
"gasPrice\":1.0e-7,\"sender\":\"k:f1e12312e4ee8c156b041c3bcc7e422e7d15cb2ddce58c6ff16742770916cfaa\"},\"nonce\":\"2024-08-23 03:34:02.198258 UTC\"}"
}]
}'