Call Contract Example
Parameters
contractAddress
-string
Contract address to interact withfunctionName
-string
Smart contract function to interact withabi
-Array<AbiItem>
(Optional) ABI of the contract to callparams
-Array<string>
(Optional) Params to call the smart contract function withvalueInWei
-string
(Optional) Amount of wei to sendgasLimit
-string
(Optional) Gas limit for the function callchain
-Object
used to ensure the user is on the correct chain (follows the MetaMask specification)chainId
-string
Base 10 string matching the chain id on ChainlistchainMetadata
(Optional) -Object
used to add the chain if the user does not have the chain added to their walletchainName
-string
nativeCurrency
-Object
name
-string
is the currency's namesymbol
-string
2-6 characters long symbol for the chaindecimals
-18
rpcUrls
-Array<string>
is an array of rpc node urls that can be used to make requests. We recommend selecting a few from the listing on ChainlistblockExplorerUrls
(Optional) -Array<string>
is an array of block explorers that can be used with the chainiconUrls
(Optional) -Array<string>
is currently unused by MetaMask
Request
This request reads the name of a contract.
curl --location --request POST "localhost:9680/callContract" \
--header 'Content-Type: application/json' \
--data-raw '{
"contractAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"functionName": "totalSupply",
"params": [],
"abi": [
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
],
"chain": { "chainId": "1", "chainMetadata": { "chainName": "Ethereum", "nativeCurrency": { "name": "ETH", "symbol": "ETH", "decimals": 18 }, "rpcUrls": ["https://rpc.ankr.com/eth"] } }
}'
Response
The response value(s) of the smart contract method are mixed. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices:
"FaucetToken"
Last updated