Contract related APIs
This chapter introduces how to contract deployment, contract execution on Transformers chain. Contract execution includes balance inquiry, token/NFT transfer, ect.
Prerequisites
- Prepare an account, which includes the account private key, public key, and address.
- Ensure that there is a certain amount of TTOS in the account to be used for gas fees for deploying/executing contracts.
- Need to have a certain foundation in contract development, Familiar with Solidity language and compilation process,Understand the deployment and execute contract process of other mainstream blockchain websites.
- Familiar with the transaction process of Transformers network.
Deploy Contract
GetDeployContractTransaction
- Send deploy Contract request through
/GetDeployContractTransaction
interface.
The parameter format is as follows:
{
"id": "",
"jsonrpc": "",
"params": {
"addr": "cED97dA085527Fe7e1772CA59Aa1e64A78143128",
"contract": "608060405234801561001057600080fd5b506108b3806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630483a7f61461005c5780631629614e1461008c57806327e235e3146100a85780637ad9ad7c146100d8578063afc58189146100f4575b600080fd5b610076600480360381019061007191906105a8565b610110565b60405161008391906106d7565b60405180910390f35b6100a660048036038101906100a19190610615565b610128565b005b6100c260048036038101906100bd91906105a8565b6102a7565b6040516100cf91906106d7565b60405180910390f35b6100f260048036038101906100ed91906105d5565b6102bf565b005b61010e60048036038101906101099190610615565b61037d565b005b60016020528060005260406000206000915090505481565b80806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156101aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a1906106b7565b60405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546101f89190610759565b9250508190555081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461024e9190610703565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f3a14c6aa3e15c61c97825b026647b989a91e18aa33b689769475a298922480428360405161029b91906106d7565b60405180910390a25050565b60006020528060005260406000206000915090505481565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461030d9190610703565b925050819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f322d0c4befd4c2dd440740b711488a1638fd7d8eeb25f9dacede84083db428c98360405161037191906106d7565b60405180910390a35050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610400576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f790610697565b60405180910390fd5b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610482576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047990610697565b60405180910390fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104d09190610703565b9250508190555080600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105269190610759565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f867b353f032680758428983522443995b88120a470e436b962c6a9d0d8940af78260405161057391906106d7565b60405180910390a250565b60008135905061058d8161084f565b92915050565b6000813590506105a281610866565b92915050565b6000602082840312156105be576105bd6107f8565b5b60006105cc8482850161057e565b91505092915050565b600080604083850312156105ec576105eb6107f8565b5b60006105fa8582860161057e565b925050602061060b85828601610593565b9150509250929050565b60006020828403121561062b5761062a6107f8565b5b600061063984828501610593565b91505092915050565b600061064f6011836106f2565b915061065a826107fd565b602082019050919050565b60006106726014836106f2565b915061067d82610826565b602082019050919050565b610691816107bf565b82525050565b600060208201905081810360008301526106b081610642565b9050919050565b600060208201905081810360008301526106d081610665565b9050919050565b60006020820190506106ec6000830184610688565b92915050565b600082825260208201905092915050565b600061070e826107bf565b9150610719836107bf565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561074e5761074d6107c9565b5b828201905092915050565b6000610764826107bf565b915061076f836107bf565b925082821015610782576107816107c9565b5b828203905092915050565b60006107988261079f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b7f4e6f206c6f636b65642062616c616e6365000000000000000000000000000000600082015250565b7f496e73756666696369656e742062616c616e6365000000000000000000000000600082015250565b6108588161078d565b811461086357600080fd5b50565b61086f816107bf565b811461087a57600080fd5b5056fea264697066735822122067e67aed3152cf78a07c4f8842540cf5803e421699b10fbf8f66c015550b0ed464736f6c63430008070033",
"data": "",
"info": "[]",
"isFindUtxo": false,
"nContractType": "0",
"pubstr": "MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=",
"txInfo": "info"
}
}
Parameter name | remark |
---|---|
contract | The compiled binary code of the contract source code |
data | Compiled binary code for constructing parameters |
{
"id": "",
"jsonrpc": "",
"method": "",
"result": {
"code": 0,
"contractJs": "{\"version\":\"1_1.0.0_d\",\"txMsgReq\":{\"version\":\"1_1.0.0_d\",\"txMsgInfo\":{\"nodeHeight\":\"601\",\"contractStorageList\":[\"A8B8Ae6F84709fF80E08aD9d26575c161aCC95f1\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"dea1b44a641928d6a09db9a3d9da274abe4ef13eb23833213144a5b46c612136\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEASFAPKN8n+Nqn2RcJX8XCgyx1sveBLZ/f5tn5JpM2Xxs=\"}}}}",
"message": "",
"txJson": "{\"time\":\"1717148103333839\",\"identity\":\"2eb2F635320c3Dbf29eadD35E894c13EE3F20bd5\",\"utxo\":{\"owner\":[\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"],\"vin\":[{\"prevOut\":[{\"hash\":\"dea1b44a641928d6a09db9a3d9da274abe4ef13eb23833213144a5b46c612136\"}]}],\"vout\":[{\"value\":\"480\",\"addr\":\"VirtualDeployContractBurnGas\"},{\"value\":\"1982446498797\",\"addr\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"},{\"value\":\"493200\",\"addr\":\"VirtualBurnGas\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":7,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4406,\\\"blockTimestamp\\\":1717148110,\\\"input\\\":\\\"608060405234801561001057600080fd5b506108b3806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630483a7f61461005c5780631629614e1461008c57806327e235e3146100a85780637ad9ad7c146100d8578063afc58189146100f4575b600080fd5b610076600480360381019061007191906105a8565b610110565b60405161008391906106d7565b60405180910390f35b6100a660048036038101906100a19190610615565b610128565b005b6100c260048036038101906100bd91906105a8565b6102a7565b6040516100cf91906106d7565b60405180910390f35b6100f260048036038101906100ed91906105d5565b6102bf565b005b61010e60048036038101906101099190610615565b61037d565b005b60016020528060005260406000206000915090505481565b80806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156101aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a1906106b7565b60405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546101f89190610759565b9250508190555081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461024e9190610703565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f3a14c6aa3e15c61c97825b026647b989a91e18aa33b689769475a298922480428360405161029b91906106d7565b60405180910390a25050565b60006020528060005260406000206000915090505481565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461030d9190610703565b925050819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f322d0c4befd4c2dd440740b711488a1638fd7d8eeb25f9dacede84083db428c98360405161037191906106d7565b60405180910390a35050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610400576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f790610697565b60405180910390fd5b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610482576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047990610697565b60405180910390fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104d09190610703565b9250508190555080600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105269190610759565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f867b353f032680758428983522443995b88120a470e436b962c6a9d0d8940af78260405161057391906106d7565b60405180910390a250565b60008135905061058d8161084f565b92915050565b6000813590506105a281610866565b92915050565b6000602082840312156105be576105bd6107f8565b5b60006105cc8482850161057e565b91505092915050565b600080604083850312156105ec576105eb6107f8565b5b60006105fa8582860161057e565b925050602061060b85828601610593565b9150509250929050565b60006020828403121561062b5761062a6107f8565b5b600061063984828501610593565b91505092915050565b600061064f6011836106f2565b915061065a826107fd565b602082019050919050565b60006106726014836106f2565b915061067d82610826565b602082019050919050565b610691816107bf565b82525050565b600060208201905081810360008301526106b081610642565b9050919050565b600060208201905081810360008301526106d081610665565b9050919050565b60006020820190506106ec6000830184610688565b92915050565b600082825260208201905092915050565b600061070e826107bf565b9150610719836107bf565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561074e5761074d6107c9565b5b828201905092915050565b6000610764826107bf565b915061076f836107bf565b925082821015610782576107816107c9565b5b828203905092915050565b60006107988261079f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b7f4e6f206c6f636b65642062616c616e6365000000000000000000000000000000600082015250565b7f496e73756666696369656e742062616c616e6365000000000000000000000000600082015250565b6108588161078d565b811461086357600080fd5b50565b61086f816107bf565b811461087a57600080fd5b5056fea264697066735822122067e67aed3152cf78a07c4f8842540cf5803e421699b10fbf8f66c015550b0ed464736f6c63430008070033\\\",\\\"recipient\\\":\\\"A8B8Ae6F84709fF80E08aD9d26575c161aCC95f1\\\",\\\"sender\\\":\\\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\\\",\\\"version\\\":0,\\\"virtualMachine\\\":0}}\"}"
}
}
sig_tx()
- Sign the returned information content using the SDK's
sig_tx
method.
Provide code snippets integrate C/C++code into Java programs through JNI.
JNIEXPORT jstring JNICALL Java_src_sig_sig_signContractMessageTx(JNIEnv *env, jobject, jlong pkey,
jstring tx) {
std::string tx_t = jstring2string(env, tx);
char *buf = sig_contract_tx(pkey, tx_t.c_str(), tx_t.size());
std::string result(buf);
free(buf);
return env->NewStringUTF(result.c_str());
}
SendContractMessage
- The signed content is sent to the entire network for broadcasting through the
SendContractMessage
interface.
Sample Response:
{
"id": "1",
"jsonrpc": "2.0",
"method": "SendContractMessage",
"result": {
"code": 0,
"message": "success",
"txHash": "0xf166e4fbb26d72597f603756e0548a3d0a4d3cc34b34ea9678622e6f64953cf9"
}
}
Execute contract
Executing a contract allows for many operations on a smart contract, including querying name/symbol/total supply, querying balance, querying decimal places, performing token/NFT transfers, minting, approve etc. The specific calling method needs to be matched according to the content of your smart contract.
- Querying contract information does not need uplink operations, and the istochain field is set to "false",Parse the return body to obtain the corresponding data.
- Transfer/Mint transactions need uplink operations,and the istochain field is set to "true", And the trading body needs to sign and broadcast through the
SendContractMessage
interface for sending. - When it comes to uplink operations, TTOS needs to be consumed.
GetCallContractTransaction
Parameter format:
{
"id": "1",
"jsonrpc": "2.0",
"params": {
"addr": "0xcED97dA085527Fe7e1772CA59Aa1e64A78143128",
"args": "0xa9059cbb00000000000000000000000012460d65f8df3b75e5279fb930a6b7cdfc4b38d4000000000000000000000000000000000000000000000000000000000bebc200",
"contractAddress": "0x7350399179EC2B0702008aE8b43a0579AA699Eb1",
"deployer": "cED97dA085527Fe7e1772CA59Aa1e64A78143128",
"deployutxo": "0x8a02413da127b48318a7ed12a46a4f68b83cdc6c21f937d7e6c99393d64112b0",
"isFindUtxo": false,
"istochain": "true",
"money": "0",
"pubstr": "MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=",
"tip": "0",
"txInfo": "info"
}
}
Parameter name | remark |
---|---|
deployer | TTOS address with deployer |
deployutxo | the utxo deployed through deploy_utxo_req interface acquisition,A deployer may deploy multiple contracts |
args | Built ABI function object, encoded value content |
pubstr | Executor's public key,No transfer of tokens/NFTs involved, value is "" |
tip | Tips for deployers |
money | Reward contract address |
istochain | true or false,No transfer of tokens/NFTs involved, value is false |
Return format:
{
"id": "1",
"jsonrpc": "2.0",
"method": "GetCallContractTransaction",
"result": {
"code": 0,
"contractJs": "{\"version\":\"1_1.1.1_t\",\"txMsgReq\":{\"version\":\"1_1.1.1_t\",\"txMsgInfo\":{\"nodeHeight\":\"1218\",\"contractStorageList\":[\"4273252d184B8d3E57fD07f255c947d35F0D0a56\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"b2048d103af6a0974877d74d7f0e9c5497ba9cba82a1b02d56f87d7878a4f50c\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEAnLqD9/PigVRvGYX+QlAlTfVRl9Pe8FVJMAB7iiSfGg0=\"}}}}",
"message": "success",
"txJson": "{\"time\":\"1719996570790958\",\"identity\":\"Ee24c3812e8D6253e808448e44E76CD0027AF610\",\"utxo\":{\"owner\":[\"FFFc74b51BC5e75527fE5970D04355958dd3657C\"],\"vin\":[{\"prevOut\":[{\"hash\":\"e145cfb7325cce407a266f5ee06a4d5b97f4a1c393ce36171713fffdca4ee461\"}]}],\"vout\":[{\"value\":\"70667\",\"addr\":\"VirtualCallContractBurnGas\"},{\"value\":\"6784875300101405\",\"addr\":\"FFFc74b51BC5e75527fE5970D04355958dd3657C\"},{\"value\":\"72200\",\"addr\":\"VirtualBurnGas\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":8,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4625,\\\"blockTimestamp\\\":1719996570,\\\"contractDeployer\\\":\\\"FFFc74b51BC5e75527fE5970D04355958dd3657C\\\",\\\"donation\\\":0,\\\"input\\\":\\\"71e2a65700000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000a146bcaaee8d0e09eafcf022f1c3b199bf66bfee\\\",\\\"output\\\":\\\"\\\",\\\"recipient\\\":\\\"4273252d184B8d3E57fD07f255c947d35F0D0a56\\\",\\\"sender\\\":\\\"FFFc74b51BC5e75527fE5970D04355958dd3657C\\\",\\\"transfer\\\":0,\\\"version\\\":0,\\\"virtualMachine\\\":0}}\",\"info\":\"aW5mbw==\"}"
}
}
Return name | remark |
---|---|
contractJs | Contract block related information |
txJs | Contract input and output reference return information |
ErrorCode | Successfully returned "0" |
After signing, put txJson
into the data example of the return body:
{
"id": "1",
"jsonrpc": "2.0",
"method": "GetCallContractTransaction",
"result": {
"code": 0,
"contractJs": "{\"version\":\"1_1.1.1_t\",\"txMsgReq\":{\"version\":\"1_1.1.1_t\",\"txMsgInfo\":{\"nodeHeight\":\"1218\",\"contractStorageList\":[\"4273252d184B8d3E57fD07f255c947d35F0D0a56\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"b2048d103af6a0974877d74d7f0e9c5497ba9cba82a1b02d56f87d7878a4f50c\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEAnLqD9/PigVRvGYX+QlAlTfVRl9Pe8FVJMAB7iiSfGg0=\"}}}}",
"message": "success",
"txJson": "{\"time\":\"1719996570790958\",\"identity\":\"Ee24c3812e8D6253e808448e44E76CD0027AF610\",\"utxo\":{\"owner\":[\"FFFc74b51BC5e75527fE5970D04355958dd3657C\"],\"vin\":[{\"prevOut\":[{\"hash\":\"e145cfb7325cce407a266f5ee06a4d5b97f4a1c393ce36171713fffdca4ee461\"}],\"vinSign\":{\"sign\":\"4TyX8AyHuc1vJJX+cwO1b8qFXtcnXbyViUzVuZ011IIMowwcOw0yaIEjjRWWBS2gBSINcV+UOm5xDWpIKBXxBQ==\",\"pub\":\"MCowBQYDK2VwAyEAnLqD9/PigVRvGYX+QlAlTfVRl9Pe8FVJMAB7iiSfGg0=\"}}],\"vout\":[{\"value\":\"70667\",\"addr\":\"VirtualCallContractBurnGas\"},{\"value\":\"6784875300101405\",\"addr\":\"FFFc74b51BC5e75527fE5970D04355958dd3657C\"},{\"value\":\"72200\",\"addr\":\"VirtualBurnGas\"}],\"multiSign\":[{\"sign\":\"VaMrk3Pwrevg5nGs1Hh9emCeqnIpbH9EbzgkjgC/7/D45+8aaio1Mwwgz9Nb/vYfRZffKXVsExrFITH6ngiZDA==\",\"pub\":\"MCowBQYDK2VwAyEAnLqD9/PigVRvGYX+QlAlTfVRl9Pe8FVJMAB7iiSfGg0=\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":8,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4625,\\\"blockTimestamp\\\":1719996570,\\\"contractDeployer\\\":\\\"FFFc74b51BC5e75527fE5970D04355958dd3657C\\\",\\\"donation\\\":0,\\\"input\\\":\\\"71e2a65700000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000a146bcaaee8d0e09eafcf022f1c3b199bf66bfee\\\",\\\"output\\\":\\\"\\\",\\\"recipient\\\":\\\"4273252d184B8d3E57fD07f255c947d35F0D0a56\\\",\\\"sender\\\":\\\"FFFc74b51BC5e75527fE5970D04355958dd3657C\\\",\\\"transfer\\\":0,\\\"version\\\":0,\\\"virtualMachine\\\":0}}\",\"info\":\"aW5mbw==\"}"
}
}
Query token decimals
- The decimals method for constructing ABI.
String functionName = "decimals";
//Create an ABI function object
Function function = new Function(functionName, Arrays.asList(), // parameter list
Arrays.asList(new TypeReference<Uint256>() {
})); // List of return value types
// Perform ABI encoding
String encodedFunction = FunctionEncoder.encode(function);
The encoded encodedFunction
value serves as a parameter for args
.
- Query token decimals request through
/GetCallContractTransaction
interface.
{
"id": "1",
"jsonrpc": "2.0",
"params": {
"addr": "0xcED97dA085527Fe7e1772CA59Aa1e64A78143128",
"args": "0x313ce567",
"contractAddress": "0x7350399179EC2B0702008aE8b43a0579AA699Eb1",
"deployer": "cED97dA085527Fe7e1772CA59Aa1e64A78143128",
"deployutxo": "0x8a02413da127b48318a7ed12a46a4f68b83cdc6c21f937d7e6c99393d64112b0",
"isFindUtxo": false,
"istochain": "true",
"money": "0",
"pubstr": "MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=",
"tip": "0",
"txInfo": "info"
}
}
Return format:
{
"id": "1",
"jsonrpc": "2.0",
"method": "GetCallContractTransaction",
"result": {
"code": 0,
"contractJs": "{\"version\":\"1_1.1.1_t\",\"txMsgReq\":{\"version\":\"1_1.1.1_t\",\"txMsgInfo\":{\"nodeHeight\":\"1218\",\"contractStorageList\":[\"4273252d184B8d3E57fD07f255c947d35F0D0a56\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"b2048d103af6a0974877d74d7f0e9c5497ba9cba82a1b02d56f87d7878a4f50c\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEAnLqD9/PigVRvGYX+QlAlTfVRl9Pe8FVJMAB7iiSfGg0=\"}}}}",
"message": "success",
"txJson": "{\"time\":\"1719996570790958\",\"identity\":\"Ee24c3812e8D6253e808448e44E76CD0027AF610\",\"utxo\":{\"owner\":[\"FFFc74b51BC5e75527fE5970D04355958dd3657C\"],\"vin\":[{\"prevOut\":[{\"hash\":\"e145cfb7325cce407a266f5ee06a4d5b97f4a1c393ce36171713fffdca4ee461\"}]}],\"vout\":[{\"value\":\"70667\",\"addr\":\"VirtualCallContractBurnGas\"},{\"value\":\"6784875300101405\",\"addr\":\"FFFc74b51BC5e75527fE5970D04355958dd3657C\"},{\"value\":\"72200\",\"addr\":\"VirtualBurnGas\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":8,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4625,\\\"blockTimestamp\\\":1719996570,\\\"contractDeployer\\\":\\\"FFFc74b51BC5e75527fE5970D04355958dd3657C\\\",\\\"donation\\\":0,\\\"input\\\":\\\"71e2a65700000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000a146bcaaee8d0e09eafcf022f1c3b199bf66bfee\\\",\\\"output\\\":\\\"\\\",\\\"recipient\\\":\\\"4273252d184B8d3E57fD07f255c947d35F0D0a56\\\",\\\"sender\\\":\\\"FFFc74b51BC5e75527fE5970D04355958dd3657C\\\",\\\"transfer\\\":0,\\\"version\\\":0,\\\"virtualMachine\\\":0}}\",\"info\":\"aW5mbw==\"}"
}
}
Parse the Output value in the TxInfo
information of the data object in txJson
.
String output = result.getJSONObject("data").getJSONObject("TxInfo").getString("output");
List<Type> results = FunctionReturnDecoder.decode(output, function.getOutputParameters());
BigInteger balanceValue = (BigInteger) results.get(0).getValue();
Query token balance
- The balance method for constructing ABI.
String functionName = "balanceOf";
Address address = new Address(address);
Function functions = new Function(functionName, Arrays.asList(address),
Arrays.asList(new TypeReference<Uint256>() {
}));
String encodedFunction = FunctionEncoder.encode(functions);
The encoded encodedFunction
value serves as a parameter for args
.
-
Query token balance request through
/GetCallContractTransaction
interface. -
In the return parameters,Parse the Output value in the
TxInfo
information of the data object intxJs
.
String output = result.getJSONObject("data").getJSONObject("TxInfo").getString("output");
List<Type> results = FunctionReturnDecoder.decode(output, functions.getOutputParameters());
if(results.size()>0){
BigInteger balanceValue = (BigInteger) results.get(0).getValue();
return new BigDecimal(balanceValue.divide(decimals));
}
To obtain the balance value, it is necessary to process the decimal places based on the returned value from the decimals
function above.
Token transaction
Token transfer is also a process of calling contracts, using the Ethereum web3j function code to call the GetCallContractTransaction
interface
Asset transfer requires going up the chain and consuming a small amount of TTOS
Step1: Building a trading body
The trading method name may be either transfer or transferFrom, and it needs to be applied specifically according to the content defined by AbiJson in the contract. If it is transferFrom, the address of the form needs to be set in the input parameter list.
String functionName = "transfer";
boolean isTrade = getFunction(functionName,info.getAbiJs());
List<Type> inputList = new ArrayList<Type>();
if(!isTrade){
functionName ="transferFrom";
Address formAddress = new Address(addr);
inputList.add(formAddress);
}
Address recipientAddress = new Address(toAddr);
Uint256 value = new Uint256(amount);
inputList.add(recipientAddress);
inputList.add(value);
Function functions = new Function(functionName, inputList,
Arrays.asList(new org.web3j.abi.TypeReference<Address>() {
}, new org.web3j.abi.TypeReference<Uint256>() {
}));
String encodedFunction = FunctionEncoder.encode(functions);
The encoded encodedFunction
value serves as a parameter for args
.
For example: http://IP:port/GetCallContractTransaction
curl http://localhost:20620/GetCallContractTransaction -X POST -H "Content-Type: application/json" -d '
{
"id": "123",
"jsonrpc": "",
"params": {
"addr": "cED97dA085527Fe7e1772CA59Aa1e64A78143128",
"args": "0x7ad9ad7c000000000000000000000000ff3778ca36a2936390c06d8b0457f5b8e408389c0000000000000000000000000000000000000000000000000000000000002710",
"contractAddress": "0x7350399179EC2B0702008aE8b43a0579AA699Eb1",
"deployer": "cED97dA085527Fe7e1772CA59Aa1e64A78143128",
"deployutxo": "0x8a02413da127b48318a7ed12a46a4f68b83cdc6c21f937d7e6c99393d64112b0",
"isFindUtxo": false,
"istochain": "true",
"money": "0",
"pubstr": "MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=",
"tip": "0",
"txInfo": "info"
}
}
'
Sample Request:
{
"id": "1",
"jsonrpc": "2.0",
"params": {
"addr": "0xcED97dA085527Fe7e1772CA59Aa1e64A78143128",
"args": "0xa9059cbb00000000000000000000000012460d65f8df3b75e5279fb930a6b7cdfc4b38d4000000000000000000000000000000000000000000000000000000000bebc200",
"contractAddress": "0x7350399179EC2B0702008aE8b43a0579AA699Eb1",
"deployer": "cED97dA085527Fe7e1772CA59Aa1e64A78143128",
"deployutxo": "0x8a02413da127b48318a7ed12a46a4f68b83cdc6c21f937d7e6c99393d64112b0",
"isFindUtxo": false,
"istochain": "true",
"money": "0",
"pubstr": "MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=",
"tip": "0",
"txInfo": "info"
}
}
Sample Response:
{
"id": "1",
"jsonrpc": "2.0",
"method": "",
"result": {
"code": -1535152768,
"contractJs": "{\"version\":\"1_1.0.0_d\",\"txMsgReq\":{\"version\":\"1_1.0.0_d\",\"txMsgInfo\":{\"nodeHeight\":\"603\",\"contractStorageList\":[\"7350399179EC2B0702008aE8b43a0579AA699Eb1\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"79675c88de3a336d2e47c6134146f0a4d26e068ca76aa730ca654830c6bb6b96\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEASFAPKN8n+Nqn2RcJX8XCgyx1sveBLZ/f5tn5JpM2Xxs=\"}}}}",
"message": "",
"txJson": "{\"time\":\"1717148359029088\",\"identity\":\"0aFeBC02da4d5111d05d425e74e822B032274f2b\",\"utxo\":{\"owner\":[\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"],\"vin\":[{\"prevOut\":[{\"hash\":\"79675c88de3a336d2e47c6134146f0a4d26e068ca76aa730ca654830c6bb6b96\"}]}],\"vout\":[{\"value\":\"25041\",\"addr\":\"VirtualCallContractBurnGas\"},{\"value\":\"1982446318715\",\"addr\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"},{\"value\":\"65000\",\"addr\":\"VirtualBurnGas\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":8,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4345,\\\"blockTimestamp\\\":1717148360,\\\"contractDeployer\\\":\\\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\\\",\\\"donation\\\":0,\\\"input\\\":\\\"7ad9ad7c000000000000000000000000ff3778ca36a2936390c06d8b0457f5b8e408389c0000000000000000000000000000000000000000000000000000000000002710\\\",\\\"output\\\":\\\"\\\",\\\"recipient\\\":\\\"7350399179EC2B0702008aE8b43a0579AA699Eb1\\\",\\\"sender\\\":\\\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\\\",\\\"transfer\\\":0,\\\"version\\\":0,\\\"virtualMachine\\\":0}}\"}"
}
}
In the result
structure of the return body, obtain the txJson
field for signature.
Step2: sig_tx() function sign txJson
body
Sign the return txJson
value as it is, and call SendMessageas
a parameter.
Calling the sig_tx() method in the tfc_sdk
dynamic library
char * sig_tx(const char *message ,int msize, long long pkey);
The structure of the broadcast transaction body after signing
{
"id": "",
"jsonrpc": "",
"result": {
"code": "",
"contractJs": "{\"version\":\"1_1.0.0_d\",\"txMsgReq\":{\"version\":\"1_1.0.0_d\",\"txMsgInfo\":{\"nodeHeight\":\"601\",\"contractStorageList\":[\"A8B8Ae6F84709fF80E08aD9d26575c161aCC95f1\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"dea1b44a641928d6a09db9a3d9da274abe4ef13eb23833213144a5b46c612136\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEASFAPKN8n+Nqn2RcJX8XCgyx1sveBLZ/f5tn5JpM2Xxs=\"}}}}",
"message": "",
"txJson": "{\"time\":\"1717148103333839\",\"identity\":\"2eb2F635320c3Dbf29eadD35E894c13EE3F20bd5\",\"utxo\":{\"owner\":[\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"],\"vin\":[{\"prevOut\":[{\"hash\":\"dea1b44a641928d6a09db9a3d9da274abe4ef13eb23833213144a5b46c612136\"}],\"vinSign\":{\"sign\":\"3o82Rq7taGO+VRtrhtxWOVPAolo/pVxuNXEBdklDpDVd8tJcTjNrnmaMFixdav2wCyvCb+AFOd02ryPI4JV1Cw==\",\"pub\":\"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=\"}}],\"vout\":[{\"value\":\"480\",\"addr\":\"VirtualDeployContractBurnGas\"},{\"value\":\"1982446498797\",\"addr\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"},{\"value\":\"493200\",\"addr\":\"VirtualBurnGas\"}],\"multiSign\":[{\"sign\":\"YVcOA5gZhVNaQx7eoduw4lOI4d1HNtPRWEUoMzDK6D2UnZXDbRziXV66XiaRxKOzXF3kF/N4j8PEe5CMjkf3BQ==\",\"pub\":\"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":7,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4406,\\\"blockTimestamp\\\":1717148110,\\\"input\\\":\\\"608060405234801561001057600080fd5b506108b3806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630483a7f61461005c5780631629614e1461008c57806327e235e3146100a85780637ad9ad7c146100d8578063afc58189146100f4575b600080fd5b610076600480360381019061007191906105a8565b610110565b60405161008391906106d7565b60405180910390f35b6100a660048036038101906100a19190610615565b610128565b005b6100c260048036038101906100bd91906105a8565b6102a7565b6040516100cf91906106d7565b60405180910390f35b6100f260048036038101906100ed91906105d5565b6102bf565b005b61010e60048036038101906101099190610615565b61037d565b005b60016020528060005260406000206000915090505481565b80806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156101aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a1906106b7565b60405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546101f89190610759565b9250508190555081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461024e9190610703565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f3a14c6aa3e15c61c97825b026647b989a91e18aa33b689769475a298922480428360405161029b91906106d7565b60405180910390a25050565b60006020528060005260406000206000915090505481565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461030d9190610703565b925050819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f322d0c4befd4c2dd440740b711488a1638fd7d8eeb25f9dacede84083db428c98360405161037191906106d7565b60405180910390a35050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610400576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f790610697565b60405180910390fd5b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610482576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047990610697565b60405180910390fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104d09190610703565b9250508190555080600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105269190610759565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f867b353f032680758428983522443995b88120a470e436b962c6a9d0d8940af78260405161057391906106d7565b60405180910390a250565b60008135905061058d8161084f565b92915050565b6000813590506105a281610866565b92915050565b6000602082840312156105be576105bd6107f8565b5b60006105cc8482850161057e565b91505092915050565b600080604083850312156105ec576105eb6107f8565b5b60006105fa8582860161057e565b925050602061060b85828601610593565b9150509250929050565b60006020828403121561062b5761062a6107f8565b5b600061063984828501610593565b91505092915050565b600061064f6011836106f2565b915061065a826107fd565b602082019050919050565b60006106726014836106f2565b915061067d82610826565b602082019050919050565b610691816107bf565b82525050565b600060208201905081810360008301526106b081610642565b9050919050565b600060208201905081810360008301526106d081610665565b9050919050565b60006020820190506106ec6000830184610688565b92915050565b600082825260208201905092915050565b600061070e826107bf565b9150610719836107bf565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561074e5761074d6107c9565b5b828201905092915050565b6000610764826107bf565b915061076f836107bf565b925082821015610782576107816107c9565b5b828203905092915050565b60006107988261079f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b7f4e6f206c6f636b65642062616c616e6365000000000000000000000000000000600082015250565b7f496e73756666696369656e742062616c616e6365000000000000000000000000600082015250565b6108588161078d565b811461086357600080fd5b50565b61086f816107bf565b811461087a57600080fd5b5056fea264697066735822122067e67aed3152cf78a07c4f8842540cf5803e421699b10fbf8f66c015550b0ed464736f6c63430008070033\\\",\\\"recipient\\\":\\\"A8B8Ae6F84709fF80E08aD9d26575c161aCC95f1\\\",\\\"sender\\\":\\\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\\\",\\\"version\\\":0,\\\"virtualMachine\\\":0}}\"}"
}
}
Step3: send message
After returning the value for public key signature, send the transaction as a parameter
For example: http://IP:port/SendContractMessage
curl http://localhost:20620/SendContractMessage -X POST -H "Content-Type: application/json" -d '
{
"id": "",
"jsonrpc": "",
"result": {
"code": "",
"contractJs": "{\"version\":\"1_1.0.0_d\",\"txMsgReq\":{\"version\":\"1_1.0.0_d\",\"txMsgInfo\":{\"nodeHeight\":\"601\",\"contractStorageList\":[\"A8B8Ae6F84709fF80E08aD9d26575c161aCC95f1\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"dea1b44a641928d6a09db9a3d9da274abe4ef13eb23833213144a5b46c612136\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEASFAPKN8n+Nqn2RcJX8XCgyx1sveBLZ/f5tn5JpM2Xxs=\"}}}}",
"message": "",
"txJson": "{\"time\":\"1717148103333839\",\"identity\":\"2eb2F635320c3Dbf29eadD35E894c13EE3F20bd5\",\"utxo\":{\"owner\":[\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"],\"vin\":[{\"prevOut\":[{\"hash\":\"dea1b44a641928d6a09db9a3d9da274abe4ef13eb23833213144a5b46c612136\"}],\"vinSign\":{\"sign\":\"3o82Rq7taGO+VRtrhtxWOVPAolo/pVxuNXEBdklDpDVd8tJcTjNrnmaMFixdav2wCyvCb+AFOd02ryPI4JV1Cw==\",\"pub\":\"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=\"}}],\"vout\":[{\"value\":\"480\",\"addr\":\"VirtualDeployContractBurnGas\"},{\"value\":\"1982446498797\",\"addr\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"},{\"value\":\"493200\",\"addr\":\"VirtualBurnGas\"}],\"multiSign\":[{\"sign\":\"YVcOA5gZhVNaQx7eoduw4lOI4d1HNtPRWEUoMzDK6D2UnZXDbRziXV66XiaRxKOzXF3kF/N4j8PEe5CMjkf3BQ==\",\"pub\":\"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":7,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4406,\\\"blockTimestamp\\\":1717148110,\\\"input\\\":\\\"608060405234801561001057600080fd5b506108b3806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630483a7f61461005c5780631629614e1461008c57806327e235e3146100a85780637ad9ad7c146100d8578063afc58189146100f4575b600080fd5b610076600480360381019061007191906105a8565b610110565b60405161008391906106d7565b60405180910390f35b6100a660048036038101906100a19190610615565b610128565b005b6100c260048036038101906100bd91906105a8565b6102a7565b6040516100cf91906106d7565b60405180910390f35b6100f260048036038101906100ed91906105d5565b6102bf565b005b61010e60048036038101906101099190610615565b61037d565b005b60016020528060005260406000206000915090505481565b80806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156101aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a1906106b7565b60405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546101f89190610759565b9250508190555081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461024e9190610703565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f3a14c6aa3e15c61c97825b026647b989a91e18aa33b689769475a298922480428360405161029b91906106d7565b60405180910390a25050565b60006020528060005260406000206000915090505481565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461030d9190610703565b925050819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f322d0c4befd4c2dd440740b711488a1638fd7d8eeb25f9dacede84083db428c98360405161037191906106d7565b60405180910390a35050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610400576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f790610697565b60405180910390fd5b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610482576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047990610697565b60405180910390fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104d09190610703565b9250508190555080600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105269190610759565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f867b353f032680758428983522443995b88120a470e436b962c6a9d0d8940af78260405161057391906106d7565b60405180910390a250565b60008135905061058d8161084f565b92915050565b6000813590506105a281610866565b92915050565b6000602082840312156105be576105bd6107f8565b5b60006105cc8482850161057e565b91505092915050565b600080604083850312156105ec576105eb6107f8565b5b60006105fa8582860161057e565b925050602061060b85828601610593565b9150509250929050565b60006020828403121561062b5761062a6107f8565b5b600061063984828501610593565b91505092915050565b600061064f6011836106f2565b915061065a826107fd565b602082019050919050565b60006106726014836106f2565b915061067d82610826565b602082019050919050565b610691816107bf565b82525050565b600060208201905081810360008301526106b081610642565b9050919050565b600060208201905081810360008301526106d081610665565b9050919050565b60006020820190506106ec6000830184610688565b92915050565b600082825260208201905092915050565b600061070e826107bf565b9150610719836107bf565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561074e5761074d6107c9565b5b828201905092915050565b6000610764826107bf565b915061076f836107bf565b925082821015610782576107816107c9565b5b828203905092915050565b60006107988261079f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b7f4e6f206c6f636b65642062616c616e6365000000000000000000000000000000600082015250565b7f496e73756666696369656e742062616c616e6365000000000000000000000000600082015250565b6108588161078d565b811461086357600080fd5b50565b61086f816107bf565b811461087a57600080fd5b5056fea264697066735822122067e67aed3152cf78a07c4f8842540cf5803e421699b10fbf8f66c015550b0ed464736f6c63430008070033\\\",\\\"recipient\\\":\\\"A8B8Ae6F84709fF80E08aD9d26575c161aCC95f1\\\",\\\"sender\\\":\\\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\\\",\\\"version\\\":0,\\\"virtualMachine\\\":0}}\"}"
}
}
'
Sample Request:
{
"id": "",
"jsonrpc": "",
"result": {
"code": "",
"contractJs": "{\"version\":\"1_1.0.0_d\",\"txMsgReq\":{\"version\":\"1_1.0.0_d\",\"txMsgInfo\":{\"nodeHeight\":\"601\",\"contractStorageList\":[\"A8B8Ae6F84709fF80E08aD9d26575c161aCC95f1\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"dea1b44a641928d6a09db9a3d9da274abe4ef13eb23833213144a5b46c612136\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEASFAPKN8n+Nqn2RcJX8XCgyx1sveBLZ/f5tn5JpM2Xxs=\"}}}}",
"message": "",
"txJson": "{\"time\":\"1717148103333839\",\"identity\":\"2eb2F635320c3Dbf29eadD35E894c13EE3F20bd5\",\"utxo\":{\"owner\":[\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"],\"vin\":[{\"prevOut\":[{\"hash\":\"dea1b44a641928d6a09db9a3d9da274abe4ef13eb23833213144a5b46c612136\"}],\"vinSign\":{\"sign\":\"3o82Rq7taGO+VRtrhtxWOVPAolo/pVxuNXEBdklDpDVd8tJcTjNrnmaMFixdav2wCyvCb+AFOd02ryPI4JV1Cw==\",\"pub\":\"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=\"}}],\"vout\":[{\"value\":\"480\",\"addr\":\"VirtualDeployContractBurnGas\"},{\"value\":\"1982446498797\",\"addr\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"},{\"value\":\"493200\",\"addr\":\"VirtualBurnGas\"}],\"multiSign\":[{\"sign\":\"YVcOA5gZhVNaQx7eoduw4lOI4d1HNtPRWEUoMzDK6D2UnZXDbRziXV66XiaRxKOzXF3kF/N4j8PEe5CMjkf3BQ==\",\"pub\":\"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":7,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4406,\\\"blockTimestamp\\\":1717148110,\\\"input\\\":\\\"608060405234801561001057600080fd5b506108b3806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630483a7f61461005c5780631629614e1461008c57806327e235e3146100a85780637ad9ad7c146100d8578063afc58189146100f4575b600080fd5b610076600480360381019061007191906105a8565b610110565b60405161008391906106d7565b60405180910390f35b6100a660048036038101906100a19190610615565b610128565b005b6100c260048036038101906100bd91906105a8565b6102a7565b6040516100cf91906106d7565b60405180910390f35b6100f260048036038101906100ed91906105d5565b6102bf565b005b61010e60048036038101906101099190610615565b61037d565b005b60016020528060005260406000206000915090505481565b80806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156101aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a1906106b7565b60405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546101f89190610759565b9250508190555081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461024e9190610703565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f3a14c6aa3e15c61c97825b026647b989a91e18aa33b689769475a298922480428360405161029b91906106d7565b60405180910390a25050565b60006020528060005260406000206000915090505481565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461030d9190610703565b925050819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f322d0c4befd4c2dd440740b711488a1638fd7d8eeb25f9dacede84083db428c98360405161037191906106d7565b60405180910390a35050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610400576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f790610697565b60405180910390fd5b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610482576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047990610697565b60405180910390fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104d09190610703565b9250508190555080600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105269190610759565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f867b353f032680758428983522443995b88120a470e436b962c6a9d0d8940af78260405161057391906106d7565b60405180910390a250565b60008135905061058d8161084f565b92915050565b6000813590506105a281610866565b92915050565b6000602082840312156105be576105bd6107f8565b5b60006105cc8482850161057e565b91505092915050565b600080604083850312156105ec576105eb6107f8565b5b60006105fa8582860161057e565b925050602061060b85828601610593565b9150509250929050565b60006020828403121561062b5761062a6107f8565b5b600061063984828501610593565b91505092915050565b600061064f6011836106f2565b915061065a826107fd565b602082019050919050565b60006106726014836106f2565b915061067d82610826565b602082019050919050565b610691816107bf565b82525050565b600060208201905081810360008301526106b081610642565b9050919050565b600060208201905081810360008301526106d081610665565b9050919050565b60006020820190506106ec6000830184610688565b92915050565b600082825260208201905092915050565b600061070e826107bf565b9150610719836107bf565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561074e5761074d6107c9565b5b828201905092915050565b6000610764826107bf565b915061076f836107bf565b925082821015610782576107816107c9565b5b828203905092915050565b60006107988261079f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b7f4e6f206c6f636b65642062616c616e6365000000000000000000000000000000600082015250565b7f496e73756666696369656e742062616c616e6365000000000000000000000000600082015250565b6108588161078d565b811461086357600080fd5b50565b61086f816107bf565b811461087a57600080fd5b5056fea264697066735822122067e67aed3152cf78a07c4f8842540cf5803e421699b10fbf8f66c015550b0ed464736f6c63430008070033\\\",\\\"recipient\\\":\\\"A8B8Ae6F84709fF80E08aD9d26575c161aCC95f1\\\",\\\"sender\\\":\\\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\\\",\\\"version\\\":0,\\\"virtualMachine\\\":0}}\"}"
}
}
Sample Response:
{
"id": "1",
"jsonrpc": "2.0",
"method": "GetCallContractTransaction",
"result": {
"code": 0,
"txhash": "0x9486c7cb49e22726b5fbbcaac4f4842e020bc3357feeed3037c23e1fc88c8715",
"message": "success"
}
}
Mint NFT
The mint method for constructing ABI.
String functionName = "mint";
int number = 1;
Uint256 quantity = new Uint256(number);
Function function = new Function(
functionName,
Arrays.asList(quantity),
Collections.emptyList());
String encodedFunction = FunctionEncoder.encode(function);
The encoded encodedFunction
value serves as a parameter for args
.
Step1: mint NFT request through /GetCallContractTransaction
interface.
The mint transaction needs to on chain, and the istochain
field should be set to "true".
Step2: sig_tx() function sign txJson
body
Sign the txJson
field in the return body, update the txJson
field information after signing, and send it as the request body
Step3: send message
Broadcast transactions through calling the SendContractMessage
interface and upload them onto the chain
Others
Other contract related execution operations only require passing different args
parameters in the GetCallContractTransaction interface.
The specific arg encoding method can be found at: https://docs.web3js.org/guides/smart_contracts/mastering_smart_contracts#abi-and-bytecode