Skip to main content

Call a smart contract method

In this guide, you will learn how to call a smart contract method using the MARCO API.

Scenario

This guide presumes that you have successfully deployed a smart contract—let's say one 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;
}

Prerequisites

Before you start, complete the following prerequisites:

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 Contract Call 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 '{
"contractId": "<SMART_CONTRACT_GROUP_ID>:<SMART_CONTRACT_INSTANCE_ID>",
"method": "<SMART_CONTRACT_METHOD_NAME>",
"params": ["<PARAM_0>"]
"options": {
"marco": {
"intent": "<INTENT_UUID>",
"walletId": "<SENDER_WALLET_ID>",
"dependencies": []
"tag": "<TAG>",
},
"plugin": {
"walletPassword": "<SENDER_WALLET_PASSWORD>"
}
}
}'

Replace:

  • 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_GROUP_ID: The resource ID of the contract group, if you have followed the above step, this will be the groupId from the previous query's response.
  • 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.
  • PARAM_0 (optional): The list of arguments to be passed to the method. For instance, the update function requires just one parameter, such as "Hello World!". Be aware that it is possible to pass multiple arguments using the params array.
  • INTENT_UUID (optional): 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 is f1b0c9e0-9f1e-4c4e-8b1a-9b0b9b9b9b9b. If you need to generate UUIDs for testing purposes, you can use an online tool such as UUID generator.
  • SENDER_WALLET_ID: The resource ID of the wallet that will call the smart contract. For example, WAL-62EPFgDCGOM.
  • TAG (optional): A string used for categorizing and identifying the request. This is a string identifier that can be used for labeling or categorizing the request.
  • SENDER_WALET_PASSWORD: The password of the SENDER_WALLET_ID.

Once the request is sent, the API returns an action ID and its status:

{
"actionId": "3dd80efc-3538-4a5e-9b31-4075565a4022",
"intent": "e3c8e28d-9a6f-4aed-8a3f-faa4e538b2df",
"status": "PENDING"
}

Next step

To retrieve the details of the smart contract method call, follow to the Search transactions guide.