私有鏈與本地chainlink節點搭建
- 本地私有鏈搭建
- 創建檔案夾以保存檔案
- 在node1下輸入命令創建賬戶,輸入并記住密碼
- 呼叫puppeth創建私有鏈創世紀檔案,配置方法可參考如下
- 初始化私有鏈
- 啟動geth
- Chainlink節點
- 配置PostgreSQL
- 搭建chainlink節點
- 部署LinkToken合約
- 組態檔搭建chainlink節點
- 啟動chainlink
本地私有鏈搭建
在搭建私有鏈之前需要安裝geth
Version: 1.10.1-stable //我的geth版本
創建檔案夾以保存檔案
創建如下的檔案目錄
/myChain
├── chainlink
└── localChain
├── node1
在node1下輸入命令創建賬戶,輸入并記住密碼
sudo geth --datadir ./ account new //賬戶用于后面填入初始以太的賬戶
呼叫puppeth創建私有鏈創世紀檔案,配置方法可參考如下
- 要選擇
Clique - proof-of-authority配置創建POA鏈 - 要設定
Which accounts should be pre-funded? (advisable at least one)填入上面創建的賬戶地址用于設定初始的以太 Which accounts are allowed to seal? (mandatory at least one)設定初始的挖礦賬戶,依舊填入上面創建的賬戶
+-----------------------------------------------------------+
| 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)
> testChain
ERROR[04-09|13:47:08.779] I also like to live dangerously, still no spaces, hyphens or capital letters
> testchain
Sweet, you can set this via --network=testchain next time!
INFO [04-09|13:47:19.771] Administering Ethereum network name=testchain
WARN [04-09|13:47:19.771] No previous configurations found path=/root/.puppeth/testchain
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)
> 0x24829d5D928c9f1aE2B8eFC13a24C42b6EB1846D
> 0x
Which accounts should be pre-funded? (advisable at least one)
> 0x24829d5D928c9f1aE2B8eFC13a24C42b6EB1846D
> 0x
Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)
>
Specify your chain/network ID if you want an explicit one (default = random)
>
INFO [04-09|13:49:02.108] 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 testchain.json, testchain-aleth.json, testchain-harmony.json, testchain-parity.json
> testchain
INFO [04-09|13:49:30.973] Saved native genesis chain spec path=testchain.json/testchain.json
ERROR[04-09|13:49:30.973] Failed to create Aleth chain spec err="unsupported consensus engine"
ERROR[04-09|13:49:30.973] Failed to create Parity chain spec err="unsupported consensus engine"
INFO [04-09|13:49:30.975] Saved genesis chain spec client=harmony path=testchain.json/testchain-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
> ^C
完成上面的步驟后,可以得到testchain.json這個檔案,這就是創建私有鏈所需要的創世紀檔案
初始化私有鏈
在node1下初始化
sudo geth --datadir ./ init testchain.json
配置成功如下
INFO [04-09|14:04:53.526] Maximum peer count ETH=50 LES=0 total=50
INFO [04-09|14:04:53.526] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [04-09|14:04:53.527] Set global gas cap cap=25000000
INFO [04-09|14:04:53.527] Allocated cache and file handles database=/myChain/localChain/run/geth/chaindata cache=16.00MiB handles=16
INFO [04-09|14:04:53.534] Writing custom genesis block
INFO [04-09|14:04:53.563] Persisted trie from memory database nodes=355 size=50.43KiB time=2.522668ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [04-09|14:04:53.564] Successfully wrote genesis state database=chaindata hash="7304a9…c1e849"
INFO [04-09|14:04:53.564] Allocated cache and file handles database=/myChain/localChain/run/geth/lightchaindata cache=16.00MiB handles=16
INFO [04-09|14:04:53.568] Writing custom genesis block
INFO [04-09|14:04:53.582] Persisted trie from memory database nodes=355 size=50.43KiB time=2.078084ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [04-09|14:04:53.583] Successfully wrote genesis state database=lightchaindata hash="7304a9…c1e849"
啟動geth
sudo geth --datadir ./ --networkid 47505 --allow-insecure-unlock console
此處的47505是創建puppeth創世紀塊中可以自己指定也可隨機生成的,若是隨機生成需要在testchain.json中查看networkid
到此為止,私有鏈就創建完畢了,下一步搭建在本地的chainlink節點
Chainlink節點
需要安裝Docker 、PostgreSQL
Docker version 20.10.5, build 55c4c88 //我的docker版本
psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1) // 我的psql版本
配置PostgreSQL
安裝PostgreSQL可參考這篇教程
按照這篇教程的步驟一步步完成即可
需要注意的是一下兩個報錯
報錯一
在創建完成my_user后試圖連接會報錯如下
psql: FATAL: Peer authentication failed for user "my_user"
參考這篇教程需要改的檔案的部分內容要改成如下形式,要不然還是會報錯
# Database administrative login by Unix domain socket
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
(我記得要改的內容只有第一行的md5和第二行的trust?)
報錯二
在呼叫連接資料庫中,會提示不存在資料
解決方式可參考這篇博客
輸入CREATE DATABASE chainlink WITH OWNER my_user ENCODING 'UTF8';可解決
結果如下
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+-----------------------
chainlink | my_user | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
現在我們的PostgreSQL也已經配置完畢
搭建chainlink節點
搭建程序可參考這篇博客
部署LinkToken合約
首先需要在已經建立好的私有鏈上部署LinkToken.sol合約
以如下方式啟動geth
sudo geth --datadir ./ -networkid 47505 --rpc --ws --rpcaddr "0.0.0.0" --rpcport 80 --allow-insecure-unlock console
啟動的 --rpc --ws 為必須
--rpcaddr "0.0.0.0" 與 --rpcport 80 視配置要求決定

將合約部署在私鏈上如下,利用transfer函式可以進行轉LINK幣操作
組態檔搭建chainlink節點
首先在我們的chainlink目錄下
mkdir .chainlink
cd .chainlink
vim .env
填入如下引數
ROOT=/chainlink
LOG_LEVEL=debug
ETH_CHAIN_ID=47505 // 你的ChainID
MIN_OUTGOING_CONFIRMATIONS=0
MIN_INCOMING_CONFIRMATIONS=0
LINK_CONTRACT_ADDRESS=0xC64E8Ae217d72cd8cFdf321Db81227E0e05C9661 //部署LinkToken合約地址
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
ALLOW_ORIGINS=*
ETH_URL=ws://localhost:8546 // RPC介面地址
DATABASE_URL=postgresql://my_user:123@localhost:5432/chainlink?sslmode=disable
DATABASE_TIMEOUT=0
在DATABASE_URL 需要注意的要點是
- my_user 是資料庫的用戶名,即創建資料庫時你自己創建的用戶
- 123是創建資料庫的密碼
- localhost:5432是psql的埠地址 (好像是
- chainnlink是你創建的database的名字
啟動chainlink
.chainlink下輸入
docker run --net host -p 6688:6688 -v ~/.chainlink:/chainlink -it --env-file=.env smartcontract/chainlink local n
提示輸入密碼、郵箱、郵箱密碼后,即可進入

瀏覽器輸入你的ip:6688即可進入chainlink控制臺

到此為止,我們的本地私有鏈的chainlink節點已經部署完畢啦!
特別鳴謝碩寶的友情支持(
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/274462.html
標籤:區塊鏈
上一篇:猛如虎的“rm -rf”指令
