Building upon our previous guide on [Geth deployment for Ethereum testnet](), this article walks through creating and deploying a custom cryptocurrency on the Rinkeby testnet—a sandbox environment for Ethereum developers.
Understanding ERC20 Standards
Ethereum's smart contract ecosystem relies heavily on standardized protocols. The ERC20 token standard (EIP-20) defines a set of rules for creating fungible tokens on Ethereum. Below are key components of the ERC20 interface:
Core Methods
name()
Returns the token’s name (e.g., "StatusNetwork").symbol()
Returns the token’s ticker symbol (e.g., "SNT").decimals()
Specifies the divisibility of the token (e.g.,18for Ether-like units).totalSupply()
Outputs the total circulating supply of tokens.balanceOf(address _owner)
Checks the token balance of a specified address.transfer(address _to, uint256 _value)
Moves tokens from the sender’s account to another address.approve()&transferFrom()
Enables delegated token spending (e.g., for dApps).
Events
Transfer: Logs token transfers between addresses.Approval: Records authorized spending allowances.
Step-by-Step Deployment
1. Writing the Smart Contract
The contract is written in Solidity—a statically typed language for Ethereum. Below is a simplified ERC20 token contract (token.sol):
pragma solidity ^0.7.0;
interface ERC20Standard {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address _owner) external view returns (uint256 balance);
function transfer(address _to, uint256 _value) external returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);
function approve(address _spender, uint256 _value) external returns (bool success);
function allowance(address _owner, address _spender) external view returns (uint256 remaining);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract Token is ERC20Standard {
string private _name = "ansheng";
string private _symbol = "as";
uint8 private _decimals = 18;
uint256 private _totalSupply = 10**19; // 10 tokens with 18 decimals
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
constructor() {
_balances[msg.sender] = _totalSupply;
}
// Implement all ERC20 functions here...
}2. Compiling the Code
Install the Solidity compiler (solc) via Homebrew (macOS):
brew update
brew upgrade
brew tap ethereum/ethereum
brew install solidityCompile the contract:
solc --abi --bin -o solcoutput token.solThis generates Token.abi (ABI definition) and Token.bin (bytecode).
3. Deploying to Rinkeby Testnet
Connect to Geth Console:
geth attach /usr/local/etc/geth/geth.ipcUnlock Accounts:
personal.unlockAccount("0x...", "password", 0);Deploy Contract:
var bytecode = "0x..."; // From Token.bin var abi = [...]; // From Token.abi var contract = eth.contract(abi).new({from: "0x...", data: bytecode, gas: 4700000});- Note the Contract Address (e.g.,
0xe16c...d48).
Interacting with the Token Contract
Using web3.py (Python Library)
from web3 import Web3
web3 = Web3(Web3.HTTPProvider("https://rinkeby.infura.io/v3/YOUR_PROJECT_ID"))
# Load contract
contract_address = Web3.toChecksumAddress("0xe16c...d48")
with open('Token.abi') as f:
ABI = json.load(f)
contract = web3.eth.contract(address=contract_address, abi=ABI)
# Query token info
print(contract.functions.name().call()) # Output: 'ansheng'
print(contract.functions.totalSupply().call()) # Output: 10000000000000000000Key Operations
Transfer Tokens:
contract.functions.transfer("0xRecipientAddress", 100).transact({'from': "0xSenderAddress"})Check Allowances:
contract.functions.allowance("0xOwner", "0xSpender").call()
FAQs
1. Why use Rinkeby over Mainnet?
Rinkeby is a proof-of-authority testnet, ideal for development without real financial risk.
2. How do I get test ETH?
Use Rinkeby’s faucet: https://www.rinkeby.io/#faucet.
3. What if my contract deployment fails?
Ensure your account has sufficient test ETH for gas fees.
👉 Explore more Ethereum development tools
Conclusion
This guide covered ERC20 token creation, compilation, deployment, and interaction on Rinkeby. For further exploration, see the transaction on Etherscan. Happy coding! 🚀