I try to build a game in unity, in which you can earn a blockchain token by minting it.
The API of the mint function looks like this:
{
"constant": false,
"inputs": [{"internalType": "address","name": "account","type": "address"}, {"internalType": "uint256","name": "amount","type": "uint256"}],
"name": "mint",
"outputs": [{"internalType": "bool","name": "","type": "bool"}],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
I first checked the approach in the flappy-bird-documentation and tried to change the set to score as follows:
public Function mintToken() {
return contract.GetFunction("mint");
}
CreateMintTokenTransactionInput(string addressFrom, string addressOwner, string privateKey, string adress , BigInteger amount, HexBigInteger gas = null, HexBigInteger valueAmount = null) {
var function = mintToken ();
return function.CreateTransactionInput(addressFrom, gas, valueAmount, adress, amount);
}
In the Start method of unity I go:
var transactionInput = CreateMintTokenTransactionInput(_userAddress, _addressOwner, _privateKey, adress, amount);
var transactionSignedRequest = new TransactionSignedUnityRequest(_url, GameControl.instance.Key, _userAddress);
//send and wait
yield return transactionSignedRequest.SignAndSendTransaction(transactionInput);
But the parameters of the function seem to be wrong.
I wonder if there is an easier way to do this or how I could fix my approach. In more general terms: How can I call an arbitrary smart contract method with parameters in Ethereum?
The next Problem ist that i dont get a transactionHash and I am not sure how to Debug this:
yield return transactionMintRequest.SignAndSendTransaction(mint, contractAddress);
if (transactionMintRequest.Exception != null)
{
Debug.Log(transactionMintRequest.Exception.Message);
yield break;
}
Debug.Log(transactionMintRequest);
var transactionMintHash = transactionMintRequest.Result;
Debug.Log("Transfer txn hash:" + transactionMintHash);