Nodeless Ethereum Smart Contracts Development with Infura
The Ethereum Blockchain is on the verge of bringing the Decentralized Web to the masses, disrupting several Industries along the way.
Considering that most of Blockchain projects right now are Ethereum-based, and the reported level of adoption of the World’s most popular Blockchain platform, it feels natural for a developer willing to explore the space, to give Solidity a try.
To get started with your Smart Contracts, you will need a development environment and proper access to an Ethereum node.
Show me the tools
Similar to what the Node.js, Webpack and Karma/Mocha stack can bring to the local development lifecycle of frontend developers, Truffle is a development environment and testing framework aiming to make life easier for Ethereum developers.
If you plan on building token sale contracts, a popular option is to combine Truffle with the (almost) ready-to-use Smart Contracts of the OpenZeppelin framework. It’s one of the easiest way to produce consistent code using existing boilerplate that you can inherit from.
The Smart Contract Development Lifecycle
Code auditing aside, a smart contract development process can be simplified into these 3 majors steps:
- Local development
- Staging (QA) on Testnet
- Launch on MainNet
While it’s easy to spoof local RPC calls using ganache, connecting to the staging and main Ethereum networks would normally require you to provision, run and maintain your own Ethereum node.
But do we really want to potentially spend hours on infrastructure management matters? What if your machine also lacks the processing power to do operate a node in acceptable performance conditions?
That’s where Infura could come in handy.
Your access to the Ethereum network
Infura provides an infrastructure for your decentralized applications so you can focus on development and nothing else.
It basically enables you to interact with Smart Contracts on the Ethereum Blockchain through an API. A simple, yet a great way to speed up your development workflow and give your machine an easier time.
Let’s see how.
- A Metamask Wallet with some ETH
(You can get some for free on the Ropsten TestNet faucet)
- Node (=> 10.x)
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
- The Truffle framework
npm install -g truffle
- A (configured) Infura account :)
For the purpose of this test, we’ll be calling the functions of Stacktical DSLA token sale Smart Contracts, available at this address.
Time to set things up.
Head over to https://metamask.io/ and install the browser extension.
Once installed, switch Metamast to the Ropsten Test Network (TestNet):
Go to Settings > Reveal Seed Words.
Your Mnemonic Seed Words are displayed. Keep them handy.
Go to … > Copy Address to clipboard
You should now have in your possession:
✅ Your Mnemonic Seed Words
✅ The address of the account that will deploy the Smart Contracts
Head over to infura.io, sign up and create a new project from your dashboard.
I’d advise creating 2 projects from the start, one for Development and another one for Production — less room for mistakes.
We will be using the Ropsten TestNet for Development purposes, deploying and whitelisting the smart contract in there.
Make sure your take good note of your API Key .
At the time of writing the V3 auth flow (involving the API Secret) is not mandatory yet.
Getting your local development ready
Clone the token sale contracts repository with the following command:
git clone email@example.com:Stacktical/stacktical-contracts-token-sale.git \
Then install the Smart Contract dependencies:
From there, you can edit the code to suit your needs* and start playing with the available Smart Contracts functions using ganache (make sure your instance is up).
Let’s deploy the contracts on a real Blockchain now.
*PRs and Bug reports will be rewarded according to the upcoming OSS Development Bounty Campaign.
Deploying the Smart Contracts to the Testnet
Testnet environments work like the real deal, minus the gas fees.
They’re the perfect playground for repeatedly interacting with Smart Contracts and improve the quality of developments before the official availability of contracts on the Ethereum Blockchain.
We are now going to use Infura to connect to the Ropsten Testnet without installing an Ethereum node locally.
Set your deployment parameters according to the repository README:
export DSLA_INFURA_APIKEY_DEV=<your Infura API Key>
export DSLA_MNEMONIC_DEV=<your dev mnemonic>
Make sure you replace <your Infura API Key> with your actual Infura API key (ndlr: on your Infura dashboard) and <your dev mnemonic> with the Metamast mnemonic you had previously saved.
Now proceed with the contracts deployment using the following command:
truffle migrate --network ropsten
Check the status of your deployment on Etherscan:
Once deployed, you will be able to whitelist your Smart Contract address in your Infura dashboard:
Giving the deployed Smart Contracts a try
truffle console --network ropsten
Now let’s execute some function of the Smart Contract:
$ truffle console --network ropsten
truffle(ropsten)> participant = "0x556249c7E5B660CCe504a7e5EbA021F32C6216Df"
transactionIndex: 2 },
logs:  }
Infrastructure management can be daunting for developers that are not in full DevOps capacity, especially when it comes to Blockchains, DAGs and other Ledger-based technologies.
I hope you have a better idea on how Infura makes it easier to focus on your Solidity developments and (nearly) forget about the rest.
Upon successful testing and auditing the Smart Contracts, they can be deployed to the Mainnet using the following Truffle command:
truffle migrate --network production
And the Token Sale can start…
Obviously, you’ll want to deploy your own token on the Mainnet, not ours!
⚡️ Stacktical combines the power of predictive and blockchain technologies to help companies indemnify their customers for performance failures, while rewarding their support teams for operational excellence.
Powered by DSLA, the Decentralized Service Level Agreement ERC-20 token.