Setup Private Node Blockchain Ethereum Network dan Bitcoin (Geth)
Assalamualaikum, saya berkongsi kaedah secara asas memasang, konfigurasi blockchain Ethereum dan juga menjadi panduan untuk kita bangunkan Bitcoin. Tutorial ni saya menggunakan Etherium yang popular iaitu Ethereum Client (Geth) dan saya menggunakan windows 10 dan inshaa Allah untuk tutorial akan datang saya akan menggunakan MacOS dan juga Linux. Selain daripada itu juga tutorial ini, setup menggunakan 1 node sahaja (single node). Next, saya akan buatkan tutorial untuk lebih daripada 1 nodes.
Langkah 1 : Download Geth.
Anda boleh dapatkan installer Geth di https://geth.ethereum.org/downloads/
Download versi windows dan jangan lupa tick (development tools).
Langkah 2 : Memasang Geth.
Menyemak pemasangan Geth
Langkah 3 : Cipta folder Blockchain Data
Blockchain memerlukan tempat untuk menyimpan rekod @ block. Jadi kita perlu sediakan folder. Contoh saya buat adalah :
- Create folder poachain
- Create sub folder poachain> node1 (mudah jika kita nak setup lebih daripada 1 node)
- Create sub folder poachain> node 1 > chain-data
D:\Privategeth\poachain\node1\chain-data
Langkah 4 : Cipta akaun Baharu
Sebelum langkah berikutnya, perkara penting adalah kita perlu mencipta akaun terlebih dahulu. Disini, kita perlukan masukkan password.
geth account new –datadir accounts
Selepas command ini, folder account/keystore akan dibina untuk setiap akaun.
Untuk mendapatkan alamat akaun adalah dengan merujuk kepada files di dalam keystore bermula UTC….
iaitu, account address adalah : f5a0a6e749291f647ba11e16c021c9d67b5ed2ee
untuk lihat semua akaun, boleh guna command ini
geth account list –datadir accounts
D:\Privategeth>geth account list –datadir accounts
INFO [01-26|12:28:25.296] Maximum peer count ETH=50 LES=0 total=50
INFO [01-26|12:28:25.348] Set global gas cap cap=50,000,000
Account #0: {f5a0a6e749291f647ba11e16c021c9d67b5ed2ee} keystore://D:\Privategeth\accounts\keystore\UTC–2022-01-26T04-07-54.108225900Z–f5a0a6e749291f647ba11e16c021c9d67b5ed2ee
Langkah 5 : Jana Genesis block
Apa itu genesis bloc ?? ia merupakan block pertama di dalam rangkaian blockchain yang kita ingin bangunkan.tinggi (height block adalah 1) dan tidak memang sebarang transaksi dan block yang baharu akan bergantung kepada block genesis ini. Anda boleh lihat genesis block di mainnet (live etherium) melalui https://etherscan.io/block/0
Oleh itu di dalam persekitaran TestNet (Bukan Production Network Mainnet) , langkah pertama adalah kita perlu jana block genesis (block pemula).
Sebelum kita menjana block genesis, konsensus blockchain terdiri daripada 2 jenis iaitu POA (Proof Of Authority – dapp) dan POW (Proof Of Work – Bitcoin). Ulasan ini saya akan ulaskan di dalam tutorial akan datang.
Ok, kita mulakan dengan command puppeth.exe (publish etherium)
D:\Privategeth>puppeth.exe
D:\Privategeth>puppeth.exe
+———————————————————–+
| Welcome to puppeth, your Ethereum private network manager |
| |
| This tool lets you create a new Ethereum network down to |
| the genesis block, bootnodes, miners and ethstats servers |
| without the hassle that it would normally entail. |
| |
| Puppeth uses SSH to dial in to remote servers, and builds |
| its network components out of Docker containers using the |
| docker-compose toolset. |
+———————————————————–+
Please specify a network name to administer (no spaces, hyphens or capital letters please)
> privatepoa
Sweet, you can set this via –network=privatepoa next time!
[32mINFO [0m[01-26|11:47:57.401] Administering Ethereum network [32mname[0m=privatepoa
[33mWARN [0m[01-26|11:47:57.723] No previous configurations found [33mpath[0m=.puppeth\privatepoa
What would you like to do? (default = stats)
1. Show network stats
2. Configure new genesis
3. Track new remote server
4. Deploy network components
> 2
What would you like to do? (default = create)
1. Create new genesis from scratch
2. Import already existing genesis
> 1
Which consensus engine to use? (default = clique)
1. Ethash – proof-of-work
2. Clique – proof-of-authority
> 2
How many seconds should blocks take? (default = 15)
> 5
Which accounts are allowed to seal? (mandatory at least one)
> 0xf5a0a6e749291f647ba11e16c021c9d67b5ed2ee (alamat akaun yang dihasilkan daripada langkah sebelum ini)
> 0x
Which accounts should be pre-funded? (advisable at least one)
> 0xf5a0a6e749291f647ba11e16c021c9d67b5ed2ee (alamat akaun yang dihasilkan daripada langkah sebelum ini)
> 0x
Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)
> no
Specify your chain/network ID if you want an explicit one (default = random)
> 496
[32mINFO [0m[01-26|11:55:03.467] Configured new genesis block
What would you like to do? (default = stats)
1. Show network stats
2. Manage existing genesis
3. Track new remote server
4. Deploy network components
> 2
1. Modify existing configurations
2. Export genesis configurations
3. Remove genesis configuration
> 2
Which folder to save the genesis specs into? (default = current)
Will create privatepoa.json, privatepoa-aleth.json, privatepoa-harmony.json, privatepoa-parity.json
> genesispoa
[32mINFO [0m[01-26|11:56:00.069] Saved native genesis chain spec [32mpath[0m=genesispoa\privatepoa.json
[31mERROR[0m[01-26|11:56:00.069] Failed to create Aleth chain spec [31merr[0m=”unsupported consensus engine”
[31mERROR[0m[01-26|11:56:00.070] Failed to create Parity chain spec [31merr[0m=”unsupported consensus engine”
[32mINFO [0m[01-26|11:56:00.072] Saved genesis chain spec [32mclient[0m=harmony [32mpath[0m=genesispoa\privatepoa-harmony.json
What would you like to do? (default = stats)
1. Show network stats
2. Manage existing genesis
3. Track new remote server
4. Deploy network components
***************** Press CTR + C to close puppeth *********************
privatepoa.json
{
“config”: {
“chainId”: 496,
“homesteadBlock”: 0,
“eip150Block”: 0,
“eip150Hash”: “0x0000000000000000000000000000000000000000000000000000000000000000”,
“eip155Block”: 0,
“eip158Block”: 0,
“byzantiumBlock”: 0,
“constantinopleBlock”: 0,
“petersburgBlock”: 0,
“istanbulBlock”: 0,
“clique”: {
“period”: 5,
“epoch”: 30000
}
},
“nonce”: “0x0”,
“timestamp”: “0x61f0c478”,
“extraData”: “0x00000000000000000000000000000000000000000000000000000000000000006c72e2fcd7dfc7a59116a3224ed87fc49fc11a8a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000”,
“gasLimit”: “0x47b760”,
“difficulty”: “0x1”,
“mixHash”: “0x0000000000000000000000000000000000000000000000000000000000000000”,
“coinbase”: “0x0000000000000000000000000000000000000000”,
“alloc”: {
“6c72e2fcd7dfc7a59116a3224ed87fc49fc11a8a“: {
“balance”: “0x200000000000000000000000000000000000000000000000000000000000000”
}
},
“number”: “0x0”,
“gasUsed”: “0x0”,
“parentHash”: “0x0000000000000000000000000000000000000000000000000000000000000000”,
“baseFeePerGas”: null
}
files genesis block yang dijana menggunakan command puppeth tadi disimpan di dalam folder ini.
D:\Privategeth\genesispoa
salin files ini (privatepoa.json) ke D:\Privategeth\
Langkah 5 : Tambah nilai Ether untuk akaun di dalam Genesis files
Untuk maklumat, transaksi di dalam Etherium memerlukan gas atau ether (wang cripto/maya) . Jadi untuk ini kita laras ke nilai ether kepada 1 million Ethers.
100000000000000000000000
Contoh seperti di bwah bagi files yang telah diedit
“alloc”: {
“f5a0a6e749291f647ba11e16c021c9d67b5ed2ee“: {
“balance”: “0x100000000000000000000000”
}
},
Langkah 6 : Melaksanakan janaan Genesis Block Untuk Node 1
Setelah kita menjana files genesis.block, kita perlu laksanakan di dalam blockchain network
geth -identity “node1” init privatepoa.json –datadir poachain/node1/chain-data
D:\Privategeth>geth -identity “node1” init privatepoa.json –datadir poachain/node1/chain-data
INFO [01-26|12:39:28.121] Maximum peer count ETH=50 LES=0 total=50
INFO [01-26|12:39:28.175] Set global gas cap cap=50,000,000
INFO [01-26|12:39:28.177] Allocated cache and file handles database=D:\Privategeth\poachain\node1\chain-data\geth\chaindata cache=16.00MiB handles=16
INFO [01-26|12:39:28.661] Writing custom genesis block
INFO [01-26|12:39:28.663] Persisted trie from memory database nodes=1 size=151.00B time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-26|12:39:28.672] Successfully wrote genesis state database=chaindata hash=9dc944..0b080d
INFO [01-26|12:39:28.675] Allocated cache and file handles database=D:\Privategeth\poachain\node1\chain-data\geth\lightchaindata cache=16.00MiB handles=16
INFO [01-26|12:39:28.852] Writing custom genesis block
INFO [01-26|12:39:28.856] Persisted trie from memory database nodes=1 size=151.00B time=0s gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-26|12:39:28.864] Successfully wrote genesis state database=lightchaindata hash=9dc944..0b080d
Apabila kita melaksanakan command di atas, beberapa files blockchain akan dicipta seperti di atas untuk menyimpan transaksi blockchain.
Langkah 6 : Memulakan Node 1
geth –networkid 496 –rpc –rpcaddr “0.0.0.0” –rpcport “40101” –port “40001” –rpcapi personal,db,eth,net,web3,clique –rpccorsdomain “*” –nodiscover –ipcdisable –datadir poachain/node1/chain-data console
atau
geth –datadir “poachain\node1\chain-data” –syncmode “full” –port 30305 –http –http.addr “localhost” –http.port 8546 –http.api “personal,eth,net,web3,txpool,miner” –networkid 496 –identity node1 console
496 – Adalah network id yang diinput masa kita menghasilkan files genesis block mengguna puppeth.
atau boleh menggunakan command ini
geth --datadir=poachain/node1/chain-data
atau
geth --datadir "poachain\node1\chain-data" --networkid 496 --port 11111 --nodiscover console
atau
D:\Privategeth>geth --datadir=poachain/node1/chain-data
INFO [01-26|12:50:12.130] Starting Geth on Ethereum mainnet...
INFO [01-26|12:50:12.185] Bumping default cache on mainnet provided=1024 updated=4096
INFO [01-26|12:50:12.192] Maximum peer count ETH=50 LES=0 total=50
INFO [01-26|12:50:12.198] Set global gas cap cap=50,000,000
INFO [01-26|12:50:12.203] Allocated trie memory caches clean=614.00MiB dirty=1024.00MiB
INFO [01-26|12:50:12.206] Allocated cache and file handles database=D:\Privategeth\poachain\node1\chain-data\geth\chaindata cache=2.00GiB handles=8192
INFO [01-26|12:50:12.981] Opened ancient database database=D:\Privategeth\poachain\node1\chain-data\geth\chaindata\ancient readonly=false
INFO [01-26|12:50:12.987] Initialised chain configuration config="{ChainID: 496 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: 0, Muir Glacier: <nil>, Berlin: <nil>, London: <nil>, Arrow Glacier: <nil>, MergeFork: <nil>, Engine: clique}"
INFO [01-26|12:50:12.996] Initialising Ethereum protocol network=1 dbversion=<nil>
INFO [01-26|12:50:13.002] Loaded most recent local header number=0 hash=9dc944..0b080d td=1 age=1h2m5s
INFO [01-26|12:50:13.006] Loaded most recent local full block number=0 hash=9dc944..0b080d td=1 age=1h2m5s
INFO [01-26|12:50:13.011] Loaded most recent local fast block number=0 hash=9dc944..0b080d td=1 age=1h2m5s
WARN [01-26|12:50:13.015] Failed to load snapshot, regenerating err="missing or corrupted snapshot"
INFO [01-26|12:50:13.018] Rebuilding state snapshot
INFO [01-26|12:50:13.021] Resuming state snapshot generation root=20d761..a57299 accounts=0 slots=0 storage=0.00B elapsed=0s
INFO [01-26|12:50:13.021] Regenerated local transaction journal transactions=0 accounts=0
INFO [01-26|12:50:13.026] Generated state snapshot accounts=1 slots=0 storage=50.00B elapsed=5.544ms
INFO [01-26|12:50:13.026] Stored checkpoint snapshot to disk number=0 hash=9dc944..0b080d
INFO [01-26|12:50:13.036] Gasprice oracle is ignoring threshold set threshold=2
WARN [01-26|12:50:13.036] Error reading unclean shutdown markers error="leveldb: not found"
INFO [01-26|12:50:13.044] Starting peer-to-peer node instance=Geth/v1.10.15-stable-8be800ff/windows-amd64/go1.17.5
INFO [01-26|12:50:13.201] New local node record seq=1,643,172,613,199 id=106d722c882c9c9d ip=127.0.0.1 udp=30303 tcp=30303
INFO [01-26|12:50:13.212] Started P2P networking self=enode://b5109d4f552831ae2ce4a9a872398fc4ab3992fcfec0fe768db4fccaf26f4e2a097a72a11a2bfad7343974e0060de7d475b4a6313e10dbfdb77d59e344b575b1@127.0.0.1:30303
INFO [01-26|12:50:13.216] IPC endpoint opened url=\\.\pipe\geth.ipc
INFO [01-26|12:50:16.989] New local node record seq=1,643,172,613,200 id=106d722c882c9c9d ip=103.53.32.18 udp=30303 tcp=30303
INFO [01-26|12:50:23.638] Looking for peers peercount=0 tried=21 static=0
INFO [01-26|12:50:33.690] Looking for peers peercount=0 tried=37 static=0
INFO [01-26|12:50:43.770] Looking for peers peercount=0 tried=30 static=0
INFO [01-26|12:50:53.928] Looking for peers peercount=0 tried=32 static=0
INFO [01-26|12:51:03.991] Looking for peers peercount=0 tried=38 static=0
INFO [01-26|12:51:14.007] Looking for peers peercount=0 tried=33 static=0
INFO [01-26|12:51:24.031] Looking for peers peercount=0 tried=36 static=0
INFO [01-26|12:51:34.306] Looking for peers peercount=0 tried=37 static=0
INFO [01-26|12:51:44.336] Looking for peers peercount=0 tried=30 static=0
INFO [01-26|12:51:54.559] Looking for peers peercount=0 tried=34 static=0
INFO [01-26|12:52:04.970] Looking for peers peercount=0 tried=37 static=0
INFO [01-26|12:52:14.982] Looking for peers peercount=0 tried=33 static=0
INFO [01-26|12:52:24.982] Looking for peers peercount=0 tried=33 static=0
Ok,berjaya untuk upkan node 1 blockchain . Anda boleh lihat
INFO [01-26|12:50:13.212] Started P2P networking self=enode://b5109d4f552831ae2ce4a9a872398fc4ab3992fcfec0fe768db4fccaf26f4e2a097a72a11a2bfad7343974e0060de7d475b4a6313e10dbfdb77d59e344b575b1@127.0.0.1:30303
INFO [01-26|12:50:13.216] IPC endpoint opened url=\\.\pipe\geth.ipc
"IPC Endpoint will open" menunjukkan ia adah bersedia untuk berkomunikasi dengan Wallet Metamask, Etherium Wallet,
Mist.
.
cuba guna arahan beberapa command di dalam consol apa kita connect ke node blockchain.
- create accound di dalam node1
> personal.newAccount("123456")
INFO [01-31|11:13:25.185] Your new key was generated address=0x778629230545866B92b5893fE26666702D3a02C4
WARN [01-31|11:13:25.190] Please backup your key file! path=D:\Privategeth\poachain\node1\chain-data\keystore\UTC--2022-01-31T03-13-22.374269400Z--778629230545866b92b5893fe26666702d3a02c4
WARN [01-31|11:13:25.200] Please remember your password!
"0x778629230545866b92b5893fe26666702d3a02c4"
> eth.accounts
["0x778629230545866b92b5893fe26666702d3a02c4"]
> miner.start(1)
INFO [01-31|11:16:48.846] Updated mining threads threads=1
null
> miner.start(1)
INFO [01-31|11:16:55.627] Updated mining threads threads=1
null
> miner.stop()
> eth.getBalance(eth.accounts[0])
0
> eth.blockNumber
0
Recent Comments