Execute commands
Now we complete the task - sending some tokens that have been delegated to a key

As mentioned in the introduction, now we want to:
  1. 1.
    As the admin key (A)†, set an allowance for a key (B)
  2. 2.
    As the key with an allowance, send tokens from key (B) to key (C)
  3. 3.
    See tokens arrive at key (C)
  4. 4.
    See allowance decrease for key (B)
† this is the key that you used to instantiate, and set as an admin. If you are running a validator in the testnet, then it is probably your self-delegate key.

Using node, you can again encode the following arguments:
{
increase_allowance: {
spender: '<key-B>',
amount: {
denom: "usource",
amount: "2000000"
}
}
}
Then, as the admin key (A), increase key (B)'s allowance:
sourced tx wasm execute <contract-addr> \
'{"increase_allowance":{"spender":"<key-B>","amount":{"denom":"usource","amount":"2000000"}}}' \
--from <admin-key-A> \
--chain-id <chain-id> \
--gas-prices 0.1usource --gas auto --gas-adjustment 1.3 -b block
If you query its allowance, you should see a value of 2000000:
sourced query wasm contract-state smart <contract-addr> '{"allowance":{"spender":"<key-B>"}}' --chain-id <chain-id>
Should return:
data:
balance:
- amount: "2000000"
denom: usource
expires:
never: {}

First, query the balance of another key, that we did not allocate any tokens to (C):
sourced q bank balances <key-C>
Let's say it already has a balance of 500usource - the command will return:
balances:
- amount: "500"
denom: usource
pagination:
next_key: null
total: "0"
Then, we again need to encode some arguments to JSON for the send:
{
execute: {
msgs: [{
bank: {
send: {
to_address: "<key-C>",
amount: [{
denom: "usource",
amount: "500"
}]
}
}
}]
}
};
Once we have the JSON, we can shape an execute command:
sourced tx wasm execute <contract-addr> \
'{"execute":{"msgs":[{"bank":{"send":{"to_address":"<key-C>","amount":[{"denom":"usource","amount":"500"}]}}}]}}' \
--from <key-B> \
--chain-id <chain-id> \
--gas-prices 0.1usource --gas auto --gas-adjustment 1.3 -b block
Note that the --from flag is now signing this from the key (B) that the admin key (A) gave a token balance to. This CW1 Subkeys contract will only work with the native token of the chain, in this case usource.

If we query balance again:
sourced q bank balances <key-C>
We expect to see the balance incremented by 500usource:
balances:
- amount: "1000"
denom: usource
pagination:
next_key: null
total: "0"

Now, if we query the allowance for key B, we should see it has decreased by 500usource:
sourced query wasm contract-state smart <contract-addr> '{"allowance":{"spender":"<key-B>"}}' --chain-id <chain-id>
data:
balance:
- amount: "1999500"
denom: usource
expires:
never: {}
We're done!
Play around some more with increasing and decreasing allowances, or even adding expiries to allowances, to get a better feel for how this works.
Copy link
On this page
Running commands
1. Add allowance for key B
2. Send tokens from key B to key C
3. Check balance of key C
4. See allowance decrease for key B