I want to be able to interact with functions on a smart contract. I do not want to setup my own node using geth, and would like to use something like Infura as a remote node.

Based on what I have seen, one of the more popular options is Web3, but I cannot get it connect to my Infura node. I run the below commands (after opening the NodeJs console using "node"):

Web3 = require("web3");
web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/personalcode"));

Running web3.eth.blockNumber after doing this returns null though. I also see the below in the output after running the require statement:

    host: 'https://mainnet.infura.io/personalcode',
    timeout: 0,
    connected: false,

The Web3 version is 1.0.0-beta.34 btw (not sure if that has anything to do with it).

Any suggestions or pointers on what I am doing wrong? I am not committed to using web3 btw. Any way to interact using the command line is fine.

1 Answer 1


You can use POST or GET from the command line to access Infura's JSON-RPC using curl. It can be used for almost all the web3 methods except those that require them to store your secure private key which they list on their github FAQ. Here is an example using the blockNumber method using POST:

curl -X POST --data '{"id":1,"jsonrpc":2.0,"method":"eth_blockNumber","params":[]}' https://mainnet.infura.io/<yourpersonalkey>

You'll find more in Infura's getting started

To use GET method (no api key):

curl -i -H "Content-Type: application/json" -H "Accept: application/json" 'https://api.infura.io/v1/jsonrpc/mainnet/eth_blockNumber'

You'll find more about this on the Infura Docs Page

There are also tutorials out there for using nodejs with Infura that you may find helpful.

  • This is a good option for read functions, but for functions which modify the blockchain, it would be painful to not be able to store the private key, and to have to sign the transaction separately. I would prefer web3 over this if I can get that to work. Any idea what I'm doing wrong there? Commented Jun 22, 2018 at 15:47

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.