blog/source/tutorials/infura_guide.md

2.7 KiB

title: Using Infura

To deploy to a test network (or even the mainnet), you usually have to synchronize a blockchain node yourself to be able to connect.

There is thankfully another alternative to save time and it is to use something like Infura, that has already synchronized nodes to which you can connect to.

They offer nodes for the most popular testnets like Ropsten, Kovan and Rinkeby and also for the main network.

Registration

To start you will need to first register with Infura. Go to https://infura.io/register and register.

Afterwards, you will get an API KEY by email. Save this key, you will need it to configure Infura. Careful, it is private.

Screenshot

Account Configuration

To deploy to Infura, we need to configure Embark with an account containing funds.

In this example we will use a mnemonic. It is also possible to use a private key (the documentation for the accounts functionality can be found here).

Make sure to read our recommendations on how to make sure your credentials stay secure here.

Edit your contract configuration (usually found at config/contracts.js) and add a new environment, which we will name infura:

Copy to clipboard
infura: {
  deployment:{
    accounts: [
      {
        mnemonic: process.env.yourMnemonic
      }
    ]
  }
}

Make sure the account has funds in the network you are deploying to. Most testnets have faucets. For example you can find a faucet for Rinkeby here.

Adding Infura

Now we will add the infura endpoint to our configuration. You should replace the key in the host field with your own. We will use Rinkeby for this example. You can specify the network as <network>.infura.io.

Copy to clipboard
infura: {
  deployment:{
    accounts: [
      {
        mnemonic: process.env.yourMnemonic
      }
    ],
    host: "rinkeby.infura.io/YOUR_KEY",
    port: false,
    protocol: 'https'
    type: "rpc"
  }
}

Deploying

Now to deploy, all you need to do is run embark run infura and Embark will deploy using Infura!

Screenshot