xclud / web3dart

Ethereum library, written in Dart.
https://pub.dev/packages/web3dart
MIT License
170 stars 94 forks source link

Cannot send transaction: Unhandled Exception: RPCError: got code -32000 with msg "invalid sender". #80

Closed Hathoriel closed 1 year ago

Hathoriel commented 1 year ago

Hi, I cannot send a transaction, it returns me "invalid sender" error. I am adding the following screenshot

image
JaafarRammal commented 1 year ago

@Hathoriel you can pass the following optional parameters to the function and it should work!

await client.sendTransaction(
      credentials,
      Transaction.callContract(
          contract: contract,
          function: transferFunction,
          parameters: [params]),
      fetchChainIdFromNetworkId: true, chainId: null);
Hathoriel commented 1 year ago

Hi, thanks for info. I will try it. 👍

Dne so 17. 12. 2022 20:32 uživatel Jaafar Rammal @.***> napsal:

@Hathoriel https://github.com/Hathoriel you can pass the following optional parameters to the function and it should work!

await client.sendTransaction( credentials, Transaction.callContract( contract: contract, function: transferFunction, parameters: [params]), fetchChainIdFromNetworkId: true, chainId: null);

— Reply to this email directly, view it on GitHub https://github.com/xclud/web3dart/issues/80#issuecomment-1356404813, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACTBOBNFREODWWAG2WED5L3WNYIN5ANCNFSM6AAAAAATAD6YRU . You are receiving this because you were mentioned.Message ID: @.***>

Hathoriel commented 1 year ago

Hi I finally made it working with this code:

sendNativeTransaction(String to, String amount, String walletId, String password) async {
    final client = _getEthClient();
    final credentials = await getPrivateKeyEthKey(password, walletId);
    final toAddress = Web3Dart.EthereumAddress.fromHex(to);
    final amountWei = double.parse(amount) * 1000000000;
    print(BigInt.from(amountWei.toInt()));
    final amountToSend = Web3Dart.EtherAmount.fromUnitAndValue(Web3Dart.EtherUnit.gwei, BigInt.from(amountWei.toInt()));
    final transaction = Web3Dart.Transaction(
      to: toAddress,
      value: amountToSend,
      maxGas: 21000,
      gasPrice: Web3Dart.EtherAmount.inWei(BigInt.from(1500000000)),
    );
    print(transaction.toString());
    final response = await client.sendTransaction(credentials, transaction, fetchChainIdFromNetworkId: true, chainId: null);
    print(response);
    return response;
  }

Main thing which made it working was this part:

fetchChainIdFromNetworkId: true, chainId: null

Would it make sense to add this inside readme, because as it is right now it didn't worked? https://pub.dev/packages/web3dart

4xMafole commented 1 year ago

This helped. @Hathoriel can you close this issue since the solution has been addressed and tested above.

Hathoriel commented 1 year ago

Closed ❤️