January 22, 2026

Capitalizations Index – B ∞/21M

Ethereum — Smart Contracts Compile and Deploy — Part II

Ethereum — Smart Contracts Compile and Deploy — Part II

As we saw in previous article Compile.js spits out Bytecode and ABI when compiled.

In this article we will write Node.js which takes all the input (Bytecode, ABI, Constructor Arguments, Gas amount) and outputs contract address. Later contract address and ABI can be used by other applications or Smart Contracts to build dApps. Above diagram describes what I just wrote. We will write Node.js for deploying to local blockchain environment, Ganache. It makes deployment process just so easy to test. Later in other articles I will show how to deploy to test networks. Create a folder deploy and file deploy.js in this folder. We will use web3.js libraries which allows to connect with local or test Ethereum networks. Web3.js is a JavaScript framework to build distributed apps (dApps). Follow below code. In bold are actual commands.

const Web3 = require(‘web3’); //Web3 is a constructor

Using above constructor, we create an instance of web3.

ganache-cli is a provider for connection to local blockchain. Consider it as communication layer between web3 and a particular Ethereum network. Each network (Test or Live) has its own provider. This provider sends and receive messages between network and web3.

const ganache = require(‘ganache-cli’);

Below require statement refers to the compile.js from previous article and captures Interface and Bytecode from compile.js. Remember module.exports as a last statement within compile.js.

const = require(‘../compile’);

While running deploy script in case you land into error “possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit.” Use below command

require(‘events’). EventEmitter.prototype._maxListeners = 100;

Write a function deploySC which is deploying smart contract. Remember every function in web3 is of asynchronous nature. That’s why function is wrapped with async. Read Promises, async and await in Java script in case you are not familiar. For asynchronous programming getting grasp of Promise and async/await is quite an important.

const deploySC = async () => )

.send();

console.log(‘deployment done’);

//This print contract address on successful deployment

console.log(‘SC Address ‘+deployContract.options.address);

}

deploySC(); //Call function to deploy contract

From the command prompt run node deploy.js from same folder where deploy.js is residing. When contract gets deployed, contract address is generated. In Ethereum world there are 2 kinds of addresses.

Externally owned Account (EOA) and Contract address. In above script accounts [0] is EOA or public address through which one can send and receive ethers. Every account address resides in a Wallet and linked to its unique private key. Contract address can also receive Ethers, but main distinction from EOA is Contract address can also receive and send messages/data. Watch out for my next article which will be an explanation of Encryption, Wallets, MetaMask, Public and Private keys concepts.

Useful links for Promise, Async/Await

https://www.youtube.com/watch?v=QO4NXhWo_NM

https://www.youtube.com/watch?v=104J7_HyaG4&list=RDQM6NzaS65Pznk&index=16

I will appreciate your claps in case you like this article.

Published at Sun, 06 Jan 2019 19:50:33 +0000

Previous Article

Hodler’s Digest, Dec. 31 – Jan. 6: Top Stories, Price Movements, Quotes and FUD of the Week

Next Article

Stablecoins, Tokenization and the Future of [BTC] in 2019

You might be interested in …

Develop a Successful Cryptocurrency & Bitcoin [BTC] Tech Startup Business Today! Manchester – Entrepreneur – Workshop – Hackathon – Bootcamp – Virtual Class – Seminar – Training – Lecture – Webinar – Conference – Course

Develop a Successful Cryptocurrency & bitcoin [BTC] Tech Startup Business Today! Manchester – Entrepreneur – Workshop – Hackathon – Bootcamp – Virtual Class – Seminar – Training – Lecture – Webinar – Conference – Course […]