How to Run Ethereum's Simplest "Hello World" Smart Contract

·

Introduction

This guide walks you through creating and deploying Ethereum's most basic smart contract—"Hello World." By the end, you'll gain hands-on experience with:

  1. Launching the GETH Ethereum wallet environment
  2. Account preparation and creation
  3. Fund transfers between accounts
  4. Account unlocking
  5. Smart contract coding
  6. Contract deployment and execution

Step-by-Step Implementation

1. Launch GETH Ethereum Wallet

Initialize a developer network node using:

geth --datadir testNet --dev console 2>> test.log

Key parameters:

👉 Master Ethereum development with these essential tools

2. Account Preparation

View existing accounts:

eth.accounts
personal.listAccounts

3. Create New Account

Generate a secondary account for practical testing:

personal.newAccount("your_password")
eth.getBalance(eth.accounts[2]) // Verify new account (0 balance)

4. Fund Transfer

Send ETH from primary to new account:

eth.sendTransaction({
  from: eth.accounts[0], 
  to: eth.accounts[2],
  value: web3.toWei(99, "ether")
})

5. Account Unlocking

Authenticate before deployment:

personal.unlockAccount(eth.accounts[2], "your_password")

6. Smart Contract Coding

Using Browser-Solidity, create this contract:

pragma solidity ^0.4.21;

contract HelloWorld {
  string greeting;
  
  constructor(string _greeting) public {
    greeting = _greeting;
  }
  
  function say() public view returns (string) {
    return greeting;
  }
}

7. Contract Deployment

Modify the auto-generated deployment script:

var _greeting = "Hello World";
var helloContract = web3.eth.contract(/* ABI */);
var hello = helloContract.new(
  _greeting,
  {from: eth.accounts[2], data: '0x...', gas: 4700000},
  function(e, contract){ /* deployment callback */ }
);

8. Execute Contract

Call the deployed contract:

hello.say() // Returns "Hello World"

Key Takeaways

👉 Explore advanced smart contract techniques

FAQ Section

Q1: Why does my new account show 0 ETH?

A: Newly created accounts require manual funding via eth.sendTransaction() from an existing account.

Q2: How do I estimate gas costs?

A: Browser-Solidity provides gas estimates during compilation. For complex contracts, test on testnets first.

Q3: What if my contract deployment fails?

A: Verify:

Q4: Can I modify deployed contracts?

A: Ethereum smart contracts are immutable. You must redeploy revised versions.

Conclusion

This "Hello World" example demonstrates Ethereum's core workflow. While simple, it establishes fundamental concepts for advanced DApp development. Practice account management and transaction flows before progressing to more complex contracts.

For further learning, explore: