前提条件
操作步骤
编译部署合约
1. 选择左侧导航栏中的BCOS > 区块链网络,进入“区块链网络”页面。
2. 选择合约管理页签,进入合约管理界面,并单击新增合约。
3. 在弹出的“新增合约”窗口中,单击选择文件并上传 StorageCell.sol 合约。
4. 在合约管理页签中,单击待编译合约所在行右侧的编译。
5. 编译完成后,单击合约名称进入合约详情页,并查看合约详情。如下图所示:


合约调用
本示例使用 DeployDynamicBcosContract 执行存证操作,再通过 InvokeBcosTrans 获取存证内容。
示例内包含以下内容:
存证内容:
0xf9c7517d72197ce6240823cd40b46ad48613cbcf
说明信息:
testinfo
调用 DeployDynamicBcosContract 存证
https://tbaas.tencentcloudapi.com/?Action=DeployDynamicBcosContract&ClusterId=bcos-i60x97wxm8&GroupId=1&AbiInfo=[{"constant":true,"inputs":[],"name":"getVersion","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getStorageCell","outputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"n","type":"string"}],"name":"setVersion","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"storageHash","type":"string"},{"name":"storageInfo","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]&ByteCodeBin=608060405234801561001057600080fd5b5060405161064b38038061064b83398101806040528101908080518201929190602001805182019291905050508160009080519060200190610053929190610072565b50806001908051906020019061006a929190610072565b505050610117565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100b357805160ff19168380011785556100e1565b828001600101855582156100e1579182015b828111156100e05782518255916020019190600101906100c5565b5b5090506100ee91906100f2565b5090565b61011491905b808211156101105760008160009055506001016100f8565b5090565b90565b610525806101266000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630d8e6e2c1461005c57806337a6beee146100ec578063788bc78c146101e8575b600080fd5b34801561006857600080fd5b50610071610251565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b1578082015181840152602081019050610096565b50505050905090810190601f1680156100de5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100f857600080fd5b506101016102f3565b604051808060200180602001838103835285818151815260200191508051906020019080838360005b8381101561014557808201518184015260208101905061012a565b50505050905090810190601f1680156101725780820380516001836020036101000a031916815260200191505b50838103825284818151815260200191508051906020019080838360005b838110156101ab578082015181840152602081019050610190565b50505050905090810190601f1680156101d85780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b3480156101f457600080fd5b5061024f600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061043a565b005b606060028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102e95780601f106102be576101008083540402835291602001916102e9565b820191906000526020600020905b8154815290600101906020018083116102cc57829003601f168201915b5050505050905090565b60608060006001818054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561038f5780601f106103645761010080835404028352916020019161038f565b820191906000526020600020905b81548152906001019060200180831161037257829003601f168201915b50505050509150808054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561042b5780601f106104005761010080835404028352916020019161042b565b820191906000526020600020905b81548152906001019060200180831161040e57829003601f168201915b50505050509050915091509091565b8060029080519060200190610450929190610454565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061049557805160ff19168380011785556104c3565b828001600101855582156104c3579182015b828111156104c25782518255916020019190600101906104a7565b5b5090506104d091906104d4565b5090565b6104f691905b808211156104f25760008160009055506001016104da565b5090565b905600a165627a7a7230582038893ddc60a60ddf3f4e33ba1daa3f5a2f05c0d16a837ae0b2facf7270957ebc0029&ConstructorParams=["0xf9c7517d72197ce6240823cd40b46ad48613cbcf","testinfo"]&SignUserId=526SSS1SSS908b010288c348e494ab21c9ccbb14f7&<公共请求参数>
返回示例
{"Response": {"RequestId": "8b86cec2-8d80-46cb-b068-16edf449f4dc","ContractAddress": "0xe4379d33af1c5b174705ed54c22677bd15ceb213"}}
说明
您需要记录返回的 ContractAddress 信息,以便调用 InvokeBcosTrans 获取存证信息时入参。
调用 InvokeBcosTrans 获取存证信息
https://tbaas.tencentcloudapi.com/?Action=DeployDynamicBcosContract&ClusterId=bcos-i60x97wxm8&GroupId=1&ContractAddress=0xe4379d33af1c5b174705ed54c22677bd15ceb213&AbiInfo=[{"constant":true,"inputs":[],"name":"getVersion","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getStorageCell","outputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"n","type":"string"}],"name":"setVersion","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"storageHash","type":"string"},{"name":"storageInfo","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]&FuncName=getStorageCell&SignUserId=526SSS1SSS908b010288c348e494ab21c9ccbb14f7&<公共请求参数>
返回示例
{"Response": {"RequestId": "71ff680a-c113-4b65-9b8f-b62afc8b02c8","TransactionRsp": "{\\"blockHash\\":null,\\"blockNumber\\":null,\\"constant\\":true,\\"from\\":null,\\"gasUsed\\":null,\\"input\\":null,\\"output\\":null,\\"queryInfo\\":\\"[ \\\\\\"0xf9c7517d72197ce6240823cd40b46ad48613cbcf\\\\\\", \\\\\\"testinfo\\\\\\" ]\\",\\"status\\":null,\\"to\\":null,\\"transactionHash\\":null}"}}
相关内容
StorageCell.sol 合约
StorageCell.sol 合约原文如下所示:
pragma solidity ^0.4.4;contract StorageCell{string _storageHash;string _storageInfo;string version;constructor (string storageHash, string storageInfo) public {_storageHash = storageHash;_storageInfo = storageInfo;}function getStorageCell() public constant returns(string, string){return(_storageHash,_storageInfo);}function getVersion()constant returns(string){return version;}function setVersion(string n){version = n;}}