Exploring Ethereum with Raspberry Pi Part 3: Transactions on a Private Blockchain

·

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:

  1. Remove outdated Golang:

    sudo apt-get remove golang
    sudo apt-get autoremove
  2. Install dependencies:

    sudo apt-get install git golang libgmp3-dev
  3. Install 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/bin

    Add the last line to ~/.profile for persistence.

  4. 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")

Step 2: Transfer Funds

  1. Unlock the sender’s account:

    personal.unlockAccount(eth.coinbase, "")
  2. 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()

Deploying Your First Smart Contract

1. Install Solidity Compiler

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc

2. 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.sol

Load 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 .designspark

Then 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:

  1. Transferred Ether between accounts.
  2. Mined blocks to confirm transactions.
  3. 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.