Web
Download or compile the SDK and put it into your project.
1. Generate Seed
- Generate the seed and return the hexadecimal string of the seed
seedBase64 = api.export_new_seed();
2. Get private-key handle
- Pass in the seed, return the private key handle
privatePkey = api.import_prikey_handler_from_seed(seedBase64);
3. Get private key
- Pass in the private key handle and return the hexadecimal code of the private key.
hexprikey = api.export_new_prikey_to_hex(privatePkey);
4. Import private key
- Pass in the hexadecimal code of the private key and return the handle of the private key.
api.import_prikey_handler_from_hex(hexprikey);
5. Get address
- Pass in the handle of the private key and return the address of the private key's addr account.
addr = api.get_addr(privatePkey);
resultaddr = api.get_addr(hexresultHandler);
console.assert(addr == resultaddr, "fail to recover private key");
6. Release private key handle
- Release the private key handle
api.free_prikey_handler(hexresultHandler);
7. Get mnemonic
- Pass in the hexadecimal seed and return the seed mnemonic.
mnemonic = api.export_mnemonic_from_seed(seedBase64);
8. Mnemonic word recovery seed
- Pass in the seed mnemonic and return the hexadecimal seed.
mnemonicresultHandler = api.import_seed_from_mnemonic(mnemonic);
9. Get public key
- Pass in the private key handle, return the base64 encoding of the public key.
base64pubkey = api.get_pubstr_base64(privatePkey);
10. Send transaction
- The following are sample steps for sending TTOS transactions. Contract transactions detailed in Contract related APIs
Transactions parameter construction
- Call the http://IP:20620/GetTransaction interface to obtain transaction body information based on parameters
Parameter:
{
"id": "",
"jsonrpc": "",
"params": {
"fromAddr": [
"0xcED97dA085527Fe7e1772CA59Aa1e64A78143128"
],
"isFindUtxo": false,
"toAddr": [
{
"addr": "0x06BA76F46631d4F344d1344303895001F1E3Af29",
"value": "13.5"
}
],
"txInfo": ""
}
}
Sample Response:
{
"id": "",
"jsonrpc": "",
"method": "",
"result": {
"code": 0,
"gas": "20200",
"height": "600",
"message": "0",
"time": "1717148047269517",
"txJson": "{\"time\":\"1717148047269517\",\"identity\":\"2eb2F635320c3Dbf29eadD35E894c13EE3F20bd5\",\"utxo\":{\"owner\":[\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"],\"vin\":[{\"prevOut\":[{\"hash\":\"3f1342e96e426e2905021ad991787131ec70d31298646b1e80da9d912eeff274\"}]}],\"vout\":[{\"value\":\"1350000000\",\"addr\":\"06BA76F46631d4F344d1344303895001F1E3Af29\"},{\"value\":\"1982446992477\",\"addr\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"},{\"value\":\"20200\",\"addr\":\"VirtualBurnGas\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":1}",
"txType": "1",
"vrfJson": "{\"vrfdata\":{\"hash\":\"6cf89d80c98eecd9138caca4f55d7ad0fda2aed9d8e68dd4642543ae3ee056d6\"},\"Vrfsign\":{\"sign\":\"u5dNZ16Rd77B4nLd8gAcKTwz+GxeHH1HIlcGennGbPaKgIFXUkmFzS/EnVxRC4nmSfESAdWyMEmj4pKBhwuqAg==\",\"pub\":\"MCowBQYDK2VwAyEAcUcydwF7CSr9bjBiUbd3drV+WMd4yd8xFL7HWGA4FTw=\"}}"
}
}
Transaction ACK signature
- In the
result
structure of the return body, obtain thetxJson
field for signature.
In the signature method sign(), the message to be signed (txJson) and private key handle parameters are passed in, return the signed message.
txJson = ...;
message = txJson;
message_size = message.length;
signature = api.sign(message, message_size, privatePkey);
- Verify whether the signature is correct
Using the verif_by_public_str() method, input parameters the public key, original message, message after signing to verify your signature.- 0 for success,
- -1 for failure.
result = api.verif_by_public_str(base64pubkey, base64pubkey.length, message, message_size, signature, signature.length);
Broadcasting transactions
- Call the http://IP:20620/SendMessageas interface to broadcast transaction.
Place the signed information back into thetxJson
struct as a parameter for the sendMessage interface to broadcast the transaction.
The structure of the broadcast transaction body after signing
{
"id": "",
"jsonrpc": "",
"result": {
"code": "",
"gas": "20200",
"height": "600",
"message": "",
"time": "1717148047269517",
"txJson": "{\"time\":\"1717148047269517\",\"identity\":\"2eb2F635320c3Dbf29eadD35E894c13EE3F20bd5\",\"utxo\":{\"owner\":[\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"],\"vin\":[{\"prevOut\":[{\"hash\":\"3f1342e96e426e2905021ad991787131ec70d31298646b1e80da9d912eeff274\"}],\"vinSign\":{\"sign\":\"ApxL8NDgh9YYDuUXpdbsbVv0cEAr3HyXmr2TICkD4mfuDIZqVlZJNUmaPAKHCs5kkn7JnZx7r12+CpnnR4ZpAg==\",\"pub\":\"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=\"}}],\"vout\":[{\"value\":\"1350000000\",\"addr\":\"06BA76F46631d4F344d1344303895001F1E3Af29\"},{\"value\":\"1982446992477\",\"addr\":\"cED97dA085527Fe7e1772CA59Aa1e64A78143128\"},{\"value\":\"20200\",\"addr\":\"VirtualBurnGas\"}],\"multiSign\":[{\"sign\":\"WCoFsLKML69x1rSpQc7pwbnd+GMfZ0Ce3wTPg96Rdb1v7ezFw9KuEBXwvGecTz264pVZB6T8hzgJIx26GuKVAA==\",\"pub\":\"MCowBQYDK2VwAyEA89VSBQU7d4uL+jvqAKeCRbgYz2tzk/Rf8DNRhB0sLbg=\"}]},\"type\":\"Tx\",\"consensus\":7,\"txType\":1}",
"txType": "1",
"vrfJson": "{\"vrfdata\":{\"hash\":\"6cf89d80c98eecd9138caca4f55d7ad0fda2aed9d8e68dd4642543ae3ee056d6\"},\"Vrfsign\":{\"sign\":\"u5dNZ16Rd77B4nLd8gAcKTwz+GxeHH1HIlcGennGbPaKgIFXUkmFzS/EnVxRC4nmSfESAdWyMEmj4pKBhwuqAg==\",\"pub\":\"MCowBQYDK2VwAyEAcUcydwF7CSr9bjBiUbd3drV+WMd4yd8xFL7HWGA4FTw=\"}}"
}
}
Other
- Return the sdk version number.
version = api.get_version()