I cannot use executeFunction to pass parameterized data into the smart contract. I have been working for almost two days now. The following are the code snippets:
leaderBoardData(integer) function
//āLeaderboard
public static async UniTask<string> leaderBoardData(int i)
{
//Define function name
//public const string LEADERBOARD_CALL = "readStructFromMapping";
string functionName = LeaderBoardContractData.LEADERBOARD_CALL;
//Define contract request
//Tried this:
// object[] parameters = { i.ToString()};
//
//Also this:
// object[] parameters = new object[1];
// parameters[0] = i;
//
//Then this:
object[] parameters = { i };
string results = await OnRunContractFunction(functionName, parameters);
return results;
}
OnRunContractFunction(function, parameters) function
static async UniTask<string> OnRunContractFunction(string functionName, object[] args)
{
//Defining contract data
string address = LeaderBoardContractData.Address;
ChainList chain = LeaderBoardContractData.requiredChain;
object[] abi = LeaderBoardContractData.GetAbiObject();
//Ensure WalletConnect
if (WalletConnect.Instance == null)
{
throw new Exception("Method failed. WalletConnect.Instance must not be null. Add the WalletConnect.prefab to your scene.");
}
//Setup Web3
await Moralis.SetupWeb3();
RunContractDto runContractDto = new RunContractDto()
{
Abi = abi,
Params = args
};
MoralisClient moralisClient = Moralis.GetClient();
string result = await moralisClient.Web3Api.Native.RunContractFunction(address, functionName, runContractDto, chain);
return result;
}
readStructMapping
function object
//readStructFromMapping
object[] readStructFromMappingInputParams = new object[1];
readStructFromMappingInputParams[0] = new { internalType = "uint8", name = "position", type = "uint8" };
object[] readStructFromMappingOutputParams = new object[2];
readStructFromMappingOutputParams[0] = new { internalType = "address", name = "refUser", type = "address" };
readStructFromMappingOutputParams[1] = new { internalType = "uint256", name = "refScore", type = "uint256" };
newAbi[2] = new { inputs = readStructFromMappingInputParams, outputs = readStructFromMappingOutputParams, name = LEADERBOARD_CALL, stateMutability = "view", type = "function" };
readStructMapping ABI
{
"inputs": [
{
"internalType": "uint8",
"name": "position",
"type": "uint8"
}
],
"name": "readStructFromMapping",
"outputs": [
{
"internalType": "address",
"name": "refUser",
"type": "address"
},
{
"internalType": "uint256",
"name": "refScore",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}