How to deploy a smart contract on ethereum testnet?

This is a step by step tutorial for people who want to learn how to deploy a contract to ethereum testnet. More and more people are interested on smart contract development on ethereum nowadays. When I started to learn solidity, the first thing I wanted to do is to deploy a contract and see what a smart contract can do on the blockchain. Therefore I decided to write a blog to share my experience about how I deployed contracts on ethereum testnet.

1. Write a contract. In this case, we are using the simplest contract from solidity official document.

pragma solidity ^0.4.0;

contract SimpleStorage {
uint storedData;

function set(uint x) {
storedData = x;
}

function get() constant returns (uint) {
return storedData;
}
}

2. The testnet I’m using here is Roptsen. You can get some free ether for deploying contracts at this faucet website: http://faucet.ropsten.be:3001/.

3. Using a wallet to deploy the contract. I’m using Parity for myself. There are many other options on the market. Should be very similar. For starting parity to connect with Ropsten testnet, you can use following command:

$ parity — chain ropsten — bootnodes “enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303,enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303”

open your browser at localhost:8080, you can see parity web UI:

4. Open the contract tab, click deploy button, you can fill the form to submit your contract to the testnet.

5. To complete the form, you need to get the abi / solc combined ouput for the contract. You can save the contract in a storage.sol file. Using the following command to compile this file to get the output (you might to need to install solc first):

$ solc --combined-json abi,bin storage.sol

the output is:

{"contracts":{"storage.sol:SimpleStorage":{"abi":"[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]","bin":"6060604052341561000f57600080fd5b5b60ce8061001e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b11460475780636d4ce63c146067575b600080fd5b3415605157600080fd5b60656004808035906020019091905050608d565b005b3415607157600080fd5b60776098565b6040518082815260200191505060405180910390f35b806000819055505b50565b6000805490505b905600a165627a7a72305820fbe58fb47842b138c5fd44d533bd6dd9324435d415c78395941197f0e01d69950029"}},"version":"0.4.16+commit.d7661dd9.Linux.g++"}

6. After you complete the form for deploying the contract, you can submit the deployment request to deploy it to the testnet.

7. Now you can see the deployed contract on the testnet blockchian: https://ropsten.etherscan.io/address/0x18A0fa8e30f419c26744dBDC149c7de0fCea92D0

Deploying smart contracts is fun. It is even more fun to interact with them on the blockchain. I usually learn more and faster when my hands get dirty. If you have any other questions, please leave your questions in the comments. Thanks!

Click more to read about smart contracts
Like what you read? Give Bleev.In a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.