avatarHyungsuk Kang

Summary

The context provides a step-by-step guide to deploying a smart contract directly from Truffle using Infura.

Abstract

The context is a guide to deploying a smart contract directly from Truffle using Infura, a secret weapon to the Ethereum infrastructure. The guide begins by suggesting the use of Metamask for a comfortable Ethereum development experience. It then provides instructions for obtaining an Infura API key and initializing a Truffle project on a folder. The guide also covers setting up environment variables with dotenv, editing the truffle.js file, and deploying the contract to the desired network. The successful deployment of the contract will be indicated by logs. The guide concludes with a congratulatory message and a promise of a future guide on deploying a website on IPFS with Infura.

Bullet points

  • Get Metamask for a comfortable Ethereum development experience.
  • Get an Infura API Key.
  • Initialize a Truffle project on a folder and install the truffle-HDwallet package with npm.
  • Set up environment variables with dotenv.
  • Edit the truffle.js file.
  • Deploy the contract to the desired network.
  • The successful deployment of the contract will be indicated by logs.
  • A future guide on deploying a website on IPFS with Infura will be provided.

Deploy Your Smart Contract Directly from Truffle with Infura

Photo by Nick Fewings on Unsplash

It is often painful to develop on Remix with copying/pasting code on Open-zeppelin repository and scroll down the whole code without any gizmos included in the editor.

Well, not anymore. I found a way to do all that within the Truffle framework.

New to trading? Try crypto trading bots or copy trading

1. Get Metamask

Trust me. It is really comfortable to have this without downloading full node of ethereum.

2. Get infura API Key.

Infura by ConsenSys

infura is secret weapon to ethereum infrastructure.

Here’s what ConsenSys media says:

Many of the blockchain space’s most remarkable projects — Metamask,CryptoKitties, UJO, Radar Relay, Cipher Browser, uPort — utilize Infura’s APIs to connect their applications to the Ethereum network.

This includes signing to transaction for creating contract on metamask, which is what we are going to do.

3. `truffle init` then install truffle-hdwallet-provider.

Initialize truffle project on a folder and install truffle-HDwallet package with npm.

npm install --save truffle-hdwallet-provider

4. Set Environment Variable with dotenv

‘dotenv’ package opens .env file and stores its key and value to process.env variable.

First install dotenv on the project

# with npm
npm install --save dotenv
# or with Yarn
yarn add dotenv

Then setup environment variable:

MNENOMIC = // Your metamask's recovery words
INFURA_API_KEY = // Your Infura API Key after its registration

5. Edit truffle.js(truffle-config.js on Windows) with this file

I hope to apply this in truffle-box in near future:

6. Deploy to the desired network

For example, if the contract is deployed on Ropsten testnet:

truffle migrate --network ropsten

Voila! the contract should be deployed and show logs like this:

Using network 'ropsten'.
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0xa5f964329db84e4afed621a520c37c1aa376596912e509722eedba49a2378cc2
Migrations: 0x588a268a8db4784679c93b99bf6f3ab1c6a4831c
Saving successful migration to network...
... 0x6291aff7d5e14f24e8ee1047f10c84dc2ccd8eb17e8c60a52f2239164a8506c2
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying Etherball...
... 0xf2a77097dc01d1e0fd8885a1b114d1d45c41442d1a1acc7f5b0c23f570719ea7
Etherball: 0x88be89a5c61bfbe927794ba9cb6c52938a8e6b9e
Saving successful migration to network...
... 0x2c52eb548b10957aafa27f2fae9abc984445b5f82742f90c66b1a6e53640e963
Saving artifacts...

Congratulations if you deployed your smart contract successfully! Next, I will go through how to deploy website on IPFS with Infura.

For tips:

ETH: 0xEC9F815A29F16503649dDF9e34fAd1ad41f5f526

BCH: qp57se74fna2ddtp9chc2rh65cpqhet24qvjher26

BTC: 1AezMy3WzEFwEMEs4emhkqxEQAcafSSpSH

Join Coinmonks Telegram Channel and Youtube Channel get daily Crypto News

Also, Read

Ethereum
Truffle
Infura
Smart Contracts
Tutorial
Recommended from ReadMedium