Skip to main content

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

  1. Prepare an account, which includes the account private key, public key, and address.
  2. Ensure that there is a certain amount of TTOS in the account to be used for gas fees for deploying/executing contracts.
  3. 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.
  4. Familiar with the transaction process of Transformers network.

Deploy Contract

  • Send deploy Contract request through /GetDeployContractTransaction interface.

The parameter format is as follows:

{
"id": "1",
"jsonrpc": "2.0",
"params": {
"addr": "0xcED97dA085527Fe7e1772CA59Aa1e64A78143128",
"contract": "608060405234801561001057600080fd5b506108b3806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630483a7f61461005c5780631629614e1461008c57806327e235e3146100a85780637ad9ad7c146100d8578063afc58189146100f4575b600080fd5b610076600480360381019061007191906105a8565b610110565b60405161008391906106d7565b60405180910390f35b6100a660048036038101906100a19190610615565b610128565b005b6100c260048036038101906100bd91906105a8565b6102a7565b6040516100cf91906106d7565b60405180910390f35b6100f260048036038101906100ed91906105d5565b6102bf565b005b61010e60048036038101906101099190610615565b61037d565b005b60016020528060005260406000206000915090505481565b80806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410156101aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a1906106b7565b60405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546101f89190610759565b9250508190555081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461024e9190610703565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f3a14c6aa3e15c61c97825b026647b989a91e18aa33b689769475a298922480428360405161029b91906106d7565b60405180910390a25050565b60006020528060005260406000206000915090505481565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461030d9190610703565b925050819055508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f322d0c4befd4c2dd440740b711488a1638fd7d8eeb25f9dacede84083db428c98360405161037191906106d7565b60405180910390a35050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541415610400576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f790610697565b60405180910390fd5b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610482576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047990610697565b60405180910390fd5b806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104d09190610703565b9250508190555080600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105269190610759565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f867b353f032680758428983522443995b88120a470e436b962c6a9d0d8940af78260405161057391906106d7565b60405180910390a250565b60008135905061058d8161084f565b92915050565b6000813590506105a281610866565b92915050565b6000602082840312156105be576105bd6107f8565b5b60006105cc8482850161057e565b91505092915050565b600080604083850312156105ec576105eb6107f8565b5b60006105fa8582860161057e565b925050602061060b85828601610593565b9150509250929050565b60006020828403121561062b5761062a6107f8565b5b600061063984828501610593565b91505092915050565b600061064f6011836106f2565b915061065a826107fd565b602082019050919050565b60006106726014836106f2565b915061067d82610826565b602082019050919050565b610691816107bf565b82525050565b600060208201905081810360008301526106b081610642565b9050919050565b600060208201905081810360008301526106d081610665565b9050919050565b60006020820190506106ec6000830184610688565b92915050565b600082825260208201905092915050565b600061070e826107bf565b9150610719836107bf565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561074e5761074d6107c9565b5b828201905092915050565b6000610764826107bf565b915061076f836107bf565b925082821015610782576107816107c9565b5b828203905092915050565b60006107988261079f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b7f4e6f206c6f636b65642062616c616e6365000000000000000000000000000000600082015250565b7f496e73756666696369656e742062616c616e6365000000000000000000000000600082015250565b6108588161078d565b811461086357600080fd5b50565b61086f816107bf565b811461087a57600080fd5b5056fea264697066735822122067e67aed3152cf78a07c4f8842540cf5803e421699b10fbf8f66c015550b0ed464736f6c63430008070033",
"data": "",
"info": "[]",
"isFindUtxo": false,
"nContractType": "0",
"pubstr": "MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=",
"txInfo": "info"
}
}
Parameter nameremark
contractThe compiled binary code of the contract source code
dataCompiled binary code for constructing parameters

Return:

{
"id": "1",
"jsonrpc": "2.0",
"method": "GetDeployContractTransaction",
"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}}\"}"
}
}
  • Sign the returned information content using the SDK's sig_contract_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());
}
  • The signed content is sent to the entire network for broadcasting through the SendContractMessage interface.

Parameter:

{
"id": "1",
"jsonrpc": "2.0",
"method": "GetDeployContractTransaction",
"result": {
"code": 0,
"contractJs": "{\"version\":\"1_1.0.0_t\",\"txMsgReq\":{\"version\":\"1_1.0.0_t\",\"txMsgInfo\":{\"nodeHeight\":\"38063\",\"contractStorageList\":[\"0Da3C12c4800514172D09DE6B8E822f1a53867BB\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"a91ec2286abff95217e00c0f4ecced4d1dc218e54ac7b11b293f10116c321fbc\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEAl6sWjI7LUPG12NJD+1DfGoHeaKdVhlgAQWlbFDYaGKI=\"}}}}",
"message": "success",
"txJson": "{\"time\":\"1719300454043049\",\"identity\":\"32373Aa5c3Ce556B4b6c22dfCB028e33A3c8570D\",\"utxo\":{\"owner\":[\"ad8A44a37e647b143aFc7915C95b24cF95A6040f\"],\"vin\":[{\"prevOut\":[{\"hash\":\"aaebd3b5ab2814f48979f69a10938ed29efec3c5856f0d8475f25e2da179a136\"}],\"vinSign\":{\"sign\":\"tbBTFZs/Ws5dkdnpFK2jZs/H5Jv7FKUNLnl91rdfCMHXBP9EjPBgx0wgwu0WUNj9LvkGGzh5QyCupVKHJ/9WDw==\",\"pub\":\"MCowBQYDK2VwAyEAZikZ/ntlAzuMa6vRj8E6Vsr5MI+mew6ZYRS3lTfV1RQ=\"}}],\"vout\":[{\"value\":\"70667\",\"addr\":\"VirtualCallContractBurnGas\"},{\"value\":\"96216316\",\"addr\":\"ad8A44a37e647b143aFc7915C95b24cF95A6040f\"},{\"value\":\"72200\",\"addr\":\"VirtualBurnGas\"}],\"multiSign\":[{\"sign\":\"MzkwSEhy5s6/2LzfhzfBNL8tjNn3fF4pn+QOJKGD6vUjX8NdrYMj/NOkyJxQRV3QTnTflQyKngA/yZUoeA1jCA==\",\"pub\":\"MCowBQYDK2VwAyEAZikZ/ntlAzuMa6vRj8E6Vsr5MI+mew6ZYRS3lTfV1RQ=\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":8,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4555,\\\"blockTimestamp\\\":1719300460,\\\"contractDeployer\\\":\\\"ad8A44a37e647b143aFc7915C95b24cF95A6040f\\\",\\\"donation\\\":0,\\\"input\\\":\\\"71e2a65700000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e89fe559b0fe67ef03c40cd451a6dcc546a16bc2\\\",\\\"output\\\":\\\"\\\",\\\"recipient\\\":\\\"0Da3C12c4800514172D09DE6B8E822f1a53867BB\\\",\\\"sender\\\":\\\"ad8A44a37e647b143aFc7915C95b24cF95A6040f\\\",\\\"transfer\\\":0,\\\"version\\\":0,\\\"virtualMachine\\\":0}}\",\"info\":\"aW5mbw==\"}"
}
}

Return:

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

Execute contract

Executing a contract allows for many operations on a smart contract, including querying balance, querying decimal places, performing token/NFT transfers, minting, etc.

Parameter format:

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

Parameter nameremark
deployerTTOS address with deployer
deployutxothe utxo deployed through GetDeployContractTransaction interface acquisition,A deployer may deploy multiple contracts
contractAddresscontract address
argsBuilt ABI function object, encoded value content
pubstrExecutor's public key,No transfer of tokens/NFTs involved, value is ""
tipTips for deployers
moneyReward contract address
istochaintrue 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.0.0_t\",\"txMsgReq\":{\"version\":\"1_1.0.0_t\",\"txMsgInfo\":{\"nodeHeight\":\"38063\",\"contractStorageList\":[\"0Da3C12c4800514172D09DE6B8E822f1a53867BB\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"a91ec2286abff95217e00c0f4ecced4d1dc218e54ac7b11b293f10116c321fbc\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEAl6sWjI7LUPG12NJD+1DfGoHeaKdVhlgAQWlbFDYaGKI=\"}}}}",
"message": "success",
"txJson": "{\"time\":\"1719300454043049\",\"identity\":\"32373Aa5c3Ce556B4b6c22dfCB028e33A3c8570D\",\"utxo\":{\"owner\":[\"ad8A44a37e647b143aFc7915C95b24cF95A6040f\"],\"vin\":[{\"prevOut\":[{\"hash\":\"aaebd3b5ab2814f48979f69a10938ed29efec3c5856f0d8475f25e2da179a136\"}]}],\"vout\":[{\"value\":\"70667\",\"addr\":\"VirtualCallContractBurnGas\"},{\"value\":\"96216316\",\"addr\":\"ad8A44a37e647b143aFc7915C95b24cF95A6040f\"},{\"value\":\"72200\",\"addr\":\"VirtualBurnGas\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":8,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4555,\\\"blockTimestamp\\\":1719300460,\\\"contractDeployer\\\":\\\"ad8A44a37e647b143aFc7915C95b24cF95A6040f\\\",\\\"donation\\\":0,\\\"input\\\":\\\"71e2a65700000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e89fe559b0fe67ef03c40cd451a6dcc546a16bc2\\\",\\\"output\\\":\\\"\\\",\\\"recipient\\\":\\\"0Da3C12c4800514172D09DE6B8E822f1a53867BB\\\",\\\"sender\\\":\\\"ad8A44a37e647b143aFc7915C95b24cF95A6040f\\\",\\\"transfer\\\":0,\\\"version\\\":0,\\\"virtualMachine\\\":0}}\",\"info\":\"aW5mbw==\"}"
}
}
Return nameremark
contractJsContract block related information
txJsContract input and output reference return information
codeSuccessfully returned "0"
messageSuccessfully returned "success"

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": "cED97dA085527Fe7e1772CA59Aa1e64A78143128",
"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.0.0_d\",\"txMsgReq\":{\"version\":\"1_1.0.0_d\",\"txMsgInfo\":{\"nodeHeight\":\"228\",\"contractStorageList\":[\"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"9486c7cb49e22726b5fbbcaac4f4842e020bc3357feeed3037c23e1fc88c8715\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEAi4wKVbeYc4HAOtMLHJOTA/K2aEKWWdhttywUWEhppDM=\"}}}}",
"txJson": "{\"time\":\"1716018850896709\",\"identity\":\"A433AF879aC1f92Be4cA57C3517e4c2e11343dd3\",\"utxo\":{\"owner\":[\"0xfE7EfC12a4803A655f3629d05AbbB5Cd57d5beeD\"],\"vin\":[{\"prevOut\":[{\"hash\":\"90ed17d65ce0731b368a9961980e62244fe64529bdfd71fc090151499c9f6e79\"}]}],\"vout\":[{\"value\":\"2538\",\"addr\":\"VirtualCallContractBurnGas\"},{\"value\":\"99998250629\",\"addr\":\"fE7EfC12a4803A655f3629d05AbbB5Cd57d5beeD\"},{\"value\":\"58600\",\"addr\":\"VirtualBurnGas\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":8,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4282,\\\"blockTimestamp\\\":1716018850,\\\"contractDeployer\\\":\\\"fE7EfC12a4803A655f3629d05AbbB5Cd57d5beeD\\\",\\\"donation\\\":0,\\\"input\\\":\\\"313ce567\\\",\\\"output\\\":\\\"0000000000000000000000000000000000000000000000000000000000000008\\\",\\\"recipient\\\":\\\"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603\\\",\\\"sender\\\":\\\"fE7EfC12a4803A655f3629d05AbbB5Cd57d5beeD\\\",\\\"transfer\\\":0,\\\"version\\\":0,\\\"virtualMachine\\\":0}}\"}",
"message": "success",

}
}

Parse the Output value in the TxInfo information of the data object in txJson.

 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 in txJson.

   List<Type> results = FunctionReturnDecoder.decode(output, functions.getOutputParameters());
BigInteger balanceValue = (BigInteger) results.get(0).getValue();

To obtain the balance value, it is necessary to process the decimal places based on the returned value from the decimals function above.

Transfer token

  • The transfer method for constructing ABI.
caution

Asset transfer requires going up the chain and consuming a small amount of TTOS

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.

  • Transfer token request through /GetCallContractTransaction interface.
{
"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"
}
}

  1. The pubStr value is the public key of the transfer
  2. The addr value is the TTOS address of the transfer
  3. The istochain value is true
  • Sign the returned information content using the SDK's sig_contract_tx method.

  • The signed content is sent to the entire network for broadcasting through the SendContractMessage interface.

Structure after signature,as a parameter for SendContractMessage

{
"id": "1",
"jsonrpc": "2.0",
"result": {
"code": "0",
"message": "",
"contractJs": "{\"version\":\"1_1.0.0_d\",\"txMsgReq\":{\"version\":\"1_1.0.0_d\",\"txMsgInfo\":{\"nodeHeight\":\"227\",\"contractStorageList\":[\"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603\"]},\"vrfInfo\":{\"vrfdata\":{\"hash\":\"1093122915e33857c377df82abefa3c00954c0d89935d9cdd60a01fd0066b016\"},\"Vrfsign\":{\"pub\":\"MCowBQYDK2VwAyEAi4wKVbeYc4HAOtMLHJOTA/K2aEKWWdhttywUWEhppDM=\"}}}}",
"txJs": "{\"time\":\"1716012233085554\",\"identity\":\"200579F024457E2670b5ed3430cB2247Ea8C0837\",\"utxo\":{\"owner\":[\"6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\"],\"vin\":[{\"prevOut\":[{\"hash\":\"1093122915e33857c377df82abefa3c00954c0d89935d9cdd60a01fd0066b016\"}],\"vinSign\":{\"sign\":\"aQGtgZa+10JUX8VisKLc93ni8e7R/X2KdgLXdBBp3bspnlHtsb+hAzKPnbQEEqk2oB1GCXB2pksP6VukSfc0Aw==\",\"pub\":\"MCowBQYDK2VwAyEAuOmhl9PiwwviYtwW1ZVzl8e2LGC+4KA5fsQmJyt/XTo=\"}}],\"vout\":[{\"value\":\"48119\",\"addr\":\"VirtualCallContractBurnGas\"},{\"value\":\"197899479843\",\"addr\":\"6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\"},{\"value\":\"71400\",\"addr\":\"VirtualBurnGas\"}],\"multiSign\":[{\"sign\":\"1GqxwY9eh2ONlZM4Lw9OleJq8VKbAj+cJFYGEmnXofitcDbVFwKGsz+ETmkkfrNk3TeOqnGK+4K6OPjYVEMiDA==\",\"pub\":\"MCowBQYDK2VwAyEAuOmhl9PiwwviYtwW1ZVzl8e2LGC+4KA5fsQmJyt/XTo=\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":8,\"data\":\"{\\\"TxInfo\\\":{\\\"blockPrevRandao\\\":4279,\\\"blockTimestamp\\\":1716012240,\\\"contractDeployer\\\":\\\"fE7EfC12a4803A655f3629d05AbbB5Cd57d5beeD\\\",\\\"donation\\\":0,\\\"input\\\":\\\"a9059cbb000000000000000000000000a5818edcbee321f479f8143ecddc28ccebf1c99d0000000000000000000000000000000000000000000000000000000000000014\\\",\\\"output\\\":\\\"0000000000000000000000000000000000000000000000000000000000000001\\\",\\\"recipient\\\":\\\"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603\\\",\\\"sender\\\":\\\"6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\\\",\\\"transfer\\\":0,\\\"version\\\":0,\\\"virtualMachine\\\":0}}\"}",
}
}

Return:

{
"id": "1",
"jsonrpc": "2.0",
"method": "GetCallContractTransaction",
"result": {
"code": 0,
"txhash": "0x9486c7cb49e22726b5fbbcaac4f4842e020bc3357feeed3037c23e1fc88c8715",
"message": "success",

}
}

Others

The contract calling interface can also perform operations such as mint, approve, querying name/symbol/total supply, etc., which need to be called according to the methods defined in the contract.

When it comes to uplink operations, TTOS needs to be consumed. Unless it is necessary to transfer operations, istochain should be set to false.