Call a smart contract method
This guide will walk you through the process of calling a smart contract method using the MARCO API.
Before you begin
Before you start, complete the following prerequisites:
- Get your API tokens
- Create a wallet
- Authorize wallet access to the service account
- Deploy a smart contract
- Authorize a service account access to use a smart contract
Step by step
This guide presumes that you have successfully deployed a smart contract—let's say one named a smart contract named SCI-8FbUlJFG-VY
—on the finboot-clique-v1
network that has method named update
:
// A public function that accepts a string argument and updates the `message` storage variable.
function update(string memory newMessage) public {
message = newMessage;
}
To call the smart contract method, send a POST
request to the Send GLO endpoint as follows:
curl --location --request POST 'https://api-marco.finboot.com/v1/ledger-ops/contract/call' \
--header 'ApplicationToken: <APPLICATION_TOKEN>' \
--header 'Authorization: Bearer <ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"dependencies": [],
"intent": "<INTENT_UUID>",
"glo": {
"version": "0.1.0",
"type": "contract_call",
"options": {
"contract_instance": {
"lookup_service": {
"type": "marco",
"value": "marco"
},
"resource": "<SMART_CONTRACT_INSTANCE_ID>"
},
"method_name": "<SMART_CONTRACT_METHOD_NAME>",
"args": [<ARG_0>]
},
"meta": {}
},
"walletId": "<SENDER_WALLET_ID>",
"walletPassword": "<SENDER_WALLET_PASSWORD>"
}'
Replace:
INTENT_UUID
: An Universally Unique Identifier (UUID) is a 128-bit string represented in hexadecimal that uniquely identifies an action or a group of actions. UUIDs are typically generated using algorithms that ensure their uniqueness. An example of a valid UUID isf1b0c9e0-9f1e-4c4e-8b1a-9b0b9b9b9b9b
. If you need to generate UUIDs for testing purposes, you can use an online tool such as UUID generator.APPLICATION_TOKEN
: The marpp token. For guidance on obtaining this token, see the Quickstart guide.ACCESS_TOKEN
: The access token. For guidance on obtaining this token, see the Quickstart guide.SMART_CONTRACT_INSTANCE_ID
: The resource ID of the smart contract instance you want to interact with. For example,SCI-8FbUlJFG-VY
.SMART_CONTRACT_METHOD_NAME
: The name of the method you want to call. For example,update
.ARG0
: The list of arguments to be passed to the method. For instance, theupdate
function requires just one parameter, such as "Hello World!". Be aware that it is possible to pass multiple arguments using theglo.args
array.SENDER_WALLET_ID
: The resource ID of the wallet that will call the smart contract. For example,WAL-62EPFgDCGOM
.SENDER_WALET_PASSWORD
: The password of theSENDER_WALLET_ID
.
Once the request is sent, the API returns an action ID and its status:
{
"id": "ac4d8d94-86e9-48b3-a8f1-12fad3b8e1d3",
"status": "PENDING"
}
Next step
To retrieve the details of the smart contract method call, follow to the Query the ledger guide.