Skip to main content

Introduction

All transaction interfaces use Post request method, and the data format of the request parameters is JSON.

Step​

Constructing a contract​

According to different interfaces, different parameter values are passed in. The interfaces for contract transactions include /GetDeployContractTransaction, /GetCallContractTransaction etc

When calling contracts, some contract calls do not require on chain(Do not sign and call the SendContractMessage interface), such as querying token balance, querying token/NFT name and Decimals, Allow NFT mint personnel etc. After calling the call method, directly parse the output field in the TxInfo of the data in the return body, and obtain the information you want through web3j parsing.

JSONObject result = JSONObject.parseObject(contract_ack.result.txJson);
String res = result.getJSONObject("data").getJSONObject("TxInfo").getString("output");

Signature of contract entity​

Based on the content returned by the interface above, use SDK to sig_contract_tx(message,message_size,privatePkey) the transaction entity.

Broadcast contract transaction​

The signed transaction body is used as a parameter to generate a /SendContractMessage for broadcasting the transaction.

Deploying contracts(/GetDeployContractTransaction), transferring token/NFT, mint NFT and other transactions require on chain operations. The API calling process is divided into three steps.

Confirm contract transaction​

After the transaction is sent, use the /ConfirmTransaction interface to check if the transaction is on chain.

API use example​

The following is an example of sending token transactions

1. GetCallContractTransaction​

Send the parameter body and obtain the token transaction body through the GetCallContractTransaction RPC interface.

Parameter​

{
"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"
}
}

Response​

{
"id": "123",
"jsonrpc": "",
"method": "",
"result": {
"code": 0,
"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}}\"}"
}
}

2. txJsonSign() Or sig_contract_tx()​

Sign the txJson field of the return body.

txJson = ...;
message = txJson;
message_size = message.length;
signature = api.txJsonSign(message,privatePkey);

Of course, the entire transaction can also be signed by calling the sig_contract_tx() method

Signed structure​

{
"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\":8,\"data\":\"{\"TxInfo\":{\"blockPrevRandao\":4345,\"blockTimestamp\":1717148360,\"contractDeployer\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\",\"donation\":0,\"input\":\"7ad9ad7c000000000000000000000000ff3778ca36a2936390c06d8b0457f5b8e408389c0000000000000000000000000000000000000000000000000000000000002710\",\"output\":\"\",\"recipient\":\"7350399179EC2B0702008aE8b43a0579AA699Eb1\",\"sender\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\",\"transfer\":0,\"version\":0,\"virtualMachine\":0}}\"}"
}
}

Add vinSign,multiSign signature data in txJson, and determine whether the signature is successful by adding Sign data

"vinSign":{sign:"ApxL8NDgh9YYDuUXpdbsbVv0cEAr3HyXmr2TICkD4mfuDIZqVlZJNUmaPAKHCs5kkn7JnZx7r12+CpnnR4ZpAg==",pub:"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg="}

"multiSign":[{sign:"WCoFsLKML69x1rSpQc7pwbnd+GMfZ0Ce3wTPg96Rdb1v7ezFw9KuEBXwvGecTz264pVZB6T8hzgJIx26GuKVAA==",pub:"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg="}]

3. SendContractMessage​

Using the signed structure as a parameter, send the transaction to the node through the SendContractMessage interface to complete call.

Response

{
"id": "1",
"jsonrpc": "2.0",
"method": "SendContractMessage",
"result": {
"code": 0,
"message": "success",
"txHash": "0x01f46aaee0d0d87f1164d9dda4154544cc67627b70d512805fd85c0f92a45706"
}
}

4. ConfirmTransaction​

Use the height obtained from interface 1.GetCallContractTransaction and the txHash obtained from interface 3.SendContractMessage to query whether the transaction is on chain.

Parameter

{
"id":"1",
"jsonrpc":"2.0",
"params":{
"txhash":"0x01f46aaee0d0d87f1164d9dda4154544cc67627b70d512805fd85c0f92a45706",
"height": "2506"
}
}

The /ConfirmTransaction interface returns a percent >= 0.8, indicating a successful transaction on the chain.

Contract body details​

  • Deploy contract
    • TxInfo Deploy contract information
      • blockPrevRandao: Random number calculated based on the vin of the transaction
      • blockTimestamp: Contract block timestamp (in seconds)
      • input: Contract binary code
      • recipient: The sender of the message
      • sender: The recipient of the message
      • version: version
      • virtualMachine: virtual machine
        • EVM:0
        • WASM:1
  • Execute contract
    • TxInfo Execute contract information
      • blockPrevRandao: Random number calculated based on the vin of the transaction
      • blockTimestamp: Contract block timestamp (in seconds)
      • contractDeployer: Deploy contract address
      • donation: A tip for the contract deployment personnel
      • input: Parameters for executing the contract
      • recipient: The sender of the message
      • sender: The recipient of the message
      • transfer: Money transferred to the contract
      • version: version
      • virtualMachine: virtual machine
        • EVM:0
        • WASM:1