FISCO BCOS 控制台 部署合约 调用 查看已部署合约的地址

deploy

部署合约。(默认提供HelloWorld合约和TableTest.sol进行示例使用) 参数:

  • 合约路径:合约文件的路径,支持相对路径、绝对路径和默认路径三种方式。用户输入为文件名时,从默认目录获取文件,默认目录为: contracts/solidity,比如:HelloWorld。
# 部署HelloWorld合约,默认路径
[group:1]> deploy HelloWorld
contract address:0xc0ce097a5757e2b6e189aa70c7d55770ace47767

# 部署HelloWorld合约,相对路径
[group:1]> deploy contracts/solidity/HelloWorld.sol
contract address:0xd653139b9abffc3fe07573e7bacdfd35210b5576

# 部署HelloWorld合约,绝对路径
[group:1]> deploy ~/fisco/console/contracts/solidity/HelloWorld.sol
contract address:0x85517d3070309a89357c829e4b9e2d23ee01d881

 

注:

  • 部署用户编写的合约,可以将solidity合约文件放到控制台根目录的contracts/solidity/目录下,然后进行部署即可。按tab键可以搜索contracts/solidity/目录下的合约名称。
  • 若需要部署的合约引用了其他合约或library库,引用格式为import "./XXX.sol";。其相关引入的合约和library库均放在contracts/solidity/目录。
  • 如果合约引用了library库,library库文件的名称必须以Lib字符串开始,以便于区分是普通合约与library库文件。library库文件不能单独部署和调用。

listAbi

显示合约接口和Event列表 参数:

  • 合约路径:合约文件的路径,支持相对路径、绝对路径和默认路径三种方式。用户输入为文件名时,从默认目录获取文件,默认目录为: contracts/solidity,比如:TableTest。
  • 合约名:(可选)合约名称,默认情况下使用合约文件名作为合约名参数
[group:1]> listAbi TableTest
Method list:
 name                |    constant  |    methodId    |    signature
  --------------------------------------------------------------
 remove              |    false     |    0x0fe1160f  |    remove(string,int256)
 update              |    false     |    0x49cc36b5  |    update(string,int256,string)
 select              |    true      |    0x5b325d78  |    select(string)
 insert              |    false     |    0xe020d464  |    insert(string,int256,string)

Event list:
 name                |   topic                                                                   signature
  --------------------------------------------------------------
 remove              |   0x0fe1160f9655e87c29e76aca1cab34fb2a644d375da7a900c7076bad17cad26b  |   remove(string,int256)
 update              |   0x49cc36b56a9320d20b2d9a1938a972c849191bceb97500bfd38fa8a590dac73a  |   update(string,int256,string)
 select              |   0x5b325d7821528d3b52d0cc7a83e1ecef0438f763796770201020ac8b8813ac0a  |   select(string)
 insert              |   0xe020d464e502c11b54a7e37e568c78f0fcd360213eb5f4ac0a25a17733fc19f7  |   insert(string,int256,string)

 

getDeployLog

运行getDeployLog,查询群组内由当前控制台部署合约的日志信息。日志信息包括部署合约的时间,群组ID,合约名称和合约地址。参数:

  • 日志行数,可选,根据输入的期望值返回最新的日志信息,当实际条数少于期望值时,按照实际数量返回。当期望值未给出时,默认按照20条返回最新的日志信息。
[group:1]> getDeployLog 2

2019-05-26 08:37:03  [group:1]  HelloWorld            0xc0ce097a5757e2b6e189aa70c7d55770ace47767
2019-05-26 08:37:45  [group:1]  TableTest             0xd653139b9abffc3fe07573e7bacdfd35210b5576

[group:1]> getDeployLog 1

2019-05-26 08:37:45  [group:1]  TableTest             0xd653139b9abffc3fe07573e7bacdfd35210b5576

 

注: 如果要查看所有的部署合约日志信息,请查看console目录下的deploylog.txt文件。该文件只存储最近10000条部署合约的日志记录。

call

运行call,调用合约。 参数:

  • 合约路径:合约文件的路径,支持相对路径、绝对路径和默认路径三种方式。用户输入为文件名时,从默认目录获取文件,默认目录为: contracts/solidity。意思是,要调用的合约必须已经存在于contracts/solidity中,若不在,拷贝一份对应的合约文件过来。
  • 合约地址: 部署合约获取的地址。
  • 合约接口名:调用的合约接口名。
  • 参数:由合约接口参数决定。参数由空格分隔;数组参数需要加上中括号,比如[1,2,3],数组中是字符串或字节类型,加双引号,例如[“alice”,”bob”],注意数组参数中不要有空格;布尔类型为true或者false。
# 调用HelloWorld的get接口获取name字符串
[group:1]> call HelloWorld 0x175b16a1299c7af3e2e49b97e68a44734257a35e get
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return values:
[
    "Hello,World!"
]
---------------------------------------------------------------------------------------------

# 调用HelloWorld的set接口设置name字符串
[group:1]> call HelloWorld 0x175b16a1299c7af3e2e49b97e68a44734257a35e set "Hello, FISCO BCOS"
transaction hash: 0x54b7bc73e3b57f684a6b49d2fad41bd8decac55ce021d24a1f298269e56f1ce1
---------------------------------------------------------------------------------------------
transaction status: 0x0
description: transaction executed successfully
---------------------------------------------------------------------------------------------
Output
Receipt message: Success
Return message: Success
---------------------------------------------------------------------------------------------
Event logs
Event: {}

# 调用HelloWorld的get接口获取name字符串,检查设置是否生效
[group:1]> call HelloWorld 0x175b16a1299c7af3e2e49b97e68a44734257a35e get
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return values:
[
    "Hello,FISCO BCOS"
]
---------------------------------------------------------------------------------------------


# 调用TableTest的insert接口插入记录,字段为name, item_id, item_name
[group:1]> call TableTest 0x5f248ad7e917cddc5a4d408cf18169d19c0990e5 insert "fruit" 1 "apple"
transaction hash: 0x64bfab495dc1f50c58d219b331df5a47577aa8afc16be926260238a9b0ec0fbb
---------------------------------------------------------------------------------------------
transaction status: 0x0
description: transaction executed successfully
---------------------------------------------------------------------------------------------
Output
Receipt message: Success
Return message: Success
---------------------------------------------------------------------------------------------
Event logs
Event: {"InsertResult":[1]}

# 调用TableTest的select接口查询记录
[group:1]> [group:1]> call TableTest 0x5f248ad7e917cddc5a4d408cf18169d19c0990e5 select "fruit"
---------------------------------------------------------------------------------------------
Return code: 0
description: transaction executed successfully
Return message: Success
---------------------------------------------------------------------------------------------
Return values:
[
    [
        "fruit"
    ],
    [
        1
    ],
    [
        "apple"
    ]
]
---------------------------------------------------------------------------------------------

 

posted @ 2022-09-26 19:50  牧之丨  阅读(382)  评论(0编辑  收藏  举报