0

I'm able to deploy my contract to sepolia. I have ABI, Bytecode of deployed contract.

in .NET environment in register method I have:

                {
                    var senderAddress = "0xF428E821e8D5f89031F38a0E5eA3419735c150a7"; 
                    var contractAddress = "0x*";
                    var web3 = new Web3("https://sepolia.infura.io/v3/*");
                    var carContract = new CarRegistrationContract(senderAddress, contractAddress, web3);
                    var transactionHash = await carContract.AddCarAsync("ABC123", 50000, 123, 456);
                    Console.WriteLine("Transaction Hash: " + transactionHash);
                    return true;
                }
                catch (Exception ex)
                {
                    throw;
                }

and my AddCarAsync method looks like this

public async Task<string> AddCarAsync(string vin, BigInteger milage, BigInteger eventCode, BigInteger dealershipId)
        {
            var addCarFunction = contract.GetFunction("addCar");
            var gasPrice = Web3.Convert.ToWei(20, UnitConversion.EthUnit.Gwei);
            var gasLimit = 21000;

            var encodedData = addCarFunction.GetData(vin, milage, eventCode, dealershipId);
            var transactionInput = new TransactionInput()
            {
                Data = encodedData,
                GasPrice = new HexBigInteger(gasPrice),
                Gas = new HexBigInteger(gasLimit),
                To = contractAddress
            };

            //The method eth_sendTransaction does not exist/is not available: eth_sendTransaction
            var transactionHash = await web3.Eth.Transactions.SendTransaction.SendRequestAsync(transactionInput);
            return transactionHash;
        }

I catch an error, in 'SendRequestAsync': The method eth_sendTransaction does not exist/is not available: eth_sendTransaction

Not sure what is going on, and what to do with this? Should I sign this transaction somehow? I tried but with no luck. Need some guidance from more experienced devs. Thanks

2 Answers 2

0

eth_sendTransaction is a method that assumes you have access to a node that you fully manage yourself and the node manages your private key and signs the transaction. eth_sendTransaction is not supported by node providers for security reasons.

What you want to use instead is eth_sendRawTransaction, in which you construct & sign the transaction locally and then send it to the remote node to propagate.

1
  • Thanks, that was the issue
    – michal
    Commented Oct 27, 2023 at 10:55
0

This is a solution for my issue

var account = new Account(_walletPrivateKey);var nonce = await _web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(account.Address, BlockParameter.CreatePending());var gasPrice = Web3.Convert.ToWei(10, UnitConversion.EthUnit.Gwei);var gasLimit = 1000000;

var functionInput = new AddCarFunction
{
  Vin = vin,
  Milage = (uint)milage,
  EventCode = (uint)eventCode,
  DealershipId = (uint)dealershipId,
  Nonce = nonce,
  Gas = new HexBigInteger(gasLimit),
  GasPrice = new HexBigInteger(gasPrice),
};
var transactionInput = functionInput.CreateTransactionInput(_contractAddress);

var offlineTransactionSigner = new AccountOfflineTransactionSigner();
var txtSigned = offlineTransactionSigner.SignTransaction(account, transactionInput);
var txtHash = await _web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(txtSigned.EnsureHexPrefix());

return txtHash;

now I'm able to interact with my contract on testnet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.