Skip to main content

Run contract function

POSThttps://deep-index.moralis.io/api/v2/:address/function

Run a given function of a contract ABI and retrieve readonly data.

PATH PARAMS
addressstringrequired
The address of the contract
QUERY PARAMS
chainstring
The chain to query
function_namestringrequired
The function name of the contract
BODY PARAM
abijson
The contract ABI
paramsjson
The params for the given function
Responses
API KEY
import Moralis  from 'moralis';
import { EvmChain } from '@moralisweb3/evm-utils';

try {
const abi = []; // Add ABI

const functionName = 'balanceOf';

const address = '0x1234567890123456789012345678901234567890';

const chain = EvmChain.ETHEREUM;

await Moralis.start({
apiKey: 'YOUR_API_KEY',
// ...and any other configuration
});

const response = await Moralis.EvmApi.utils.runContractFunction({
abi,
functionName,
address,
chain,
});

console.log(response?.result);
} catch (e) {
console.error(e);
}
Response Example
Empty