Smart Contract

What is a smart contract?

A smart contract is a self-executing program that automates the actions.

This endpoint can be used to call the read functions on a smart contract, eg. owner. This search endpoint can be used to call any custom read functions on your smart contract.

This guide is designed to walk you through the steps needed to do a smart contract query.

There are 2 approaches to performing a search on a smart contract. Option 1 (using Overledger V3) is the recommended approach.

Prerequisites

  • Obtain an authorization token
    You must obtain an authorisation token to interact with Overledger's API and call any endpoint. This token will authenticate your requests and grant you access to the necessary endpoints. Please follow the authentication process provided by Overledger to get your authorisation token.

Option 1 (Recommended)

Call the endpoint

As an example, if you want to call the balanceOf function on the smart contract 0xbe7e4990ac053b79862e264398cc2637174af12e, make a call to the endpoint /api/smart-contracts/read, with the following request body:

curl --request POST \
     --url https://api.sandbox.overledger.io/api/smart-contracts/read \
     --header 'API-Version: 3.0.0' \
     --header 'Authorization: Bearer token' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "functionName": "balanceOf",
  "smartContractId": "0xbe7e4990ac053b79862e264398cc2637174af12e",
  "outputParameters": [
    {
      "type": "uint256"
    }
  ],
  "inputParameters": [
    {
      "value": {
        "newKey": "0xF9cd6C86992Fce1481dBc4bDB7E1b101c1e8cEE2"
      },
      "type": "address"
    }
  ]
}
'

📘

Replace the input and output parameters with what is expected by the function. In this case function balanceOf expects an address as input. It gives back the balance in uint256 format, hence its set as the type under output parameter type.

If the request is successful, you will receive a response with the smart contract details, as below:

{
    "location": {
        "technology": "ethereum",
        "network": "ethereum sepolia testnet"
    },
    "smartContractId": "0xbe7e4990ac053b79862e264398cc2637174af12e",
    "functionName": "balanceOf",
    "outputParameters": [
        {
            "value": 0,
            "type": "uint256"
        }
    ]
}

In the above response, outputParameters.value represents the balance of the address.


Option 2

Call the endpoint

As an example, if you want to call the owner function on the smart contract0xbe7e4990ac053b79862e264398cc2637174af12e, make a call to the endpoint /v2/autoexecution/search/smartcontract, with the following request body:

curl --request POST \
     --url https://api.sandbox.overledger.io/v2/autoexecution/search/smartcontract \
     --header 'Authorization: Bearer token' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
    "location": {
        "technology": "Ethereum",
        "network": "ethereum sepolia Testnet"
    },
    "requestDetails": {
        "destination": [
            {
                "smartContract": {
                    "smartContractId": "0xbe7e4990ac053b79862e264398cc2637174af12e",
                    "function": {
                        "name": "owner",
                        "inputParameters": [
                        ],
                        "outputParameters": [
                            {
                                "type": "address"
                            }
                        ]
                    }
                }
            }
        ]
    }
}

Note: Replace the input and output parameters with what is expected by the function. In this case function owner does not expect any input parameters. It gives back an address as a response, hence it's part of the output parameters.

If the request is successful, you will receive a response with the smart contract details, as below:

{
    "preparationSmartContractSearchResponse": {
        "requestId": "fbb5866a-c091-41a9-add8-3d5d2302edc5",
        "gatewayFee": {
            "amount": "0",
            "unit": "QNT"
        }
    },
    "executionSmartContractSearchResponse": {
        "location": {
            "technology": "Ethereum",
            "network": "ethereum sepolia testnet"
        },
        "smartContract": {
            "smartContractId": "0xbe7e4990ac053b79862e264398cc2637174af12e",
            "function": {
                "functionId": "0x8da5cb5b",
                "name": "owner",
                "inputParameters": [],
                "outputParameters": [
                    {
                        "value": "0x6e32da6edbea6b4c794cd50c830753f9b134def0",
                        "type": "address"
                    }
                ]
            }
        }
    }
}

In the above response, outputParameters.value represents the owner of the smart contract.