CallGenericReadFunction

This function does not trigger a UI modal

Description

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.

Details

Signature

Task<dynamic> CallGenericReadFunction(dynamic args)

Arguments

Parameter
Type
Definition

args.contractAddress

String

Contract address of the smart contract to be called

args.functionABI

String

args.functionName

String

Name of the function to be called as per the ABI.

args.chain

Metafi.Unity.Chain

args.params

List<object>

Return Value

dynamic object returned from smart contract.

{
    data = {
        ...
    },
    error = "",
}

Handling Large Numerical Values

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);

Example

using System;
using Metafi.Unity;

public class GameManager : MonoBehaviour {
    public async void ReadSmartContractData(){
        var res = await MetafiProvider.Instance.CallGenericReadFunction( new {
            contractAddress = "contract-address",
            functionABIPath = "path-to-abi",
            functionName = "readMetadata",
            @params = new object ["param1", "param2"],
            chain = Chains.MUMBAI,
        });
    }
}

Last updated