区块链Fisco Bcos console控制台的使用

兰涛 lands

前言

以下内容是根据实际使用下来,依据 Fisco Bcos 官网做的实操,对一些重要的命令做了详情演示,删除了一些无关的命令。

内容

账户的使用

每一个账户对应着一对公钥和私钥,如果初次启动 console 是没有账户,为了方便控制台会帮助我们自动生成一个账户。也可以将已有的账户拷贝当 accounts_gm/gm 目录下

账户登录控制台

1
2
3
4
5
6
7
8
# 根据配置默认登录 选择账户文件夹下的第一个配置文件
bash start.sh
# 输入参数:群组号、((-pem、pem文件路径) or (-p12、p12文件路径))
bash start.sh group0 -pem accounts_gm/gm/0x870dd48121072641bbe7efd648e12681d2b345b3.pem

# 切换用户
[group0]: /apps> loadAccount 0xfae566617652bab13fd2260e1da16eb9e864ecaf
Load account 0xfae566617652bab13fd2260e1da16eb9e864ecaf success!

控制台命令列表

基本命令

切换群组

1
2
[group0]: /apps>  switch group2
Switched to group2.

默认节点

1
2
3
4
5
6
7
8
9
# 设置默认节点 默认节点名称可以更具getGroupInfo查询
[group0]: /apps> setNodeName agencyAgroup0nodeCompanyABcosNodeService
Current default node name: agencyAgroup0nodeCompanyABcosNodeService
# 获取当前控制台的默认节点
[group0]: /apps> getNodeName
Current default node name: agencyAgroup0node1BcosNodeService
# 清楚设置的默认节点 如果情况了当前控制台的默认节点 则会随机选择节点进行通讯
[group0]: /apps> clearNodeName
Clear nodeName to empty.

合约操作

命令列表

1
2
3
4
5
6
7
---------------------------合约操作----------------------------
* call 调用合约
* deploy 部署合约
* getCode 查询合约地址的2进制
* getDeployLog 查询当前控制台部署的合约
* listAbi 列出指定合约名部署的所有合约地址
* listDeployContractAddress 列出指定合约名部署的所有合约地址

使用详情

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 部署合约 同一个合约部署两次 会产两个合约地址
[group0]: /apps> deploy HelloWorld
transaction hash: 0x391e8deb93e8926c10dc5f813c6297e791fb39046f697962eb88efeb8cffb399
contract address: 0x810c4b153b2bdb6395d4b33a5968f7b51a607141
currentAccount: 0x3fd0b00b3514ed60df1465d05d754ed5bba7ea2c

# 调用合约方法 调用合约的时候需要指定合约地址 合约v1和合约v2的数据是隔离的
[group0]: /apps> call HelloWorld 0x374f377f00dcf74679cdf70b5a454d4ef8326a62 get
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return value size:1
Return types: (STRING)
Return values:(你好)
---------------------------------------------------------------------------------------------

[group0]: /apps> call HelloWorld 0x810c4b153b2bdb6395d4b33a5968f7b51a607141 get
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return value size:1
Return types: (STRING)
Return values:(Hello, World!)
---------------------------------------------------------------------------------------------

# 查询当前控制台部署的合约
[group0]: /apps> getDeployLog
2023-11-22 22:26:54 [group:group0] HelloWorld 0x374f377f00dcf74679cdf70b5a454d4ef8326a62
2023-11-22 22:45:41 [group:group0] HelloWorld 0x810c4b153b2bdb6395d4b33a5968f7b51a607141
# 列出指定合约名部署的所有合约地址
[group0]: /apps> listDeployContractAddress HelloWorld
0x810c4b153b2bdb6395d4b33a5968f7b51a607141 2023-11-23 11:57:31
0x374f377f00dcf74679cdf70b5a454d4ef8326a62 2023-11-23 11:28:38
# 显示合约接口和Event列表
[group0]: /apps> listAbi HelloWorld
Method list:
name | constant | methodId | signature
--------------------------------------------------------------
set | false | 3590b49f | set(string)
get | true | 299f7f9d | get()

区块链状态查询

命令列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
---------------------------区块链状态查询----------------------------
* getBlockNumber 查询区块链高度
* getSyncStatus 查询同步状态
* getPeers 查询当前连接到客户端节点的peers
* getBlockByHash 通过哈希查询有关块的信息
* getBlockByNumber 通过块号查询有关块的信息
* getBlockHashByNumber 通过块号查询块哈希。
* getBlockHeaderByHash 通过哈希查询有关块头的信息
* getBlockHeaderByNumber 通过块号查询有关块头的信息
* getPendingTxSize 查询待处理事务的大小
* getTotalTransactionCount 查询总事务数
* getTransactionByHash 通过事务哈希查询有关事务的信息
* getTransactionByHashWithProof 通过事务哈希查询事务和事务证明
* getTransactionReceipt 通过事务哈希查询事务收据
* getTransactionReceiptByHashWithProof 通过事务哈希查询收据和事务收据证明
* getSystemConfigByKey 按键查询系统配置值
* setSystemConfigByKey 按键设置系统配置值

使用详情

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 查询区块链高度
[group0]: /apps> getBlockNumber
20
# 查询同步状态
[group0]: /apps> getSyncStatus
SyncStatusInfo{
isSyncing='false',
protocolId='null',
genesisHash='10acf97f98c92d3d7cfa2307089d21fb46a59050a229893906345e41eae893e7',
nodeId='f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069',
blockNumber='20',
latestHash='7a41b1dfc649fb8d9ae4e00e797ed9a9bf2cc9551013582f1b07df798d18e713',
knownHighestNumber='20',
txPoolSize='null',
peers=[

],
knownLatestHash='7a41b1dfc649fb8d9ae4e00e797ed9a9bf2cc9551013582f1b07df798d18e713'
}
# 查询节点的Peers
[group0]: /apps> getPeers
PeersInfo{
p2pNodeID='045344bc886142bc14ebab0970b4ea715a53284c55a8ab302a542071a1122f9c09b345e4c28e91661c888091926ec00eeb442c083025edf2d62865c994ec3ec808',
endPoint='0.0.0.0:30300',
groupNodeIDInfo=[
NodeIDInfo{
group='group0',
nodeIDList=[
63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece,
f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069
]
}
],
peers=[

]
}
# 是否开启权限检查
[group0]: /apps> getSystemConfigByKey auth_check_status
1
# 版本
[group0]: /apps> getSystemConfigByKey compatibility_version
3.5.0
# 每个leader可以连续打包的区块数目,
[group0]: /apps> getSystemConfigByKey consensus_leader_period
5
# 每个区块中可包含的最大交易数目
[group0]: /apps> getSystemConfigByKey tx_count_limit
1000
# 每笔交易运行时消耗的gas上限 根据运行函数的复杂度 耗时等计算出来的值,如果超过就会拒绝执行
[group0]: /apps> getSystemConfigByKey tx_gas_limit
3000000000

共识操作

命令列表

1
2
3
4
5
6
7
8
9
---------------------------共识操作----------------------------
* addObserverProposal 添加一个观察节点(创建提案)
* addSealerProposal 添加一个共识节点(创建提案)
* getConsensusStatus 查询共识状态
* getObserverList 查询观察节点的nodeId列表。
* getPbftView 查询节点的pbft视图
* getSealerList 查询共识节点的nodeId列表
* removeNodeProposal 删除一个节点(创建提案)
* setConsensusNodeWeightProposal 为指定节点设置共识权重(创建提案)

使用详情

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 查询当前群组所有节点
[group0]: /apps> getGroupPeers
peer0: 63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece
peer1: f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069
# 查询观察节点
[group0]: /apps> getObserverList
[
63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece
]
# 查询共识节点
[group0]: /apps> getSealerList
[
Sealer{
nodeID='f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069',
weight=1
}
]
# 移除节点,这里移除的是观察节点,也可以移除共识节点
[group0]: /apps> removeNodeProposal 63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece
Remove node proposal created, ID is: 13
---------------------------------------------------------------------------------------------
Proposer: 0x76b72d379b8f640d061e152784026923e266bcb4
Proposal Type : removeNode
Proposal Status : finished
---------------------------------------------------------------------------------------------
Agree Voters:
0x76b72d379b8f640d061e152784026923e266bcb4
---------------------------------------------------------------------------------------------
Against Voters:
# 加入观察节点
[group0]: /apps> addObserverProposal 63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece
Add observer proposal created, ID is: 14
---------------------------------------------------------------------------------------------
Proposer: 0x76b72d379b8f640d061e152784026923e266bcb4
Proposal Type : setNodeWeight
Proposal Status : finished
---------------------------------------------------------------------------------------------
Agree Voters:
0x76b72d379b8f640d061e152784026923e266bcb4
---------------------------------------------------------------------------------------------
Against Voters:
# 加入共识节点 指定节点和共识权重 加入共识节点之前,需要先加入观察节点是区块高度一致后再加入共识节点, 避免造成共识错误
[group0]: /apps> addSealerProposal 63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece 1
Add consensus sealer proposal created, ID is: 15
---------------------------------------------------------------------------------------------
Proposer: 0x76b72d379b8f640d061e152784026923e266bcb4
Proposal Type : setNodeWeight
Proposal Status : finished
---------------------------------------------------------------------------------------------
Agree Voters:
0x76b72d379b8f640d061e152784026923e266bcb4
---------------------------------------------------------------------------------------------
Against Voters:
# 设置节点权重
[group0]: /apps> setConsensusNodeWeightProposal f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069 2
Set consensus weight proposal created, ID is: 18
---------------------------------------------------------------------------------------------
Proposer: 0x76b72d379b8f640d061e152784026923e266bcb4
Proposal Type : setNodeWeight
Proposal Status : finished
---------------------------------------------------------------------------------------------
Agree Voters:
0x76b72d379b8f640d061e152784026923e266bcb4
---------------------------------------------------------------------------------------------
Against Voters:
# 查看共识节点
[group0]: /apps> getSealerList
[
Sealer{
nodeID='f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069',
weight=2
},
Sealer{
nodeID='63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece',
weight=1
}
]

组信息查询

命令列表

1
2
3
4
5
6
---------------------------组信息查询----------------------------
* getGroupInfo 查询当前组信息。
* getGroupInfoList 获取所有组信息
* getGroupList 列出所有组列表
* getGroupNodeInfo 获取组节点信息
* getGroupPeers 查看节点所在group节点列表。

详情

1
2
3
4
5
6
7
8
9
10
11
12
13
[group0]: /apps> getGroupList
[
group0
]
[group0]: /apps> getGroupInfoList
返回结果为[getGroupInfo1,getGroupInfo2]

[group0]: /apps> getGroupInfo

# 获取当前组的所有节点
[group0]: /apps> getGroupPeers
peer0: 63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece
peer1: f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069
群组详细信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
// 区块链ID
"chainID":"chain0",
// 群组ID
"groupID":"group0",
//创世块信息
"genesisConfig":{
"consensusType":"pbft",
"blockTxCountLimit":1000,
"txGasLimit":3000000000,
"consensusLeaderPeriod":5,
"sealerList":[
{
"nodeID":"f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069",
"weight":1
}
]
},
// 组内节点信息
"nodeList":[
{
"type":1,
"iniConfig":{
"binaryInfo":{
"version":"3.5.0",
"gitCommitHash":"1b0c43920038664a899f0e94e3922204e28be70b",
"platform":"Linux/g++",
"buildTime":"20231017 06:11:20"
},
"chainID":"chain0",
"groupID":"group0",
"smCryptoType":true,
"isSerialExecute":true,
"nodeID":"63261e5abcba2bfbc03624db41e38192298ef605b67640f3d0c745c3d1c01d155bbe94d1ae33c18083fa4d88447a9bc44324174ae57fc3286b97d0fb007eaece",
"nodeName":"agencyAgroup0node1BcosNodeService",
"rpcServiceName":"chain0.agencyABcosRpcService.RpcServiceObj",
"gatewayServiceName":"chain0.agencyABcosGatewayService.GatewayServiceObj",
"authCheck":true,
"isWasm":false,
"isAuthCheck":true
},
"name":"agencyAgroup0node1BcosNodeService",
"serviceInfoList":null,
"protocol":{
"compatibilityVersion":50659328,
"minSupportedVersion":0,
"maxSupportedVersion":2
}
},
{
"type":1,
"iniConfig":{
"binaryInfo":{
"version":"3.5.0",
"gitCommitHash":"773c82d4289698e0adf0321dd5c8ba0f3d4e9aea",
"platform":"Linux/g++",
"buildTime":"20231120 09:26:49"
},
"chainID":"chain0",
"groupID":"group0",
"smCryptoType":true,
"isSerialExecute":true,
"nodeID":"f1684ec3fae49f3b291762b06c9742013d61c7f7a6bbccfb10cc45e5753f49b37ab4adf4b1f979ee9c394bba62e9c4f904f05d860370ce55b0395978731c2069",
"nodeName":"agencyAgroup0nodeCompanyABcosNodeService",
"rpcServiceName":"chain0.agencyABcosRpcService.RpcServiceObj",
"gatewayServiceName":"chain0.agencyABcosGatewayService.GatewayServiceObj",
"authCheck":true,
"isWasm":false,
"isAuthCheck":true
},
"name":"agencyAgroup0nodeCompanyABcosNodeService",
"serviceInfoList":null,
"protocol":{
"compatibilityVersion":50659328,
"minSupportedVersion":0,
"maxSupportedVersion":2
}
}
]
}

权限管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
---------------------------权限管理----------------------------
# 委员会委员 set方法有限制 get没有
* setDeployAuthTypeProposal 设置合约的部署策略
* checkDeployAuth 检查账户是否具有合约部署权限。
* checkMethodAuth 检查是否存在合约方法的调用权限
* closeDeployAuthProposal 关闭账户的部署权限
* openDeployAuthProposal 开启账户的部署权限。
* getDeployAuth 获取合约的部署策略 back_list white_list
# 合约管理员
* getContractAdmin 获取合约的管理员
* setMethodAuth 合约管理员设置合约方法的权限策略
* getMethodAuth 查询合约方法的权限策略
* openMethodAuth 为账户开启合约方法的调用权限
* closeMethodAuth 为账户关闭合约方法的调用权限

* freezeAccount 冻结特定账户。冻结的账户,能登录但是没有调用和部署权限等
* freezeContract 冻结特定合约。冻结的合约,方法不会被调用。
* unfreezeAccount 解冻特定账户。
* unfreezeContract 解冻特定合约。

* getCommitteeInfo 获取委员会信息。
* getContractStatus 获取合约状态。
* getLatestProposal 获取最新提案信息。
* getProposalInfo 委员范围获取填信息

* removeNodeProposal 删除共识节点。
* resetAdminProposal 重置特定合约的管理员。
* revokeProposal 撤销委员会的特定提案。
* setConsensusNodeWeightProposal 设置共识节点的权重。
* setRateProposal 更新委员会投票率。
* setSysConfigProposal 设置系统配置。
* updateGovernorProposal 更新一个管理者。
* upgradeVoteProposal 升级委员会投票计算逻辑。
* voteProposal 投票支持或反对委员会中的特定提案1通过 0反对
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 查看当前账户的部署权限
[group0]: /apps> checkDeployAuth
Deploy : ACCESS
Account: 0x76b72d379b8f640d061e152784026923e266bcb4

# 检查当前账户是否有方法调用权限 查询方法不受控制
[group0]: /apps> checkMethodAuth 0x374f377f00dcf74679cdf70b5a454d4ef8326a62 set
Method : PERMISSION DENIED
Account : 0x76b72d379b8f640d061e152784026923e266bcb4
Interface: set
Contract : 0x374f377f00dcf74679cdf70b5a454d4ef8326a62

[group0]: /apps> checkMethodAuth 0x374f377f00dcf74679cdf70b5a454d4ef8326a62 get
Method : PERMISSION DENIED
Account : 0x76b72d379b8f640d061e152784026923e266bcb4
Interface: get
Contract : 0x374f377f00dcf74679cdf70b5a454d4ef8326a62

# 关闭账户对合约的部署权限
[group0]: /apps> closeDeployAuthProposal 0x76b72d379b8f640d061e152784026923e266bcb4
Close deploy auth proposal created, ID is: 20
---------------------------------------------------------------------------------------------
Proposer: 0x76b72d379b8f640d061e152784026923e266bcb4
Proposal Type : modifyDeployAuth
Proposal Status : finished
---------------------------------------------------------------------------------------------
Agree Voters:
0x76b72d379b8f640d061e152784026923e266bcb4
---------------------------------------------------------------------------------------------
Against Voters:

# 开启账户对合约的部署权限
[group0]: /apps> openDeployAuthProposal 0x76b72d379b8f640d061e152784026923e266bcb4
Open deploy auth proposal created, ID is: 21
---------------------------------------------------------------------------------------------
Proposer: 0x76b72d379b8f640d061e152784026923e266bcb4
Proposal Type : modifyDeployAuth
Proposal Status : finished
---------------------------------------------------------------------------------------------
Agree Voters:
0x76b72d379b8f640d061e152784026923e266bcb4
---------------------------------------------------------------------------------------------
Against Voters:


# 设置合约方法的权限 需要保当前账户是合约的管理员 就算是委员会委员也不行
[group0]: /apps> setMethodAuth 0x374f377f00dcf74679cdf70b5a454d4ef8326a62 set(string) white_list
{
"code":0,
"msg":"Success"
}

# 查询合约方法的权限策略
[group0]: /apps> getMethodAuth 0x374f377f00dcf74679cdf70b5a454d4ef8326a62 set(string)
---------------------------------------------------------------------------------------------
Contract address: 0x374f377f00dcf74679cdf70b5a454d4ef8326a62
Contract method : set(string)
Method auth type: WHITE_LIST
---------------------------------------------------------------------------------------------
Access address:
---------------------------------------------------------------------------------------------
Block address :

账户操作

1
2
3
4
5
---------------------------账户操作----------------------------
* getCurrentAccount 获取当前账户信息
* listAccount 列出当前保存的账户列表
* loadAccount 为交易签名加载账户
* newAccount 创建账户

BFS 操作

命令列表

1
2
3
4
5
6
7
8
---------------------------BFS操作----------------------------
* cd 更改到给定路径的目录。
* fixBFS 修复指定版本的bfs错误。
* ln 创建用于访问合约的链接。
* ls 列出给定路径中的资源。
* mkdir 在给定路径中创建目录。
* pwd 显示工作目录名称的绝对路径
* tree 以树状格式列出目录的内容。

CRUD 合约操作

命令列表

1
2
3
4
5
6
7
8
---------------------------CRUD合约操作----------------------------
* alter 按sql更改表列
* create 按sql创建表
* delete 按sql删除记录
* desc 描述表信息
* insert 按sql插入记录
* select 按sql选择记录
* update 按sql更新记录

分片操作

1
2
3
4
---------------------------分片操作----------------------------
* getContractShard 获取合约所属的分片。
* linkShard 将合约添加到分片。
* makeShard 创建一个分片。

官方文档

控制台命令列表 ‒ FISCO BCOS 3.0 v3.3.0 文档

  • 标题: 区块链Fisco Bcos console控制台的使用
  • 作者: 兰涛
  • 创建于 : 2023-11-24 17:42:27
  • 更新于 : 2024-01-26 09:53:34
  • 链接: https://lands.work/788e9d87/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论