Register a smart contract
In this guide, you will learn how register a contract already deployed on a ledger using the MARCO API.
This process will make the contract accessible and manageable on the MARCO platform, whether it was deployed through Ledger ops APIs or other external methods.
Prerequisites
Before you start, complete the following prerequisites:
1. Create a contract group
A contract group works just as a folder to keep your smart contracts organized. In order to register a smart contract, you need first a contract group.
To create a contract group, send a POST
request to the Create contract group endpoint as follows:
curl --location --request POST 'https://api-marco.finboot.com/v1/contract-groups' \
--header 'ApplicationToken: <APPLICATION_TOKEN>' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <ACCESS_TOKEN>' \
--data '{
"projectId": "<PROJECT_ID>",
"name": "<NAME>"
}'
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.PROJECT_ID
: The resource ID of the project in which you are creating the contract group. For example,PRJ-7IKd2DrTtkI
. Note that the service account making the request must have access to this project.NAME
: A name of your choice to easily identify the contract group.
You will receive a response similar to the following:
{
"groupId": "SCG-p-wiZSEYYVw",
"name": "my contract group"
}
Save the groupId
for the following step.
2. Register a smart contract
To register a smart contract, send a POST
request to the Register a smart contract endpoint as follows:
curl --location --request POST 'https://api-marco.finboot.com/v1/contract-groups/instances' \
--header 'ApplicationToken: <APPLICATION_TOKEN>' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <ACCESS_TOKEN>' \
--data '{
"groupId": "<GROUP_ID>",
"name": "<NAME>",
"interface": "<ABI>",
"ledgerReference": {
"ledgerId": "<LEDGER_ID>",
"nativeReference": "<CONTRACT_ADDRESS>"
}
}'
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, ssee theGROUP_ID
: The resource ID of the contract group, if you have followed the above step, this will be thegroupId
from the previous query's response.NAME
: A name of your choice to easily identify the smart contract. For examplemy contract
.ABI
: The ABI of the smart contract. For example,'[{"inputs":[{"name":"value","type":"string"}],"type":"constructor"}]'
.LEDGER_ID
: The resource ID of the ledger where the contract is deployed. For example,LGR-3c8de984e49
.CONTRACT_ADDRESS
: The address or reference to the contract that you are registering. This refers to the blockchain native reference of the contract. If you deployed the smart contract using the MARCO Ledger Call API, use the Search Transaction API to get thecontractAddress
in the details of the action. For example,0xD5b93DDe1558EdFEF555f7f6d2CAfc44EEA658CA
You will receive a 201
response with the registered contract.
For more info about Smart Contracts Registry, see the Smart Contract Registry API.