Models - Noixion-NXN/Tron-Client-Library GitHub Wiki
Nodes
The library uses the nodes of the Tron network to connect, retrieve information and perform actions using the GRPC protocol.
The class TronNode
excapsulates a node address as the combination of its host and port.
TronNode node = new TronNode("node_ip:port");
View javadoc: TronNode
TronCurrency
Tron currency is commonly expressed as TRX, but 1 TRX = 1000000 SUN. To make this conversion, the library uses the class Troncurrency
TronCurrency amount1 = TronCurrency.trx(100); // 100 TRX
TronCurrency amount2 = TronCurrency.sun(100000000); // 100,000,000 SUN
amount1.getTRX() == ampount2.getTRX();
amount1.getSUN() == amount2.getSUN();
View javadoc: TronCurrency
Identifiers
Transactions and blocks have hexadecimal identifiers. The library uses the class HashIdentifier
to encapsulate them.
// Identifier from Hex string
HashIdentifier id1 = new HashIdentifier("9a4fd83d2e7cf0fc68b85f3f62b28fe126db6c7660862302180421538c89778");
// Identifier from byte array
byte[] bytes = {0x00, ...};
HashIdentifier id2 = new HashIdentifier(bytes);
View javadoc: HashIdentifier
Adresses
Tron addresses start with 41 in hexadecimal and is expressed commonly as Base-58 check format. The library uses the class TronAddress
to encapsulate them.
// Address from string
TronAddress addr = new TronAddress("TFA1qpUkQ1yBDw4pgZKx25wEZAqkjGoZo1");
// Address from byte array
byte[] bytes = {0x00, ...};
TronAddress addr2 = new TronAddress(bytes);
View javadoc: TronAddress
Wallets
Wallets are encrypted private keys. the library uses TronWallet
to encapsulate them. They are required to perfrom transactions.
// Create a new wallet
TronWallet wallet1 = new TronWallet();
// Write the wallet to a file.
wallet1.writeToFile(new File("my_wallet.json"), "my_password");
// Load a wallet from a file
TronWallet wallet2 = new TronWallet(new File("my_wallet.json"), "my_password");
// Extract private key
TronPrivateKey key = wallet2.getPrivateKey();
// Create a new wallet from a private key
TronWallet wallet3 = new TronWallet(key);
View javadoc: TronPrivateKey, TronWallet