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:
- Launching the GETH Ethereum wallet environment
- Account preparation and creation
- Fund transfers between accounts
- Account unlocking
- Smart contract coding
- 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.logKey parameters:
--dev: Enables POA consensus with a pre-funded developer account--datadir: Specifies blockchain data storage locationconsole: Enters interactive mode
👉 Master Ethereum development with these essential tools
2. Account Preparation
View existing accounts:
eth.accounts
personal.listAccounts3. 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
- Developer accounts start with excessive balances; create secondary accounts for realistic testing
- Always unlock accounts before transactions
- Browser-Solidity simplifies initial development
- Gas costs vary based on contract complexity
👉 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:
- Sufficient account balance
- Correct unlocking password
- Adequate gas limit
- Proper constructor arguments
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:
- Truffle development framework
- ERC-20 token standards
- Decentralized application architectures