Skip to main content

JSON RPC API

Covenant

1. Obtain parameters: Before starting a transaction, you need to obtain certain necessary parameters for the transaction (such as utxo, transaction hash, etc.) through the specified protocol.

2. Fill in the protocol: Then fill in the protocol with the corresponding parameters, form the protocol into json and then send it to the sending node.

3. Node processing: The node generates a transaction, and then the transaction body will be returned through the interface.

4. Transaction signature: After receiving the transaction body returned by the node, the user will sign the transaction with the content to be returned through the interface provided in librpc.dll/librpc.so.

5. Transaction on-chain: At this time, the transaction has been generated, and then broadcast through the send transaction interface, and then the result of whether the transaction is successful is returned through interface.

Example:

void transaction(long long pkey){
std::string data=R"delimiter(
{
"tfsrpc":"0.0.1",
"method":"transaction",
"params":["0x8199787886e29346a9f1206494cb8bD3C0b008Cf","0x9efA1DA5ceAaa3680415279373CEc97f98D0A935","1.0"]
}
)delimiter";
debugL(data);
httplib::Headers headers = {
{ "content-type", "application/json" }
};

httplib::Client cli("192.168.1.141", 20260);
httplib::Result res = cli.Post("/tfscrpc", headers,data, "application/json");

if(res.error()!=httplib::Error::Success){
debugL("error:%s",(int)res.error());
return ;
}

//debugL(res.value().body);
nlohmann::json jbody=nlohmann::json::parse(res.value().body);

tx_ack ack;
std::string ackString=jbody["body"];
debugL(ackString);

char *tx_body=sig_tx((long long)pkey,ackString.c_str(),ackString.size());
std::string tx_t(tx_body);
free(tx_body);

std::string _string_tx_obdy=R"delimiter(
{
"tfsrpc":"0.0.1",
"method":"sendtransation",
"params":[]
}
)delimiter";

nlohmann::json tx_body_json=nlohmann::json::parse(_string_tx_obdy);
nlohmann::json feildbody;
feildbody.push_back(tx_t);
tx_body_json["params"]=feildbody;
auto retv= cli.Post("/tfscrpc",headers,tx_body_json.dump(),"application/json");

if(retv.error()!=httplib::Error::Success){
errorL(Sutil::Format("httplib error:%s", (int)retv.error()));
return ;
}
debugL(retv.value().body);
return ;
}

RPC Version

  • Returns the current RPC version

Parameters:
  None
Returned value:
  json structure


transaction

  • Create a normal transaction:

Parameter:
  fromaddr, toaddr,Amount of the transaction
Returned value:
  transaction body
  For details on the transaction structure, please see below example


Example

Post
{
"tfsrpc":"0.0.1",
"method":"transaction",
"params":["base58","base58","value"]
}

{
"tfsrpc":"0.0.1",
"body":"",
"message":"",
"error":""
}

Stake

  • Create a stake transaction

Parameter:
  addr,staking amount
Returned value:
  transaction body


Example:

{
"tfsrpc":"0.0.1",
"method":"unstake",
"params":["base58","utxohash"]
}
{
"tfsrpc":"0.0.1",
"body":"",
"message":"",
"error":""
}

Unstake

  • Create an unstaking transaction

Parameter:
  addr,utxohash
Returned value:
  transaction body


Invest

  • Create Investment Transactions

Parameter:
  addr,toaddr,Invest amount
Returned value:
  transaction body


Example:

{
"tfsrpc":"0.0.1",
"method":"invset",
"params":["base58","base58","value"]
}
{
"tfsrpc":"0.0.1",
"body":"",
"message":"",
"error":""
}

Disinvest

  • Create an investment transaction

Parameter:
  fromaddr,toaddr,invested utxo
Returned value:
  Trading entity


Example:

{
"tfsrpc":"0.0.1",
"method":"unstake",
"params":["base58","utxohash"]
}
{
"tfsrpc":"0.0.1",
"body":"",
"message":"",
"error":""
}

Bonus

  • Create a get bonus transaction

Parameter:
  addr
Returned value:
  transaction body


Example:

{
"tfsrpc":"0.0.1",
"method":"bonus",
"params":["base58"]

}
{
"tfsrpc":"0.0.1",
"body":"",
"message":"",
"error":""
}

Deploy contract

  • Create deployment contract transactions

Parameter:
  addr,Contract type, contract information, contract, data, public key base64
Returned value:
  transaction body


Example:

{
"tfsrpc":"0.0.1",
"method":"deploycontract",
"params":["base58","contracttype",{},"contract","data","pubstrbase64"]
}
{
"tfsrpc":"0.0.1",
"body":"",
"message":"",
"error":""
}

Call contract

  • Create Execution Contract

Parameters:
 Addr, contract deployer, utxohash of the contract, parameters, deployer public key base64, tip, transfer money to the contract
Returned value:
  transaction body


Example:

{
"tfsrpc":"0.0.1",
"method":"callcontract",
"params":["base58","deployer","deployeutxo","args","pubstr","tip","money"]
}
{
"tfsrpc":"0.0.1",
"body":"",
"message":"",
"error":""
}

height

  • Get block height

Parameters:
  Nothing
Return value:
  Block height


Example:

 {
"tfsrpc":"0.0.1",
"method":"height",
"params":[]
},
{
"height":"",
"message":"",
"error":""
}

getstakeutxo

  • Get staked utxo

Parameters:
  Addr
Returned value:
  Staked utxo


Example:

{
"tfsrpc":"0.0.1",
"method":"getstakeutxo",
"params":["base58"]
},
{
"utxos":[
{
"utxo":"",
"value":""
}
],
"message":"",
"error":""
}

getinvestutxo

  • Get investment utxo

Parameters:
 Addr, toaddr
Returned value:
 Invested utxo


Example:

{
"tfsrpc":"0.0.1",
"method":"getinvestutxo",
"params":["base58","base58"]
},
{
"utxos":[
{
"utxo":"",
"value":""
}
],
"message":"",
"error":""
}

getdeployutxo

  • Get utxo for deployment contract

Parameters:
 Addr
Returned value:
 Deploying utxo for contracts


Example:

{
"tfsrpc":"0.0.1",
"method":"getdeployutxo",
"params":["base58"]
}
{
"utxos":[],
"message":"",
"error":""
}

getbalance

  • Get balance

Parameters:
 Addr
Returned value:
 Balance


Example:

 {
"tfsrpc":"0.0.1",
"method":"getbalance",
"params":["base58"]
}
{
"balance":"",
"message":"",
"error":""
}

sendtransation

  • Broadcast transactions

Parameters:
 Trading entity

Return value:
 error message


{
"tfsrpc":"0.0.1",
"method":"sendtransation",
"params":["transation"]
},
{
"message":"",
"error":""
}