2

I want to send ETH from one account to another using Web3 interface and Infura node. I have tried like below, and I got error 405(). Error: Invalid JSON RPC response: ""

I test it in Rinkeby test network. This is how I initialize Web3 and do the transaction.

<script>
        $(document).ready(function () {
            const Web3 = require('web3');
            const web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/<Access_Token>'));

            $(".btn-send").click(function () {
                web3.eth.sendTransaction(
                    {
                        to: '0xae8cE2D0B2015Aeb62189822C7eEae2f60B011e5',
                        from: '0x5ada788989dCa813cBE82eD8bB8d54e1b43327A7',
                        value: web3.toWei("1", "ether")
                    },
                    function (error, transactionHash) {
                        if (!error) {
                            console.log("send successfully");
                        } else {
                            console.log("Error: " + error);
                        }
                    }
                );
            });
        });
</script>
1
  • you need to sign the transaction
    – Majd TL
    Mar 24, 2021 at 8:25

2 Answers 2

4

A 405 error means that the underlying JSON-RPC method is not supported by Infura. Infura only blocks methods that do not make sense for Infura, such as those that require Infura to store private keys. Apparently web3.eth.sendTransaction invokes the eth_sendTransaction method (which requires the server to hold keys). You need to use the web3 method that instead invokes eth_sendRawTransaction, so that the transaction signing happens locally.

1

you have to use your personnal parity/geth node to create offline transaction. and after that you can send this transaction with infura. documentation link : how to send transaction with infura web3js

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