-
Notifications
You must be signed in to change notification settings - Fork 13
BaerChain Contract deployment process
weidong edited this page Apr 9, 2020
·
7 revisions
- 1.1 ERC20 token contract preparation
- 1.2 Get contract binaries and ABI interface
- 1.3 Deployment contract
1. ERC20 contract deployment Back Dir
- 1.1 ERC20 contract preparation
- Remarks: This contract is mainly used for reference guidance, the actual issuance of ERC20 token contract, please refer to the actual data
1). Please refer to the security library contractSafeMath.sol
2). Please refer to ERC20 contractERC20.sol
3). Please refer to the test for issuing token contractsTestToken.sol
- 1.2 Get contract binaries and ABI interface Back Dir
- Due to the visibility and debuggability of the online editor, the method is introduced here
- Available in online editorremix, Compile the binary code of ABI interface and contract
- Note: When compiling TestToken, you need to pass in when deploying the contract. Your token name, symbol, precision, and the number of issued tokens. For details, please see the functions and descriptions of the above contracts ERC20.sol and TestToken.sol , The input of this test currency is:
_name : TestERC20Token _symbol : TET _decimals : 8 _titalSupply : 20000
- 1.3 Deployment contract Back Dir
- Deployment contract TestToken.sol, The json file isdeContract.json
- The "contract": "" field of the contract binary file obtained above, as shown in the deContract.json file
- deContract.json parameter description
from : [40 bytes] The address of the contract deployer when the contract is deployed, and the address of the caller when the contract is executed to : [40 bytes] Fill in 0 or empty when deploying the contract, and the contract address when executing the contract value : Value, default is 0 data : Array structure > type : A value of 5 means deploying a contract, a value of 6 means calling a contract > contract : The hash value of the method signature and encoding parameters, that is, the content of the input when deploying the contract and executing the contract chainId : Chain ID, which must be the same as the creation chainId nonce : Required after each deployment and execution of the contract +1 gas : Integer gas for transaction execution gasPrice : The gasPrice integer used for each gas payment keys : The private key of the transaction signature, that is, the private key of the contractor when deploying the contract, and the private key of the contractor when calling the contract - Execute in the compilation directory, obtain the "cmdWallet" execution file
cd cpp-lsac/build : Enter the directory cmake .. : Execute instruction make : Execute instruction cd cpp-lsac/build/wallet/cmdWallet : You can find the cmdWallet executable file just compiled in this directory- Execute instructions, deploy contracts Back Dir
./cmdWallet -j deContract.json -s 127.0.0.1:8081- Return result
{ "id": 1, "jsonrpc": "2.0", "result": "0x4b1ea38a5ec21fde14cbf61fd92a7febf50589a8acdf6b455ecae75166962d66" }- According to the returned hash, query the contract address
curl -X POST --data '{"jsonrpc":"2.0","method":"brc_getTransactionReceipt","params":["0x4b1ea38a5ec21fde14cbf61fd92a7febf50589a8acdf6b455ecae75166962d66"],"id":1}' http://127.0.0.1:8081- Return result Back Dir
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0xe74f729f1b70243bc5c690d80bd79804f6c4ff7f6a48180ba68e391f3822c1ee",
"blockNumber": 5211561,
"contractAddress": "0x709fb7a8e70b09bff61f7b0688f33de718ef6a10",
"cumulativeGasUsed": "0x190eba",
"from": "0x84db59804e311bdb6806cce6f82c4038b60456a1",
"gasUsed": "0x190eba",
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": "1",
"to": "0x0000000000000000000000000000000000000000",
"transactionHash": "0x4b1ea38a5ec21fde14cbf61fd92a7febf50589a8acdf6b455ecae75166962d66",
"transactionIndex": 0
}
}
- "contractAddress": "0x709fb7a8e70b09bff61f7b0688f33de718ef6a10",可得到合约地址。
2. Execute contract Back Dir
- The contract execution json file isexContract.json
- Put the contract address obtained above into the to field of the exContract.json file
- exContract.json: parameter description
from : [40 bytes] The address of the contract deployer when the contract is deployed, and the address of the caller when the contract is executed to : [40 bytes] Fill in 0 or empty when deploying the contract, and the contract address when executing the contract value : Value, default is 0 data : Array structure > type : A value of 5 means deploying a contract, a value of 6 means calling a contract > contract : The hash value of the method signature and encoding parameters, that is, the content of the input when deploying the contract and executing the contract chainId : Chain ID, which must be the same as the creation chainId nonce : +1 after each deployment and execution of the contract gas : Integer gas for transaction execution gasPrice : The gasPrice integer used for each gas payment
- Execute in the compilation directory, get cmdWallet execution file
cd cpp-lsac/build : Enter the directory
cmake .. : Execute instruction
make : Execute instruction
cd cpp-lsac/build/wallet/cmdWallet : You can find the cmdWallet executable file just compiled in this directory
- Execute contract
- This test transfer function (the minimum unit of transfer is 1000 to the address 0xe523e7c59a0725afd08bc9751c89eed6f8e16dec)
./cmdWallet -j exContract.json -s 127.0.0.1:8081
- Return result
{
"id": 1,
"jsonrpc": "2.0",
"result": "0xdf4307f0fc67ba8f04c6c0153a4610c2c636e1f472359e8931a6994043a4306c"
}
- According to the returned hash, query the contract address Back Dir
curl -X POST --data '{"jsonrpc":"2.0","method":"brc_getTransactionReceipt","params":["0xdf4307f0fc67ba8f04c6c0153a4610c2c636e1f472359e8931a6994043a4306c"],"id":1}' http://127.0.0.1:8081
- Return result
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"blockHash": "0x9b9a0387e912bf1b56250473be2c22544f872f7b722d7a92daae599214d1c79a",
"blockNumber": 5211838,
"contractAddress": "0xf74444fd4868b6334ec5341cdc4ed8a1a247e6e3",
"cumulativeGasUsed": "0xc8af",
"from": "0x84db59804e311bdb6806cce6f82c4038b60456a1",
"gasUsed": "0xc8af",
"logs": [
{
"address": "0x709fb7a8e70b09bff61f7b0688f33de718ef6a10",
"blockHash": "0x9b9a0387e912bf1b56250473be2c22544f872f7b722d7a92daae599214d1c79a",
"blockNumber": 5211838,
"data": "0x00000000000000000000000000000000000000000000000000000000000003e8",
"logIndex": 0,
"polarity": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000e79fead329b69540142fabd881099c04424cc49f",
"0x000000000000000000000000e523e7c59a0725afd08bc9751c89eed6f8e16dec"
],
"transactionHash": "0xdf4307f0fc67ba8f04c6c0153a4610c2c636e1f472359e8931a6994043a4306c",
"transactionIndex": 0,
"type": "mined"
}
],
"logsBloom": "0x00000000000000000000000001800000000000000000000000000000000000000200000200000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000008200000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000102000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": "1",
"to": "0x709fb7a8e70b09bff61f7b0688f33de718ef6a10",
"transactionHash": "0xdf4307f0fc67ba8f04c6c0153a4610c2c636e1f472359e8931a6994043a4306c",
"transactionIndex": 0
}
}
From the returned results, you can see the logs of the successful transfer
brc_call : Contract related data query Back Dir
- request
{
"jsonrpc": "2.0",
"method": "brc_call",
"params": [
{
"from": "e79fead329b69540142fabd881099c04424cc49f",
"to": "0x6bb313a31fb23dd97d73d02217af51a515db2f41",
"data": "0x18160ddd",
"chainid":"0x1"
},
"latest"
],
"id": 1
}
- Instruction example
curl -d '{"jsonrpc":"2.0","method":"brc_call","params":[{"from":"0xe79fead329b69540142fabd881099c04424cc49f","to":"0x6bb313a31fb23dd97d73d02217af51a515db2f41","data":"0x18160ddd", "chainid":"0x1"}, "latest"],"id":1}' http://127.0.0.1:8111
- Instruction example
method : Method name
params : Parameter list, 32 bytes, block hash
> from : Call contract address
> to : Contract address
> data : To query the signature of the corresponding function function of the contract
> chainid : The chainId of the chain, for example: the test net value is: 0x1, the main net value is: 0xb
- Return result
{
"id": 1,
"jsonrpc": "2.0",
"result": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000974657374546f6b656e0000000000000000000000000000000000000000000000"
}
- Parameter Description
result : Contract query returns