SendTransaction - error with 'loadChainIdFromNetwork' vs 'custom chain id'
Closed this issue · 2 comments
Hello,
I have been using the following code to "send Transaction" without any problem, but with an 'old' version of Flutter (1.xx) :
#######
Future setEthClient() async {
Client httpClient;
Web3Client ethClient;
httpClient = Client();
ethClient = Web3Client(
"https://rinkeby.infura.io/v3/afc2….”, //note : partially erased here for privacy concerns :)
httpClient);
return ethClient;
}
Future cacheSend(
String receiverRequest,
String myPrivateKeyAddress_String,
Web3Client ethClient,
DeployedContract contract,
String functionName,
List args,
EthereumAddress myAddress,
int maxGasAmount) async {
final credentials =
await ethClient.credentialsFromPrivateKey(myPrivateKeyAddress_String);
final ownAddress = await credentials.extractAddress();
final ethFunction = contract.function(functionName);
final transactionHash = await ethClient.sendTransaction(
credentials,
Transaction.callContract(
contract: contract,
function: ethFunction,
parameters: args,
from: myAddress,
maxGas: maxGasAmount),
fetchChainIdFromNetworkId: true,
);
return transactionHash;
}
}
#######
Since I have upgraded to Flutter 2.xx , I have the following error message :
#######
[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Invalid argument(s): You can't specify loadChainIdFromNetwork and specify a custom chain id!
#######
Changing "fetchChainIdFromNetworkId : true" to "fetchChainIdFromNetworkId : false", I get another error message
#######
Unhandled Exception: RPCError: got code -32000 with msg "invalid sender"
#######
I use web3dart: ^2.1.4.
After trying to find out some answer with Google & Co, without any result, I am asking for your help.
Thanks in advance.
Regards,
S.
You need to explicitly set the chainId
to null when you set featchChainIdFromNetworkId: true
, by default chainId
is set to 1.
Here is the line of code that is throwing
client.sendTransaction(
EthPrivateKey.fromHex(privateKey),
transaction,
chainId: null,
fetchChainIdFromNetworkId: true,
);
Hello,
Perfect ! All transactions 'send' working :)
Thanks a lot.
Regards,
S.