token fun
A little tutorial showing you how to create your own ERC20 tokens using Solidity on the Ethereum testnet
Rinkeby.
Preface
To get started, you need Ubuntu Linux running. An easy way is to
Then you need to install
- Solidity (object-oriented programming language for writing smart contracts);
- Geth (command line interface for running a full ethereum node implemented in Go).
To do this, execute the following:
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository -y ppa:ethereum/ethereum
$ sudo apt-get update
$ sudo apt-get install geth solc
Check your installation:
$ solc --version
$ geth version
See more details
here.
Solidity Deployment
Synchronize blockchai:
$ geth --rinkeby --fast
This will take a couple of minutes. Once you see something like this in the terminal, you are up to date (note that an average block time is 15s):
INFO [08-01|14:53:24] Imported new chain segment blocks=1 txs=1
mgas=0.021 elapsed=1.998ms mgasps=10.505 number=638703
hash=273388…bd5211
Then you can CTR-C.
To launch the CLI:
$ geth attach $HOME/.ethereum/rinkeby/geth.ipc
Create an address (account) on the Rinkeby testnet:
$ geth --rinkeby account new
Enter password and save address.
Start Geth:
$ geth --rinkeby --rpc --rpccorsdomain '*' --rpcapi
"eth,net,web3,personal" --unlock 0 --password <(echo XXX)
Go to:
Get ETH:
- Go to https://www.rinkeby.io/ and click "Crypto Faucet".
- You need a GitHub account.
- Login to create a Gist: description and filename can be anything, however, the first line (starting with "1") needs to contain the address you generated above, preceded by "0x" (see example).
- Refresh the GUI at http://ethereum.github.io/browser-solidity/ (and choose "Web3 Provider" again)
Now you should have an account balance showing a few ether.
Deploy Test Contract
Set up:
- In http://ethereum.github.io/browser-solidity/ add a new contract (plus sign top left).
- Fill in example code from here.
- Click "Create" (orange/pink button right-hand side).
- Wait for transaction to be mined.
- Check terminal synchronizing blocks: you should see the address of the new contact "contract=0x0498b6289f48e28124ec23c30993fcf59af22092".
- You should have less ether (top right).
- Check contract address in https://rinkeby.etherscan.io/.
Play:
- You should have buttons in the browser on the right-hand side (http://ethereum.github.io/browser-solidity/) corresponding to the getter and setter functions.
- Enter in "set": 2,"MyAddr",42
- Entering 2 in "getAmount" or "getAddr" should return "42" and "MyAddr", respectively.
Create ERC20 Token
- Copy code from here into http://ethereum.github.io/browser-solidity/.
- Deploy contract with "Create" button ("browser/myToken.sol/MyToken").
- Check "totalSupply" button.
- Check your balance by putting your account address you generated with Geth above into the "balanceOf" field (right-hand side). NB: address is in quotes and add "0x" if missing in the beginning of the string.
- Check contract address (from synchronization terminal or "Copy address" button in browser) in
With the
parity wallet (stop synchronizing terminal and go to
http://127.0.0.1:8180/ ) ERC20 tokens can be stored. Create a new wallet address. Stop parity and restart Geth. Click " transfer" button with your parity address in quotes and some amount.
Voila, you just did an ICO and transferred some tokens.
See
my example token (
original address and
my parity wallet).