Introduction
This tutorial provides a step-by-step guide to Ethereum development in an Ubuntu 16.04 environment. We'll cover everything from initial setup to deploying smart contracts, ensuring you gain hands-on experience with key tools like Truffle, TestRPC, and Solidity.
Environment Configuration
Key Terminologies
- Ethereum: An open-source blockchain platform enabling smart contracts.
- TestRPC: A local memory-simulated Ethereum environment for development.
- Geth: The official Go-based Ethereum client for interacting with the mainnet.
- Truffle: The most popular development framework for Ethereum.
- Solc: The Solidity compiler for smart contracts.
- Node.js: JavaScript runtime environment for backend tools.
- Web3.js: Ethereum JavaScript API for interacting with the blockchain.
Step 1: Install Node.js and npm (v6.x+)
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install nodejsStep 2: Install Solidity Compiler
sudo npm install -g solc solc-cliStep 3: Install Truffle Suite
sudo npm install -g truffleStep 4: Set Up TestRPC
sudo npm install -g ethereumjs-testrpcStep 5: Install Geth
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc ethereumGetting Started
1. Verify Truffle Installation
truffle version2. Test TestRPC Environment
testrpcOutputs 10 test accounts with private keys and HD wallet details.
3. Initialize a Truffle Project
mkdir ethtest && cd ethtest
truffle initCreates contracts/, migrations/, and test/ directories.
๐ Learn more about Truffle project structure
4. Write Your First Smart Contract
Create SimpleStorage.sol in contracts/:
pragma solidity ^0.4.0;
contract SimpleStorage {
uint storedData;
function set(uint x) { storedData = x; }
function get() constant returns (uint) { return storedData; }
}5. Compile Contracts
truffle compileGenerates JSON artifacts in build/contracts/.
6. Deploy Contracts
- Keep TestRPC running in a separate terminal.
Configure
truffle.js:module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*" } } };Run migration:
truffle migrate
7. Interactive Console
truffle console
> var ss = SimpleStorage.at("0x...")
> ss.get.call()8. Advanced Deployment
For live networks:
live: {
host: "localhost",
port: 8545,
network_id: "*",
gas: 3000000
}truffle migrate --network liveFAQ Section
Q1: Why is my Truffle migration failing?
A: Ensure TestRPC is running and truffle.js is correctly configured with the right network ID and port.
Q2: How do I reset deployments?
A: Use truffle migrate --reset --network live to force redeployment.
Q3: What's the purpose of Migrations.sol?
A: It tracks which migrations have been run on-chain.
Q4: Can I use this with Node.js?
A: Yes! Install dependencies:
npm init
npm install truffle-contract web3๐ Explore advanced Node.js integration
Troubleshooting
- Port 8080 Errors: Ensure no other service is using this port before
truffle serve. - Gas Limit Issues: Adjust
gasintruffle.jsfor complex contracts.