Transactions
Send transactions on the public layer
Basic usage
import LTO, { Binary } from '@ltonetwork/lto';
enum RELATIONSHIP { MEMBER_OF=0x3400 };
enum STATEMENT { VERIFIED=0x3500 };
lto = new LTO('T');
const account = lto.account();
const recipient = '3N2XoMuukk4BPiLn95vDkv4ocU5szMXuxVN';
lto.getBalance(account);
lto.transfer(account, recipient, 100_00000000);
lto.massTransfer(account, [{recipient: recipient1, amount: 100_00000000}, {recipient: recipient2, amount: 50_00000000}]);
lto.anchor(account, new Binary('some value').hash(), new Binary('other value').hash());
lto.anchor(
account,
{ key: new Binary('some key').hash(), value: new Binary('some value').hash() },
{ key: new Binary('other key').hash(), value: new Binary('other value').hash() },
);
lto.associate(account, RELATIONSHIP.MEMBER_OF, recipient);
lto.revokeAssociation(account, RELATIONSHIP.MEMBER_OF, recipient);
lto.lease(account, recipient, 10000_00000000);
lto.cancelLease(account, '9V7tdKEEJiH86eCPNxPg1vxhmp8oNH6Mqtf1fQeSeS4U');
lto.sponsor(account, recipient);
lto.cancelSponsorship(account, recipient);
lto.makeStatement(account, STATEMENT.VERIFIED, recipient);
lto.setData(account, {foo: 'bar'});
lto.getData(account);Executing Transactions
The LTO class provides a simple way for doing transactions. Alternatively, you can create a transaction object, sign it, and broadcast it.
Create transaction
Sign transaction
The Transaction needs then to be signed. In order to sign a transaction an account is needed.
Broadcasting transaction
For last the transaction needs to be broadcasted to the node. In order to do so we need to connect to the node using the PublicNode class.
Fluent interface
Transaction classes have convenience methods, providing a fluent interface
Sponsoring transactions
A second account can offer to pay for the transaction fees by co-signing the transaction.
Alternatively, you can set the parent property of an account to automatically have the parent sponsor all transactions of the child.
Transaction types
Transfer transaction
Mass Transfer transaction
Anchor transaction
Mapped Anchor transaction
Lease transaction
Cancel Lease transaction
SetScript transaction
Create a SetScript transaction using the compile method of the public node.
Clear a script by using null as compiled script.
Sponsorship transaction
Cancel Sponsorship transaction
Association transaction
Revoke Association transaction
Statement transaction
Data transaction
Public Node
By default, the following public nodes are used
Mainnet - https://nodes.lto.network
Testnet - https://testnet.lto.network
To use your own public node, set the node address of the LTO object.
The lto.node object will automatically be replaced when the node address is changed.
Last updated