Approve a spender
This section will show you how to use the ICRC Rosetta implementation to authorize a spender to spend your ICRC-1 tokens. Make sure you are familiar with the flow of operations for Rosetta.
The request types used for making direct transfers are APPROVE
and SPENDER
. They consist of two operations, one for the the approve operation and another for the spender operation.
You do not have to specify the FEE
operation, although the FEE
of the ICRC-1 ledger FEE
will be deducted automatically by Rosetta.
Calls may include a FEE
operation to not overlook unexpected debit operations.
Prerequisites
- Make sure you are familiar with the flow of operations for Rosetta.
Example
An example of the minimum set of operations that is sent to the construction/payloads
endpoint can be found below.
In this example, you are approving the principal xmiu5-jqaaa-aaaag-qbz7q-cai
to spend up to 10 e8 ckBTC from principal iowfl-yzooa-br3dt-77erl-nlm7f-kplhq-php75-hw3an-aeqn2-swh4t-3qe
.
curl --location '0.0.0.0:8082/construction/payloads' --header 'Content-Type: application/json' --data '{
"network_identifier": {
"blockchain": "Internet Computer",
"network": "mc6ru-gyaaa-aaaar-qaaaq-cai"
},
"public_keys": [
{
"hex_bytes": "047a83e378053f87b49aeae53b3ed274c8b2ffbe59d9a51e3c4d850ca8ac1684f7131b778317c0db04de661c7d08321d60c0507868af41fe3150d21b3c6c757367",
"curve_type": "secp256k1"
}
],
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "APPROVE",
"account": {
"address": "iowfl-yzooa-br3dt-77erl-nlm7f-kplhq-php75-hw3an-aeqn2-swh4t-3qe",
"sub_account": {
"address": "0000000000000000000000000000000000000000000000000000000000000000"
}
},
"amount": null,
"metadata": {
"allowance": {
"value": "10",
"currency": {
"symbol": "ckBTC",
"decimals": 8
}
},
"expected_allowance": null,
"expires_at": null
}
},
{
"operation_identifier": {
"index": 1
},
"type": "SPENDER",
"account": {
"address": "xmiu5-jqaaa-aaaag-qbz7q-cai",
"sub_account": {
"address": "0000000000000000000000000000000000000000000000000000000000000000"
}
}
}
],
"metadata": null
}'