WalletConnectFlutterV2
WalletConnectFlutterV2 copied to clipboard
JsonRpcError when sending transaction using MetaMask
When I'm calling a custom contract method to send transaction through metamask app, getting below error
Unhandled Exception: JsonRpcError(code: 5000, message: Internal JSON-RPC error.)
STR I have three step process like:
- Connect (connect to Metamask wallet app) : Working
- Approve (approve) : Not Working
- Complete (minting):
Step-1 is working fine when i click on Connect button its open the Metamask and i successfully received chain id and account address. But when i click on Approve button its open the Metamask app & show the Modal sheet with Approve and Reject buttons, when click on Approve It shows Internal JSON-RPC error alert as showing in screenshot:
My Code is:
Future<dynamic> callApprove(String conAddressHex, int amount, BuildContext context) async {
String transactionId = "";
try {
/// LOAD SMART CONTRACTOR
var contract = await _loadContractERC20();
/// MAKE TRANSACTION USING web3dart
Transaction transaction = Transaction.callContract(
from: EthereumAddress.fromHex(_accountAddress!),
contract: contract,
function: contract.function(_methodApprove),
parameters: [
EthereumAddress.fromHex(conAddressHex),
BigInt.from(amount) * BigInt.from(1000000000000000000)
],
);
/// MAKE ETHEREUM TRANSACTION USING THE walletconnect_flutter_v2
EthereumTransaction ethereumTransaction = EthereumTransaction(
from: _accountAddress ?? "",
to: conAddressHex,
value: '0x2386F26FC10000', // 0.01 Ether (in wei)
data: hex.encode(List<int>.from(transaction.data!)), /// ENCODE TRANSACTION USING convert LIB
);
/// OPEN METAMASK
await launchUrl(Uri.parse("$wcUriPrefix$_encodedWcUrl"),
mode: LaunchMode.externalNonBrowserApplication);
/// REQUEST TO WALLET FOR TRANSACTION USING walletconnect_flutter_v2
transactionId = await _web3App?.request(
topic: _sessionData?.topic ?? "",
chainId: kFullChainId.toString(),
request: SessionRequestParams(
method: "eth_sendTransaction",
params: [ethereumTransaction.toJson()],
),
);
} on Exception catch (_, e) {
_log("Error: $e");
}
_log("transactionId: $transactionId");
return transactionId;
}
Anyone, can you help me what's going wrong?