TTOS transaction related APIs
This chapter introduces how to achieve asset transfer, investment, withdrawal, pledge, cancellation of pledge on Transformers chain.
Preparation before trading
Prepare account
Before sending the transaction, make sure you already have the wallet address and corresponding private key file.
Please refer to the Account related function for details on account related content
Understand the transaction process
- Send transaction information to the corresponding interface in JSON format.
- Sign the transaction body after returning the transaction body information.
- After signing, send
SendMessage
to broadcast the transaction.
TTOS transaction
- Send transaction information to
/get_transaction_req
interface according to the following format:
{
"type":"tx_req",//protocol name
"fromAddr":["0x6298D7a621bF8C37E74a51c6b3E9c788975d9cF1"], // the initiator
"toAddr":[{//the receiver
"addr":"0xxxxxxxxxxxxxxx",//Receiver‘s address
"value":"2"//Amount to be transferred
}]
}
The "value" here is the actual transaction amount, and there is no need to convert the digits.
Return to content:
{
"ErrorCode": "0",
"ErrorMessage": "",
"gas": "20200",
"height": "222",
"time": "1716002681656132",
"txJson": "{\"time\":\"1716002681656132\",\"identity\":\"B2bEB45cfC5134E72C4a84fD8577fCD53600EC9a\",\"utxo\":{\"owner\":[\"6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\"],\"vin\":[{\"prevOut\":[{\"hash\":\"ef529759d9041ba53607e7377edf0792924d5cf3b5e730f5785d1f8a5effe0fa\"}]}],\"vout\":[{\"value\":\"200000000\",\"addr\":\"7058dC8425224D48A5Ff08946a1BDa6D7D1BA881\"},{\"value\":\"198099739081\",\"addr\":\"6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\"},{\"value\":\"20200\",\"addr\":\"VirtualBurnGas\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":1}",
"txType": "0",
"type": "",
"vrfJson": "{}"
}
- Sign the returned transaction information content using the SDK's
sig_tx
method
/*Sign transactions using a private key handle*/
char *sig_tx(long long pkey, const char *message, int msize);
- The signed content is sent to the entire network for broadcasting through the
SendMessage
interface.
The content after signing, as a parameter of SendMessage
{
"ErrorCode": "0",
"ErrorMessage": "",
"gas": "20200",
"height": "225",
"time": "1716010020707529",
"txJson": "{\"time\":\"1716010020707529\",\"identity\":\"0x8199787886e29346a9f1206494cb8bD3C0b008Cf\",\"utxo\":{\"owner\":[\"0x6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\"],\"vin\":[{\"prevOut\":[{\"hash\":\"e144683e5c2a088706b1e44d551826ca4bcf448f7b66117fbc21c184ba451110\"}],\"vinSign\":{\"sign\":\"HmK0MkZDgO7fn2GlDZb0RjNUZ0juIQjkT8PwXbc4rqvSIyLuU4tSmnKv/+tT+vl4RxSYteYguRAgogyg/2QUBQ==\",\"pub\":\"MCowBQYDK2VwAyEAuOmhl9PiwwviYtwW1ZVzl8e2LGC+4KA5fsQmJyt/XTo=\"}}],\"vout\":[{\"value\":\"200000000\",\"addr\":\"0x7058dC8425224D48A5Ff08946a1BDa6D7D1BA881\"},{\"value\":\"197899718881\",\"addr\":\"0x6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\"},{\"value\":\"20200\",\"addr\":\"VirtualBurnGas\"}],\"multiSign\":[{\"sign\":\"hNlK6/df3rKH5uNEphi6/QDVBDW4OAb/W1zwIUqMgbXLvX1o3avGsDtWAzfX3YzgnrQaKnhwMjQn5miqcTRbBg==\",\"pub\":\"MCowBQYDK2VwAyEAuOmhl9PiwwviYtwW1ZVzl8e2LGC+4KA5fsQmJyt/XTo=\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":1}",
"txType": "0",
"type": "",
"vrfJson": "{}"
}
After signing and before signing, there is a difference in the median content of the txJson parameter in the JSON format, which needs to be carefully observed.
Return to content:
{
"ErrorCode":"0",
"ErrorMessage":"",
"txhash":"0xe144683e5c2a088706b1e44d551826ca4bcf448f7b66117fbc21c184ba451110",
"type":""
}
ErrorCode
is "0" and the txhash
and height
values are returned, indicating that there is no problem with the transaction content.
- Save the
txhash
andheight
values to query whether the transaction is on the chain.
Staking transaction
The staking transaction process is similar to that of TTOS ordinary transactions, with only differences in the first step of transaction issuance.
Prerequisite
- Ensure that there is sufficient balance on the account before stake.
- Make sure that the account you stake is a validator account and validator is highly synchronized with the entire network.
- The minimum amount of validator stake is 1000 TTOS
- The freeze period is 30 days.
Transaction Process
- Send staking transaction information to
/get_stake_req
interface according to the following format:
{
"type":"get_stake_req",//protocol name
"fromAddr":"",//the initiator
"stake_amount":"1000",//staked amount
"PledgeType":"0"//PledgeType(default 0)
}
- Sign the returned staking transaction information content using the SDK's
sig_tx
method
/*Sign transactions using a private key handle*/
char *sig_tx(long long pkey, const char *message, int msize);
- The signed content is sent to the entire network for broadcasting through the
SendMessage
interface.
Unstake
Before Unstake, it is necessary to first query the stake transaction information and obtain utxo_hash
,utxo
value,etc.
Get staked utxo
- Query stake information content through
/get_stakeutxo_req
interface.
The parameter format is as follows:
{
"type":"get_stakeutxo_req",
"fromAddr":"" //The account that needs to be obtained
}
Return:
{
"type":"get_stakeutxo_ack",
"utxos":[{
"utxo":"",//Returned staked utxo
"value":""//Returned staked amount
}]
}
The value of the utxo
is used as the value of the parameter utxo_hash
Send unstake request
- Send unstake request through
/get_unstake_req
interface.
The parameter format is as follows:
{
"type":"get_unstake_req",
"fromAddr":"",//initiator of unstake transaction
"utxo_hash":""//The utxo that needs to be unstaked (this utxo is the staked utxo of the account returned by the get_stakeutxo_req interface)
}
- Sign the returned information content using the SDK's
sig_tx
method - The signed content is sent to the entire network for broadcasting through the
SendMessage
interface.
Investment
- Send investment request through
/get_invest_req
interface.
The parameter format is as follows:
{
"type":"get_invest_req",
"fromAddr":"",//Transaction initiator
"toAddr":"",//Investee
"invest_amount":"",//Invest amount
"investType":""//InvestType(default 0)
}
- Sign the returned information content using the SDK's
sig_tx
method - The signed content is sent to the entire network for broadcasting through the
SendMessage
interface.
Disinvestment
Before disinvestment, it is necessary to first query the investment information and obtain utxo_hash
,toAddr
value,etc.
Get invested utxo
The parameter format is as follows:
{
"type":"get_disinvestutxo_req",
"fromAddr":"",//The account that needs to be obtained
"toAddr":""//This account invests
}
Return:
{
"type":"get_disinvestutxo_ack",
"utxos":[""]//Returns the utxo invested in toAddr
}
Send disinvestment request
- Send disinvestment request through
/get_disinvest_req
interface.
The parameter format is as follows:
{
"type":"get_disinvest_req",
"fromAddr":"",//Solution to investment transaction initiator
"toAddr":"",//Investee
"utxo_hash":""//The utxo of the original investment transaction(This utxo is returned by get_disinvestutxo_req)
}
- Sign the returned information content using the SDK's
sig_tx
method - The signed content is sent to the entire network for broadcasting through the
SendMessage
interface.
Confirm Transaction
After the transaction is completed, confirm whether the transaction is on the chain through this interface.
- Send confirm request through
/confirm_transaction
interface.
The parameter format is as follows:
{
"type":"confirm_transaction",
"height":"",//Solution to investment transaction initiator
"txhash":"",//Investee
}
Return:
{
"ErrorCode":"0",
"ErrorMessage":"",
"percent":"1.000000",
"receivedsize":"46",
"sendsize":"54",
"tx":"{\"Consensus\":7,\"Type\":\"Tx\",\"identity\":\"0xB2bEB45cfC5134E72C4a84fD8577fCD53600EC9a\",\"time\":1716002681656132,\"txHash\":\"0xe144683e5c2a088706b1e44d551826ca4bcf448f7b66117fbc21c184ba451110\",\"txType\":1,\"utxo\":{\"multisign\":[{\"pub\":\"kkq7Gg9ZNWYnAnuBGqoj9BivXHg18tUuUF6AlJbJ+w5HLX/TUr4b5I2OBftjSq6UDbSoVlDofDgZ7vTvwK1HBQ==\",\"sign\":\"kkq7Gg9ZNWYnAnuBGqoj9BivXHg18tUuUF6AlJbJ+w5HLX/TUr4b5I2OBftjSq6UDbSoVlDofDgZ7vTvwK1HBQ==\"}],\"owner\":[\"0x6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\"],\"vin\":{\"prevout\":{\"hash\":[\"0xef529759d9041ba53607e7377edf0792924d5cf3b5e730f5785d1f8a5effe0fa\"]},\"vinsign\":[{\"pub\":\"MCowBQYDK2VwAyEAuOmhl9PiwwviYtwW1ZVzl8e2LGC+4KA5fsQmJyt/XTo=\",\"sign\":\"XcPmAvm1qFGWeY8NvO4DUsto1yYEn4xrlM81hd4e3Ujw0mW09QtpUHLkDJLSA0hYovSYjvuggnmpp+MJAFPODA==\"}]},\"vout\":[{\"addr\":\"0x7058dC8425224D48A5Ff08946a1BDa6D7D1BA881\",\"value\":200000000},{\"addr\":\"0x6298D7a621bF8C37E74a51c6b3E9c788975d9cF1\",\"value\":198099739081},{\"addr\":\"VirtualBurnGas\",\"value\":20200}]},\"verifySign\":[{\"pub\":\"MCowBQYDK2VwAyEAi4wKVbeYc4HAOtMLHJOTA/K2aEKWWdhttywUWEhppDM=\",\"sign\":\"i6idZaxAPBe4Wo1qnoliha2ugWV2unWj6Vs9A+WDyXx3a0uyuL6VEqmPIpmZCZk1d3YsRVUaEkvdIaxYM9FIBA==\",\"signaddr\":\"0xB2bEB45cfC5134E72C4a84fD8577fCD53600EC9a\"},{\"pub\":\"MCowBQYDK2VwAyEAB9skDcdflPUTS0Z/I8lchmh8lQt/VsVrYtgsK55/M6c=\",\"sign\":\"\",\"signaddr\":\"0xc8D39d9ADd191D89CEeEaDf9D7e1BD11168db692\"},{\"pub\":\"MCowBQYDK2VwAyEAakwLGVk3TwN2N+biAWKlS2h3mIgt5TcbBJLNrysyMEg=\",\"sign\":\"\",\"signaddr\":\"0xE9C0DBC50d52455D1168ee24EaCF0f1c7406546F\"},{\"pub\":\"MCowBQYDK2VwAyEAk9eu9p7BjsXsPRE3GNV7Q+QvdkWuEoAf2WmNLtDXSS4=\",\"sign\":\"\",\"signaddr\":\"0x4f0877c117Acd368e6785630d02fd32bFB2A4e2c\"},{\"pub\":\"MCowBQYDK2VwAyEAvZMHEwTjaxsIzVL1oZPM943Oor5xkn08c8gdkSMA7xE=\",\"sign\":\"\",\"signaddr\":\"0xBC1Ef29D64755d3F434A2249Da77011041F50539\"},{\"pub\":\"MCowBQYDK2VwAyEAwc3kvnDdn39A6+qXj+jd1ehM/4/y5k59sCC+RYFcd8g=\",\"sign\":\"\",\"signaddr\":\"0xA433AF879aC1f92Be4cA57C3517e4c2e11343dd3\"},{\"pub\":\"MCowBQYDK2VwAyEAXmvM9h9WqNrOw0f1hfFck0RLQcgmzpYYoYnS3iw5+iU=\",\"sign\":\"\",\"signaddr\":\"0xa90aF3B05B3aa42Bd53B46dAA5143a89FD000CdF\"},{\"pub\":\"MCowBQYDK2VwAyEASZRSogphZza0e2HW3RKuxxEUWYFUEUt7HcleBlzg73I=\",\"sign\":\"\",\"signaddr\":\"0xB34191301FbdcFdE7A66afD7391589a07a017600\"},{\"pub\":\"MCowBQYDK2VwAyEAiq7/Q117Ebzswos+85VzpIF3Wsjz0E+yTn52hb8cXiU=\",\"sign\":\"\",\"signaddr\":\"0x203E7cF4a95A84e68bE26D1A9F59032AeEaB2AA6\"},{\"pub\":\"MCowBQYDK2VwAyEA2es6l+RrhEuYbvIyCPN136uQWVIHjEH7Z9Yi9OXTlgA=\",\"sign\":\"\",\"signaddr\":\"0x77cd290745066F5D0e3cC29E9061F902EB378913\"},{\"pub\":\"MCowBQYDK2VwAyEAWf/+z5VEi8wcJCsi3n8JIZz2QKtfGjasEnEZ9b2dv6Q=\",\"sign\":\"\",\"signaddr\":\"0xC0CC2faC26a7E0aAE3CA6b5D1e143c297bCF5990\"},{\"pub\":\"MCowBQYDK2VwAyEA5rhi6IDicsufp4c9UOeT1fOHMWQileWTbGW7QYVDovw=\",\"sign\":\"\",\"signaddr\":\"0x200579F024457E2670b5ed3430cB2247Ea8C0837\"},{\"pub\":\"MCowBQYDK2VwAyEAk9YHlw0AByZA7Xej861jQ/cRT22fRgvmWZEYzBElHZo=\",\"sign\":\"\",\"signaddr\":\"0x4EA19C0a542283e2a7A25f02c709E1f039bDB1E3\"}]}",
"txhash":"0xe144683e5c2a088706b1e44d551826ca4bcf448f7b66117fbc21c184ba451110",
"type":""
}
Return the JSON type to determine whether the transaction is on the chain based on the percent
value.
When the percent
value is greater than 0.8, it can be concluded that the transaction has been on the chain.
Callback interface
After the transaction is completed, it is very unlikely to encounter a situation of transaction rollback. At this point, it is necessary to configure callback information to capture the rolled back block information.
-
Enable and set interface parameters for
config.json
.Modify parameter
http_callback
in config.json,The parameter has the following meanings:- ip: Callback IP address
- path: Callback Path
- port: Callback Port
- ip: Callback IP address
-
The node will add the following interfaces based on the content set above.
These interfaces are used for callback of transaction information
http://ip:port/path/add_block // Add block callback
http://ip:port/path/rollback_block // Rollback block callback
The content returned by the add_block
or rollback_block
interface is block information,so the callback data is json's block data.
Callback Example:
{
"blockdata": {
"0x9486c7cb49e22726b5fbbcaac4f4842e020bc3357feeed3037c23e1fc88c8715": {
"output": "0000000000000000000000000000000000000000000000000000000000000001",
"preHash": {
"0xf4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603": "0x1093122915e33857c377df82abefa3c00954c0d89935d9cdd60a01fd0066b016"
},
"log": [
{
"creator": "0xf4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603",
"data": "0000000000000000000000000000000000000000000000000000000000000014",
"topics": [
"ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0000000000000000000000006298d7a621bf8c37e74a51c6b3e9c788975d9cf1",
"000000000000000000000000a5818edcbee321f479f8143ecddc28ccebf1c99d"
]
}
],
"dependentCTx": [
"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603"
],
"storage": {
"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603_1969923b79d750ee12954b254446ef55c8a3f443d736b4378c9934266f6934b8": "f8978080808080808080b842b8406664346637326364643333323466366361393364633831646639316435356638386131663235333235336539363964343436636365643430663231393533303980b842b84036633231313535653264636461393735636665373564363338643732643435353161343033386334656363613037393637666263333463363165343130383331808080808080",
"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603_rootHash": "5fa5c49a6a46424be09a8620b58e0e4ae9fdfa3d1e05ff819f52ac36947ad662",
"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603_5fa5c49a6a46424be09a8620b58e0e4ae9fdfa3d1e05ff819f52ac36947ad662": "f90160b842b84064313663626466616437653964636135303361356633346565333666646432333635376334393137613731663337363938623236613737376666343435323635808080808080b842b84035623730306433626535663437646461313233396566376465393866626237393333353530616139613533623631313635316330613033393166643336346462b842b840313936393932336237396437353065653132393534623235343434366566353563386133663434336437333662343337386339393334323636663639333462388080b842b8403936643466646462616566396439343664306136343261336462616539376438306464346634323638366330393762626534646564663865376533643533303380b842b84033333864376136393065646435383361376464616435323731653966333031616438633132653739616261653030303336373962623066383237363538636534808080",
"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603_fd4f72cdd3324f6ca93dc81df91d55f88a1f253253e969d446cced40f2195309": "f886b8406537396138326337313165626563356261353638356533323964613937633533356139313163393732663636376362393561373933373335376366333938387ab842b84030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030313261303566316334",
"f4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603_6c21155e2dcda975cfe75d638d72d4551a4038c4ecca07967fbc34c61e410831": "f886b8403235333263303731623631646363643634643439616332396533616461623533643431663135356237653431663134656335343137363362316337376234347ab842b84030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303363"
},
"creation": {},
"destruction": {}
},
"dependentCTx": ""
},
"tx": [
{
"data": {
"TxInfo": {
"blockPrevRandao": 4279,
"output": "0000000000000000000000000000000000000000000000000000000000000001",
"virtualMachine": 0,
"input": "a9059cbb000000000000000000000000a5818edcbee321f479f8143ecddc28ccebf1c99d0000000000000000000000000000000000000000000000000000000000000014",
"transfer": 0,
"sender": "0x6298D7a621bF8C37E74a51c6b3E9c788975d9cF1",
"contractDeployer": "0xfE7EfC12a4803A655f3629d05AbbB5Cd57d5beeD",
"recipient": "0xf4C69F83A5DC57f1772124E6F7EAF9DBcEd2e603",
"donation": 0,
"blockTimestamp": 1716012240,
"version": 0
}
},
"from": [
"0x6298D7a621bF8C37E74a51c6b3E9c788975d9cF1"
],
"time": 1716012233085554,
"to": [
{
"pub": "0xVirtualCallContractBurnGas",
"value": 48119
},
{
"pub": "0x6298D7a621bF8C37E74a51c6b3E9c788975d9cF1",
"value": 197899479843
},
{
"pub": "0xVirtualBurnGas",
"value": 71400
}
],
"type": 8,
"hash": "0x9486c7cb49e22726b5fbbcaac4f4842e020bc3357feeed3037c23e1fc88c8715"
}
],
"time": 1716012235389455,
"hash": "0x01faeeb788a7c927a725dfc02d9b9c05920063ece30ef1b93dbcb1708efed09f",
"height": 228
}
The numbers corresponding to the Transaction type
value in the returned information represent:
- -1: Genesis block
- 0: Unknown
- 1: Ordinary transactions
- 2: Stake transaction
- 3: UnStake transaction
- 4: Investment transactions
- 5: Divestment transaction
- 6: Reserved
- 7: Deployment contract
- 8: Execute contract
- 9: Get bonus