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.
Task<dynamic> CallGenericReadFunction(dynamic args)
Parameter | Type | Definition |
---|---|---|
args.contractAddress | String | Contract address of the smart contract to be called |
args.functionABI | String | The path to the JSON object for the smart contract ABI. You can store it in the Resources folder and pass in a path such as @"Assets/Resources/Contracts/Contract.json" |
args.functionName | String | Name of the function to be called as per the ABI. |
args.chain | Metafi.Unity.Chain | |
args.params | List<object> | 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. |
dynamic
object returned from smart contract.{
data = {
...
},
error = "",
}
Applicable to EVM Chains only
While passing in large numerical values (values above 9007199254740991) in
args.params
, a conversion to string format needs to be made. You can use the following methods that convert the number to the appropriate format:// For int values
string ConvertNumberToBigNumber(int value, int decimals);
// For double values
string ConvertNumberToBigNumber(double value, int decimals);
// For float values
string ConvertNumberToBigNumber(float value, int decimals);
1
using System;
2
using Metafi.Unity;
3
4
public class GameManager : MonoBehaviour {
5
public async void ReadSmartContractData(){
6
var res = await MetafiProvider.Instance.CallGenericReadFunction( new {
7
contractAddress = "contract-address",
8
functionABIPath = "path-to-abi",
9
functionName = "readMetadata",
10
@params = new object ["param1", "param2"],
11
chain = Chains.MUMBAI,
12
});
13
}
14
}
Last modified 3mo ago