xclud / web3dart

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

Transaction.callContract using 1559 and .signTransaction fails #18

Open danielnordh opened 2 years ago

danielnordh commented 2 years ago

I'm creating a signed transaction on a mobile client which is then passed to a node server for submission. This works when not including 1559 gas parameters:

final transaction = Web3Dart.Transaction.callContract(
        contract: usdcContract,
        function: usdcContract.function('transferWithAuthorization'),
        parameters: [
          Web3Dart.EthereumAddress.fromHex(user.pubKey!),
          toAddress,
          amount,
          BigInt.from(validAfter),
          BigInt.from(validBefore),
          nonce.bytes,
          BigInt.from(sigParams.v),
          bigIntToUint8List(sigParams.r),
          bigIntToUint8List(sigParams.s),
        ]
);
final signedTx = await ethClient.signTransaction(
    wallet.privateKey, 
    transaction,
    chainId: config.chain.chainId, 
    fetchChainIdFromNetworkId: false);
hexTx = "0x" + hex.encode(signedTx);

But when adding the 1559 parameters maxFeePerGas and maxPriorityFeePerGas, it fails when submitting on the node server with the following error: transaction could not be decoded: could not decode RLP components: could not decode list item 3 to Address: invalid address: 0x22ecb25c00

final transaction = Web3Dart.Transaction.callContract(
        contract: usdcContract,
        function: usdcContract.function('transferWithAuthorization'),
        parameters: [
          Web3Dart.EthereumAddress.fromHex(user.pubKey!),
          toAddress,
          amount,
          BigInt.from(validAfter),
          BigInt.from(validBefore),
          nonce.bytes,
          BigInt.from(sigParams.v),
          bigIntToUint8List(sigParams.r),
          bigIntToUint8List(sigParams.s),
        ],
        maxFeePerGas: Web3Dart.EtherAmount.fromUnitAndValue(Web3Dart.EtherUnit.gwei, 150),
        maxPriorityFeePerGas: Web3Dart.EtherAmount.fromUnitAndValue(Web3Dart.EtherUnit.gwei, 3),
);
final signedTx = await ethClient.signTransaction(
    wallet.privateKey, 
    transaction,
    chainId: config.chain.chainId, 
    fetchChainIdFromNetworkId: false);
hexTx = "0x" + hex.encode(signedTx);

I'm using web3.js 1.7.1 on the node server and the js snippet for submitting the transaction is:

Web3.eth.sendSignedTransaction(hexTx, function (err, hash) {
    if (!err) {
      response.end(JSON.stringify({"hash": hash }));
    } else {
      response.end("Error!");
    }
  });

If I use .sendTransaction (instead of .signTransaction) on the mobile client using the 1559 parameters it works. Is there something I'm missing in the combo of .callContract and .signTransaction when using 1559, or is something broken?

kaumudpa commented 2 years ago

I am facing the same problem.