CallGenericWriteFunction
This function triggers a modal for the user to confirm the transaction
This is an advanced feature and can drain user wallet funds if you interact with a malicious contract. Only link to trusted smart contract authors.
This allows you to call any smart contract function and process the response. This function should be used to query functions that require the users signature, hence it should be invoked only once the user is logged in.
CallGenericWriteFunction(args)
Parameter | Type | Definition |
---|---|---|
args.callback? | Function | Function to callback upon getting result from the smart contract function call
For numerical return values, please refer to the section below.
Structure of result object passed into callback function: 1 { 2 "status": 1/0, // success or fail 3 "error": "", // error string if any 4 "data": {any}, // data returned from the smart contract function call 5 } |
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.value? | Number | The value to be sent along with the smart contract invocation. Please refer to the section below for more information. |
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. |
None
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 { CallGenericWriteFunction } = useMetafi();
6
7
stakeContractAddress = "0xF5C9F957705bea56a7e806943f98F7877B995826"
8
const callback = (res) => {
9
console.log(res)
10
}
11
12
const stake = () => {
13
CallGenericWriteFunction({
14
callback: callback,
15
chain: chains.eth,
16
contractAddress: stakeContractAddress,
17
functionABI: stakeContractAbi.abi,
18
functionName: "stake",
19
value: 1,
20
params: [],
21
});
22
}
23
24
return (
25
<>
26
<button onClick={stake}>Stake ETH</button>
27
</>
28
);
29
};
Last modified 3mo ago