Metafi Unity SDK
Developer PortalMore Docs ⏷About Us ⏷Help & Resources ⏷
  • Get Started
  • SDK Reference
    • Provider Initialisation
    • Login
    • ShowWallet
    • HideWallet
    • TransferTokens
    • CallGenericReadFunction
    • CallGenericWriteFunction
    • CallGaslessFunction
    • Checkout
    • RetrieveUser
    • Disconnect
  • Constants
    • Chain
    • Asset
  • UI Customization
Powered by GitBook
On this page
  • Description
  • Details
  • Signature
  • Arguments
  • Return Value
  • Handling Large Numerical Values
  • Example
  1. SDK Reference

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.

Description

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.

Details

Signature

Task CallGenericWriteFunction(dynamic args, System.Action<dynamic> callback = null)

Arguments

Parameter
Type
Definition

callback?

Action<dynamic>

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.value?

String

args.chain

Metafi.Unity.Chain

args.params

List<object>

Return Value

None

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 StakeTokenButton : MonoBehaviour {
    public async void StakeTokens(){
        await MetafiProvider.Instance.CallGenericWriteFunction(new {
            contractAddress = "contract-address",
            functionABIPath = @"Assets/Resources/Contracts/path-to-contract.json",
            functionName = "stakeTokens",
            value = Utils.ConvertNumberToBigNumber(0.1, 18),
            @params = new [] {"param1", "param2"},
            chain = Chains.MUMBAI,
        },
        ((System.Action<dynamic>) (result => {
            Debug.Log("CallGenericWriteFunction complete, result: " + result.ToString());
        })));
    }
}
PreviousCallGenericReadFunctionNextCallGaslessFunction

Last updated 2 years ago

Function to callback upon getting result from the smart contract function call For numerical return values, please refer to the . Structure of result object passed into callback function:

The path to the JSON object for the . You can store it in the Resources folder and pass in a path such as @"Assets/Resources/Contracts/Contract.json"

The value to be sent along with the smart contract invocation. Please refer to the for more information.

Which chain to broadcast the transaction on. Pick a chain from the

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 .

{
    "status": 1/0, // success or fail
    "error": "", // error string if any
    "data": {any}, // data returned from the smart contract function call
}
supported chains list
smart contract ABI
section below
section below
section below