Read
Introduction
Read functions, also known as 'view' functions, retrieve data from the blockchain.
It is also important to note that invoking a read function does not create a transaction, and as a result:
- No signing is required
- It does not alter the state of the blockchain
- It is executed on a single node
- It does not cost any fees
This guide explains the process of invoking a read smart contract function.
Prerequisites
- Create an account and generate your application's API keys
Create an account on Quant Connect. Then, register your application to generate API keys to authorise your requests on Overledger APIs.
- Generate a Bearer Token You must generate an authentication token in order to use the Overledger APIs.
- Reading data from a smart contract also requires a contract address, regardless of ownership.
Choose the function to be invoked
List of read APIs
The ERC-20 and ERC-721 standards define specific functions for retrieving data from tokens. These functions are marked as 'external view', indicating they can be called without modifying the blockchain state.
Call the Smart Contract Read endpoint
For details on calling the read smart contract endpoint, please refer to the API reference
Below is a sample request for a smart contract read where we call the function 'balanceOf' to get the balance of a token for a specific user address:
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 '
{
"location": {
"technology": "ethereum",
"network": "ethereum goerli testnet"
},
"functionName": "balanceOf",
"smartContractId": "0xb0D693d6e0e3A31A55510728Cc815c02F6A3bf64"
}
'
Sample response of a smart contract read:
{
"location": {
"technology": "ethereum",
"network": "ethereum goerli testnet"
},
"functionName": "balanceOf",
"smartContractId": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"outputParameters": [
{
"type": "uint256",
"value": 1000000
}
]
}
Updated 6 months ago