Selamat datang di artikel pertama siri go-ethereum baru kami!
Dalam 10 minit akan datang, anda akan:
- Ketahui glosari blockchain pertama tanpa pengetahuan ekosistem yang diperlukan sebelumnya
- Siapkan node ujian yang diselaraskan sepenuhnya ("pelanggan / pelayan") dalam masa kurang dari 10 minit
- Buat akaun anda dan terima transaksi 8ETH dari yayasan Ethereum secara PERCUMA
Moto kami adalah, berlatih sebelum teori - jadi mari kita langsung memasuki pemasangan nod ujian Ethereum yang diselaraskan sepenuhnya yang disambungkan ke rangkaian ujian Rinkeby!
Geth
Geth
adalah antara muka baris perintah (CLI), binari, program, dan klien yang dikompilasi untuk menjalankan nod Ethereum penuh yang dilaksanakan di Go.
Kami akan menggunakan Geth untuk:
- jalankan nod Ethereum yang disegerakkan sepenuhnya untuk menyambung ke rangkaian ujian yang dipanggil Rinkeby
- buat akaun baru untuk dapat menghantar dan menerima transaksi
- untuk membaca keadaan EVM, misalnya memeriksa baki akaun apa pun (ingin tahu berapa banyak baki kekasih, teman lelaki, isteri, jiran anda? Ketelusan yang manis!)
Memasang Geth
Kami boleh memasangnya terus dari repositori:
Mac
brew tap ethereum/ethereumbrew install ethereum
Linux
sudo apt-get install software-properties-commonsudo add-apt-repository -y ppa:ethereum/ethereumsudo apt-get updatesudo apt-get install ethereum
Tingkap
Good luck :)
Sahkan pemasangan:
which geth> /usr/local/bin/geth
geth version> Geth> Version: 1.8.20-stable
Pastikan anda menjalankan versi yang sama agar dapat melakukan penyegerakan penuh rangkaian Rinkeby, seperti yang dijelaskan dalam langkah-langkah berikutnya kerana Rinkeby bertindak sebagai pekerja keras berterusan yang disokong oleh Geth 1.8.20.
Menjalankan nod blockchain
Yah, syaitan ada dalam perinciannya ... tetapi sebenarnya sebenarnya mudah. Pujian kepada pemaju Ethereum.
Mari sediakan nod Rinkeby (Ethereum test network yang menggunakan protokol Clique PoA) baru yang diselaraskan sepenuhnya .
Pelaksanaan Rinkeby PoA jauh lebih pantas tetapi kurang selamat. Ia lebih berpusat dari kesepakatan mainnet PoW yang sangat baik menjadi rangkaian ujian. Rinkeby berjaya meluluskan blok baru dengan banyak urus niaga setiap 15-an.
Ok, ok, ok ... Apa maksud perkataan itu?
- Rinkeby: nama rangkaian ujian Proof of Authority
- Node: pada dasarnya pelayan tradisional yang melaksanakan klien / pelayan Ethereum
- Kesimpulan: algoritma yang menentukan bagaimana transaksi akan disahkan, ditambahkan, dan berterusan dalam pangkalan data pada setiap Node
- Sekat: sekumpulan urus niaga dalam susunan rumit yang dihantar di sekitar wayar antara semua nod rangkaian setiap 15an
- Transaksi: jangan memikirkan transaksi bank. Transaksi blockchain adalah perubahan keadaan. Menamakan semula pemilik kontrak pintar dari Alice menjadi Bob? Menukar baki akaun anda dari 1ETH menjadi 5ETH? Menetapkan nilai "foo" pemboleh ubah menjadi "foo_value_123" dalam kontrak pintar anda? Itu urus niaga.
Anda boleh membaca lebih lanjut mengenai cadangan Rinkeby PoA di sini: //github.com/ethereum/EIPs/issues/225
geth --rinkeby --datadir=~/.gophersland_ethereum_r1 --port=30304 --cache=2048 --rpc --rpcport=8546 --rpcapi=eth,web3,net,personal --syncmode=fast
Perintah di atas akan:
- memulakan direktori baru di mana semua data akan disimpan
~/.gophersland_ethereum_r1
. Direktori lalai adalah:~/.ethereum
- mulailah memuat turun sejarah Ethereum yang diperlukan untuk menjadi Node rangkaian baru yang sah dan disegerakkan
- komunikasi akan berlaku melalui port 30304
- cache, sejenis penyangga, akan ditetapkan menjadi 2GB untuk mempercepat proses penyegerakan
- API RPC tambahan akan dilancarkan sehingga kami dapat berkomunikasi dengan simpul kami melalui konsol, GUI yang bagus di port 8546, kemudian

Tunggu beberapa jam sehingga blockchain diselaraskan sepenuhnya.
Nombor blok semasa pada 24 September ialah: 3039786. Pada AMD Ryzen 5 2600, 3.4Ghz saya, proses penyegerakan mengambil masa 3 jam. Oh ya, saya mempunyai PC permainan baru!
Sementara itu anda boleh mengikuti Web3Coach di Twitter atau menyiapkan makan malam, mungkin juga sarapan, pergi ke gim ... katakan saja, blockchain bukanlah pangkalan data terpantas :)
Akhirnya mesej yang dicetak akan:
- INFO [] Jumlah segmen rantai baru yang diimport = 1
- INFO [] Jumlah segmen rantai baru yang diimport = 1
- INFO [] Jumlah segmen rantai baru yang diimport = 1
- INFO [] Jumlah segmen rantai baru yang diimport = 1
Tahniah, anda kini menjadi sebahagian daripada revolusi blockchain dalam masa kurang dari 10 minit !!!
Membuat akaun blockchain pertama anda
Kedai kunci
All the Ethereum accounts and their keys are stored in a directory called the “keystore”. The directory is empty by default as we haven’t created our own account yet!
[email protected]:~$ ls -la ~/.gophersland_ethereum_r1/
drwx------ 4 enchanter enchanter 4096 sep 24 15:26 .drwxr-xr-x 18 enchanter enchanter 4096 sep 24 11:51 ..drwx------ 4 enchanter enchanter 4096 sep 24 15:26 gethsrw------- 1 enchanter enchanter 0 sep 24 15:26 geth.ipcdrwx------ 2 enchanter enchanter 4096 sep 23 09:54 keystore
encha[email protected]:~$ ls -la ~/.gophersland_ethereum_r1/keystore/
drwx------ 2 enchanter enchanter 4096 sep 23 09:54 .drwx------ 4 enchanter enchanter 4096 sep 24 15:26 ..
Account
To create a new account, execute the following, already familiar, geth cmd.
geth --datadir=~/.gophersland_ethereum_r1 account new
You will be prompted to enter a passphrase (this is your SUPER SECRET PASSWORD). This is required for decrypting your newly generated private key associated with your new Ethereum address, as it allows you to use it later on for signing transactions on the blockchain. Note it down somewhere, since we will need it later. But don’t worry if you forget it, this is just a test network anyway.
encha[email protected]:~$ ls -la ~/.gophersland_ethereum_r1/keystore/
drwx------ 2 enchanter enchanter 4096 sep 23 09:54 .drwx------ 4 enchanter enchanter 4096 sep 24 15:26 ..
[email protected]:~$ geth --datadir=~/.gophersland_ethereum_r1 account new
INFO [09-24|15:36:33.566] Maximum peer count ETH=25 LES=0 total=25
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: Repeat passphrase:
Address: {ceee57f2b700c2f37d1476a7974965e149fce2d4}
encha[email protected]:~$ ls -la ~/.gophersland_ethereum_r1/keystore/
drwx------ 2 enchanter enchanter 4096 sep 24 15:36 .drwx------ 4 enchanter enchanter 4096 sep 24 15:26 ..-rw------- 1 enchanter enchanter 491 sep 24 15:36
UTC--2018-09-24T13-36-43.069452577Z--ceee57f2b700c2f37d1476a7974965e149fce2d4
Woohoo! My new Ethereum address is alive: ceee57f2b700c2f37d1476a7974965e149fce2d4.
You will normally encounter this address prefixed with “0x” to indicate the address encoding, HEX.
The newest format of the keyfiles is: UTC---
If you are curious what is inside of the file, feel free to open it! You will see:
Address: your new hex address
Crypto: bunch of mathematical variables responsible for representing your private key in encrypted form, don’t worry about that magic for now
Interesting note: the account generation happens in offline mode and doesn’t require a synced blockchain node. Curious how is it possible to generate a unique address in an offline mode from the technical perspective? We will check out the go-ethereum source code itself in the next article.
Spoiler: it’s because the address is a hash of your public key which is based on your unique, private key.
Okay I have a new shinny Ethereum account, what’s my balance and how do I deposit some testing Ether?
Speaking of Ether… what is it actually?
Ether
Ether is the cryptocurrency powering the Ethereum network. It’s used as a unit of value and for paying miners for validating, appending, and persisting the transactions to the collective DB. But mainly its a technique for preventing SPAM because miners are rewarded 5 (since last month “just” 3) ETH for each successfully mined block. Yes, that’s $600 at the current price on 24th of September, every 15s. Not a bad business.
How to receive a transaction of 8ETH from the Ethereum foundation for FREE
Checking account balance
Let’s make sure our account balance is 0 first, unless someone already managed to send some Ether out of the goodness of their heart.
Geth provides a JavaScript console that can be attached to the executable binary for interacting with the blockchain conveniently. We can connect to it by specifying a socket file that is exposed once Geth boots up. Socket files are very useful for “inter process communication on the same machine”, aka IPC.
You can locate this file in the the default data directory while the Geth program is running:
[email protected]:~$ ls -la ~/.gophersland_ethereum_r1/
drwx------ 4 enchanter enchanter 4096 Sep 24 15:44 .drwxr-xr-x 18 enchanter enchanter 4096 Sep 24 15:47 ..drwx------ 4 enchanter enchanter 4096 Sep 24 15:44 gethsrw------- 1 enchanter enchanter 0 Sep 24 15:44 geth.ipcdrwx------ 2 enchanter enchanter 4096 Sep 24 15:47 keystore
Let’s interact with the Rinkeby network using the “geth attach” cmd in another terminal while your blockchain node is still running. Make sure to pass the absolute path to the IPC file, otherwise you will get an error.
[email protected]:~$ geth attach ipc:/home/enchanter/.gophersland_ethereum_r1/geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.15-stable-89451f7c/linux-amd64/go1.10.1coinbase: 0xceee57f2b700c2f37d1476a7974965e149fce2d4at block: 3044891 (Mon, 24 Sep 2018 16:42:36 CEST)
datadir: /home/enchanter/.gophersland_ethereum_r1modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
> eth.accounts["0xceee57f2b700c2f37d1476a7974965e149fce2d4"]
> eth.syncingfalse
> eth.getBalance("0xceee57f2b700c2f37d1476a7974965e149fce2d4")0
Query blockchain:
eth.accounts: to check your currently available accounts
eth.syncing: to make sure our state, DB is fully up to date with rest of the network to ensure the getBalance response will be based on the latest state
eth.getBalance(“
Receiving a transaction of 8ETH from the Ethereum foundation for FREE
The Ethereum foundation has a very neat program called “Faucet” available online for assigning Ether to accounts requesting it in real-time.
Requesting Ether:
Publish your account address on one of the public social networks
E.g, post a tweet containing your Ethereum address anywhere in the tweet like this one //twitter.com/EnchanterIO/status/1044238559224483841, make sure you tag @Web3Coach and @freeCodeCamp and let us know if you like the tutorial!
Open //www.rinkeby.io/#faucet and paste the tweet URL
Click on “Give me Ether”, choose between 3, 7.5 or 18.75 Ether
Wait few seconds
Query your account balance again


Voilà
You are rich… in a test network. Congratulation for getting so far.
You can continue expanding your blockchain skills by building one from scratch in Go!"