Reputation: 19
I got error: {"Invalid account used signing"}
The code is this
Public Shared Async Function send02Pol(privateKey As String, destination As String) As Task
'Dim chainId As UInteger = 137
' Initialize Web3 with Account and RPC URL
Dim web3 = New Web3(New Account(privateKey), "https://polygon-rpc.com")
' Convert transfer amount from Ether to Wei
Dim transferAmountInWei = Web3.Convert.ToWei(0.1)
' Create transaction input with default gas and gas price
Dim transactionInput = New TransactionInput() With {
.To = destination,
.Value = New HexBigInteger(transferAmountInWei),
.Gas = New HexBigInteger(21000), ' Default gas limit
.GasPrice = New HexBigInteger(Web3.Convert.ToWei("20", UnitConversion.EthUnit.Gwei)) ' Default gas price
}
' Send transaction and get receipt
Dim transactionReceipt = Await web3.Eth.TransactionManager.SendTransactionAsync(transactionInput)
Console.WriteLine("Transaction Hash: {0}", transactionReceipt)
End Function
I am basically trying to modify code from https://docs.nethereum.com/en/latest/nethereum-transferring-ether/
to send 0.1 pol in polygon network to an address.
A previous code already work So there is nothing wrong with the address and private key
Public Shared Async Function send01Pol(privateKey As String, recipientAddress As String) As Task Dim web3 As New Web3("https://polygon-rpc.com")
' Sender address and private key
' Amount to send (in Wei)
Dim amountInWei As BigInteger = Web3.Convert.ToWei(0.1) ' Sending 0.1 MATIC
' Estimate gas price
Dim gasPrice As HexBigInteger = Await web3.Eth.GasPrice.SendRequestAsync()
' Nonce (Transaction count for the sender address)
Dim nonce As BigInteger = Await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(recipientAddress)
' Gas limit for the transaction
Dim gasLimit As New HexBigInteger(21000) ' Standard for simple transfers
' Create raw transaction
Dim chainId As Integer = 137
' Create and sign the transaction
Dim transactionSigner As New LegacyTransactionSigner()
Dim signedTransaction As String = transactionSigner.SignTransaction(
privateKey, chainId, recipientAddress, amountInWei, nonce, gasPrice, gasLimit)
' Send the signed transaction
Dim transactionHash As String = Await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(signedTransaction)
' Display transaction hash
Console.WriteLine($"Transaction hash: {transactionHash}")
End Function
I just want to try to do the same thing using a bunch of different ways to understand basic of nethereum.
Well if I run the first code I got this exception
{"Invalid account used signing"}
But the account is working fine on the second code. The destination address and the private key works fine. So the account can't be the problem.
I am quite suspicious with chainID not being used.
Gemini says that the constructor of web3 figured that out from the url of the RPC server.
Besides, Dim web3 = New Web3(New Account(privateKey), "https://polygon-rpc.com",137) simply results in error of not being able to find suitable constructor
I already consulted chatgpt and gemini and I am stuck. So I asked humans
Upvotes: 0
Views: 23