You must have node and npm downloaded on your computer. After this tutorial you should have created and deployed an ethereum smart contract on the testrpc blockchain.

"dependencies": {
"web3": "0.17.0-alpha",
"solc": "^0.4.4"

Include the code above in your package.json file.

npm install

Download the dependencies from your command line.

var Web3 = require("web3")
var solc = require("solc")

Require dependencies in your node console.

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))

Create new web3 instance. Localhost:8545 is the default host.

contract Introduction {
function displayMessage() constant returns (string) {
return "Congrats on your first smart contract";

Make a new file called Introduction.sol (or whatever you want) and include the above code. This contract has a displayMessage function that can return a string.

var source = `[[contract syntax]]`

Create a variable for the source of the contract.

var compiled = solc.compile(source)

Create a variable for the compiled contract.


Query the compiled contract and view the bytecode and opcodes.


View the ABI, which is the public facing interface that shows what methods are available to call.

var abi = JSON.parse(compiled.contracts.Introduction.interface)

Set the ABI as a variable.

var IntroductionContract = web3.eth.contract(abi)

Create a contract object that is deployed to the ethereum testrpc blockchain.

var deployed ={
from: web3.eth.accounts[0],
data: compiled.contracts.Introduction.bytecode,
gas: 4700000,
gasPrice: 5,
}, (error, contract) => { })

Make a variable of the deployed contract.

web3.eth.getTransacton("[[transaction id]]")

In your testrpc terminal window you will see that the contract has gone through. A contract and a transaction address will be posted. Find transaction info with the above command.


View the address of the deployed contract.


Call a function on the contract. In this case, we will call the displayMessage function and the message we input into the solidity.

Disclaimer: The author is the founder of MLG Blockchain. This tutorial was originally published on MLG Blockchain.

MLG Blockchain is a blockchain development and consulting firm based in Toronto that is focused on building next generation applications using blockchain and smart contract technology. See more blockchain development tutorials on the MLG Blockchain blog.