CallGenericReadFunction
This function does not trigger a UI modal
This allows you to call any read-only smart contract function that does not require the user signature. It can be invoked even before the user is logged in.
async CallGenericReadFunction(args)
Parameter | Type | Definition |
---|---|---|
args.contractAddress | String | Contract address of the smart contract to be called |
args.functionABI | JSON | |
args.functionName | String | Name of the function to be called |
args.chain | chain (class) | |
args.params | array | Array of objects that will be sent as the arguments to the smart contract function. Please ensure that the order of params matches the contract ABI.
For large numerical inputs, please refer to the section below. |
Object returned from smart contract.
{
"statusCode": 1/0,
"data": {
...
}
}
Applicable to EVM Chains only
While passing in large numerical values (values above 9007199254740991) in
args.params
, a conversion to BigNumber format needs to be made. You can use the following methods that convert the number to and from the appropriate format:ConvertNumberToBigNumber(number, decimal)
- Use this method while passing in numbers as params to a smart function that requires uint256 numbersConvertBigNumberToNumber(bigNumber, decimal)
- Use this method while converting response values from a smart contract function call (which are in bigNumber format) to a JS Number1
import { useMetafi, chains } from '@metafi/react-sdk';
2
import stakeContractAbi from '../contracts/abi/stakeContract.json'
3
4
function StakeUSDC(user_uuid) {
5
const { CallGenericReadFunction } = useMetafi();
6
7
stakeContractAddress = "0xF5C9F957705bea56a7e806943f98F7877B995826"
8
9
const stakedBalance = () => {
10
let stakedValue = await CallGenericReadFunction({
11
chain: chains.eth,
12
contractAddress: stakeContractAddress,
13
functionABI: stakeContractAbi.abi,
14
functionName: "getStakedAmount",
15
params: ["0x40562Cf2E90f23b3969d782B5d8f134A77069b49"],
16
});
17
console.log('staked value is', stakedValue)
18
}
19
20
return (
21
<>
22
<button onClick={stakedBalance}>Get User Staked Balance</button>
23
</>
24
);
25
};
Last modified 7mo ago