1

I tried to deploy my contract on Ropsten TestNet with infura and web3.js, however when I used some functions it returned 405 error. I notice that maybe I could not use web3.eth.getTransaction() when infura, however when I use following script <script src="./node_modules/web3/dist/web3.min.js"></script> this function is called several times.

How can Iavoid the error, do I need to modity web3.min.js (https://github.com/ethereum/web3.js/blob/develop/dist/web3.min.js)? Or is there any way to replace infura?

3

2 Answers 2

1

A 405 means that the underlying JSON-RPC method is not allowed. Most of the methods that are not allowed do not make sense for a service like Infura (e.g. we don't store keys on our servers).

0

developer advocate at Chainstack here!

I just found this and thought I could add an update here in case someone will need this! 😁

When using web3.js, make sure to install it and import it correctly.

Note that Ropsten and Rinkeby are considered deprecated. I recommend using Goerli instead. Check out this article about the merge where you can find which testnets are deprecated!

Install web3.js

Install it with npm or Yarn, you can reference the web3.js docs too.

NPM

npm install web3

Yarn

yarn add web3

Import web3.js in your script

Then import it in your script at the top.

const Web3 = require("web3");

eth_getTransaction example

Now you are ready to query the blockchain using web3.js; the following script is an example using the eth_getTransaction method.

const Web3 = require("web3");
const node_url = "CHAINSTACK_NODE_URL";
const web3 = new Web3(node_url);
web3.eth.getTransaction("0xf915903ecc67ab20a5162ae13eec36e3a68ca558765ada1779847e0a0c35479c", (err, tx) => {
    console.log(tx)
})

this will return:

{
  blockHash: '0xd233ac25d1bd643ce5170cd557e0206b7bd2ece3352fa5edaec3181ac0668fc4',
  blockNumber: 14831527,
  from: '0x31cA75bA3DB4A8A61304dFAa854Bd301Dbc3484d',
  gas: 21000,
  gasPrice: '82115541266',
  maxFeePerGas: '115650024606',
  maxPriorityFeePerGas: '1500000000',
  hash: '0xf915903ecc67ab20a5162ae13eec36e3a68ca558765ada1779847e0a0c35479c',
  input: '0x',
  nonce: 41,
  to: '0xd5E72C75C3d4bAFdb62Dee079d2bF9ef614125B6',
  transactionIndex: 371,
  value: '30000000000000000',
  type: 2,
  accessList: [],
  chainId: '0x1',
  v: '0x1',
  r: '0x313004f2935447fc7d4584beecc3bafaf44231346f57c0b74b14770eddecfd98',
  s: '0x7ad1056eff0c2d12bfb78b85776326a4d5c5ba07d598576e8c2073929b456861'
}

Find more code examples in the Ethereum API section of the Chainstack docs.

If you wish to try different node providers try Chainstack. We support many EMV-based protocols.

  1. Sign up with Chainstack.
  2. Deploy a node.
  3. View node access and credentials.

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.