Transfer funds, mine Ether, and execute smart contracts.
In Part 1, we covered Ethereum basics and installed the Geth client, created accounts, and ran initial tests. Part 2 guided us through setting up a private blockchain with two nodes. Now, we’ll execute transactions, mine Ether, and deploy smart contracts—the core of Ethereum’s innovation.
Updating Geth for Ethereum 1.8
To ensure compatibility with Geth 1.8, follow these steps:
Remove outdated Golang:
sudo apt-get remove golang sudo apt-get autoremoveInstall dependencies:
sudo apt-get install git golang libgmp3-devInstall Golang 1.9.2:
wget https://dl.google.com/go/go1.9.2.linux-armv6l.tar.gz sudo tar -C /usr/local -xzf go1.9.2.linux-armv6l.tar.gz export PATH=$PATH:/usr/local/go/binAdd the last line to
~/.profilefor persistence.Build Geth 1.8:
mkdir src && cd src git clone -b release/1.8 https://github.com/ethereum/go-ethereum.git cd go-ethereum make sudo cp build/bin/geth /usr/local/bin/
Transactions and Mining on the Private Blockchain
Step 1: Check Account Balances
Use this command in the Geth console:
web3.fromWei(eth.getBalance(eth.coinbase), "ether")- Laptop: Pre-funded account (e.g., 100 Ether).
- Raspberry Pi: Zero balance initially.
Step 2: Transfer Funds
Unlock the sender’s account:
personal.unlockAccount(eth.coinbase, "")Send Ether:
eth.sendTransaction({ from: eth.coinbase, to: "0xRaspberryPiAddress", value: web3.toWei(0.1, "ether") })
Step 3: Sync via Mining
Start mining on one node to confirm transactions:
miner.start()- Monitor sync status with
admin.peers. - Stop mining with
miner.stop().
Deploying Your First Smart Contract
1. Install Solidity Compiler
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc2. Write the Contract
Save as Greeter.sol:
contract Mortal {
address owner;
function Mortal() { owner = msg.sender; }
function kill() { if (msg.sender == owner) selfdestruct(owner); }
}
contract Greeter is Mortal {
string greeting;
function Greeter(string _greeting) public { greeting = _greeting; }
function greet() constant returns (string) { return greeting; }
}3. Compile and Deploy
solc -o target --bin --abi Greeter.solLoad the contract via JavaScript (greeter.js):
var greeterFactory = eth.contract([ABI_JSON]);
var greeterCompiled = "0x" + "BYTECODE";
var _greeting = "Hello DesignSpark!";
greeterFactory.new(_greeting, {from: eth.accounts[0], data: greeterCompiled, gas: 1000000});4. Execute the Contract
greeter.greet(); // Returns "Hello DesignSpark!"FAQs
Q1: Why is my transaction pending?
A: Ensure a miner is active to process transactions. Use miner.start().
Q2: How do I reset the blockchain?
A: Run:
geth removedb --datadir .designsparkThen reinitialize the genesis block.
Q3: What’s the gas cost for calling greet()?
A: Zero—it’s a read-only function with no state change.
Conclusion
We’ve:
- Transferred Ether between accounts.
- Mined blocks to confirm transactions.
- Deployed and interacted with a smart contract.
👉 Learn more about Ethereum development or explore advanced contract use cases.
Next: Scaling private networks with additional nodes.
— Andrew Back
Open-source advocate and Director at the Free and Open Source Silicon Foundation.