Open Umair72Raza opened 19 hours ago
Hi!
You don't need to build data from the method signature manually. Instead you can call contract methods directly with the contract ABI. Docs with example: https://docs.reown.com/appkit/unity/core/usage#send-erc20-token
Now, I am getting this error
ReownNetworkException: Internal JSON-RPC error. Reown.Sign.Engine.Request[T,TR] (System.String topic, T data, System.String chainId, System.Nullable`1[T] expiry) (at ./mailto:library/packagecache/com.reown.sign@1.0.1/runtime/engine.cs:734) Reown.Sign.Nethereum.ReownSignServiceCore.SendTransactionAsyncCore (Nethereum.RPC.Eth.DTOs.TransactionInput transaction) (at ./mailto:library/packagecache/com.reown.sign.nethereum@1.0.1/runtime/reownsignservicecore.cs:55) .....
This is my updated code:
`
[ContextMenu("MintTokensWithMatic")] private async void MintTokensWithMatic() { // Get the user's account information Account account = await AppKit.GetAccountAsync(); string recipientAddress = account.Address;
// Set the amount of MR tokens to mint (adjust this to the desired number of tokens)
BigInteger mintAmount = new BigInteger(1e18); // Mint 1 MR token, scaled to 18 decimals
// Hardcoded price: 1 MATIC per token
BigInteger maticPricePerToken = new BigInteger(1e18); // 1 MATIC in wei
// Calculate the total MATIC needed (1 MATIC per token)
BigInteger totalMaticToSend = mintAmount * maticPricePerToken / new BigInteger(1e18); // Adjust for scaling
// ABI encoding for "mint(address to, uint256 amount)"
var functionSignature = "0x40c10f19";
string recipientParam = recipientAddress.Substring(2).PadLeft(64, '0'); // Pad address to 32 bytes
string amountParam = mintAmount.ToString("x").PadLeft(64, '0'); // Pad amount to 32 bytes
// Concatenate function signature and parameters
string data = functionSignature + recipientParam + amountParam;
////////////////////////////////////////////////////////////////////////
BigInteger amount = new BigInteger(1e18);
var arguments = new object[]
{
recipientAddress,
totalMaticToSend
};
var result = await AppKit.Evm.WriteContractAsync(contractAddressMRToken, PayableMRTokenABI ,"mint", amount ,arguments);
Debug.Log("<color=yellow> Result </color>" + result);
////////////////////////////////////////////////////////////////////////
}
`
Could you please share your contract ABI and address so I could take a look myself? 🙏
I have attached the files with abi and contract MRTokenABI.txt MRTokenContract.txt
Hello, I need help in my dApp where I am using Reown appkit with Unity and polygon amoy testnet to deploy and interact with contracts.
I am new to blockchain and using Reown Appkit to interact with ERC 20 and ERC1155 contracts. I am connecting to my account using the wallet connect feature from the Reown Appkit Modal to connect my mobile wallet to the unity app. In one of my code chunk, I am trying to mint ERC 20 token by giving the Polygon Amoy Testnet currency. The transaction fails randomly. It gets successful like 4 in 10 times. I am unable to observe the test case because the error and success are random. The mobile wallet app crashes and in the logs I see JSON RPC error or gas estimate failed. I am using Reown App-kit and deployed my contracts on the polygon amoy testnet that has chainId eip:80002.
` await AppKit.InitializeAsync(new AppKitConfig { projectId = "your-project-id", metadataUrl = "https://metadata-url.com",
});
`
here is the function hashes of the contract:
{ "dd62ed3e": "allowance(address,address)", "095ea7b3": "approve(address,uint256)", "70a08231": "balanceOf(address)", "313ce567": "decimals()", "4b94f50e": "getTokenPrice()", "40c10f19": "mint(address,uint256)", "06fdde03": "name()", "8da5cb5b": "owner()", "715018a6": "renounceOwnership()", "6a61e5fc": "setTokenPrice(uint256)", "95d89b41": "symbol()", "7ff9b596": "tokenPrice()", "18160ddd": "totalSupply()", "a9059cbb": "transfer(address,uint256)", "23b872dd": "transferFrom(address,address,uint256)", "f2fde38b": "transferOwnership(address)" }
Here is the code:
` // mint mr token using matics [ContextMenu("MintTokensWithMatic")] private async void MintTokensWithMatic() { // Get the user's account information Account account = await AppKit.GetAccountAsync(); string recipientAddress = account.Address;
`