安装go
# go version
go version go1. 21.0 linux/ amd64
# go env GOROOT GOPATH
/ usr/ local/ go
/ root/ go
# vim . bashrc
export PATH= $PATH: / usr/ local/ go / bin
export GOPATH= / root/ go
export PATH= $PATH: / root/ go / bin
# source . bashrc
# echo $GOPATH
/ root/ go
git clone https: / / github. com/ btcsuite/ btcd $GOPATH/ src/ github. com/ btcsuite/ btcd
# cd $GOPATH/ src/ github. com/ btcsuite/ btcd
# GO111MODULE= on go install - v . . / cmd/ ...
# btcd -- version
btcd version 0.23 .3 - beta
cd / nvme2n1/
mkdir btcd
mkdir btcd/ btcd- data
cd btcd/
# vim btcd. conf
[ Application Options]
testnet= 1
rpcuser= test
rpcpass= test@0908
datadir= / nvme2n1/ btcd/ btcd- data
# cat btcd. sh
#! / bin/ bash
nohup btcd -- configfile= / nvme2n1/ btcd/ btcd. conf >> / nvme2n1/ btcd/ btcd. log 2 > & 1 &
go get github. com/ btcsuite/ btcd/ btcutil
go get github. com/ btcsuite/ btcd/ rpcclient
# go run .
2023 / 09 / 08 16 : 50 : 06 Block count: 484510
获取区块高度
# go run .
2023 / 09 / 08 17 : 09 : 14 open / root/ . btcd/ rpc. cert: no such file or directory
exit status 1
运行 btcd 会生成rpc.cert
然后终止运行
btcd
运行 btcd.go
cd $GOPATH/ src
mkdir btcd
cd btcd/
vim btcd. go
connCfg := & rpcclient. ConnConfig{
Host: "localhost:18334" ,
Endpoint: "ws" ,
User: "test" ,
Pass: "test@0909" ,
Certificates: certs,
}
go mod init example/ btcd
go mod tidy
go run .
# go run .
2023 / 09 / 11 14 : 58 : 41 Block count: 2477301