Transaction classes have convenience methods, providing a fluent interface
import { Transfer } from '@ltonetwork/lto/transactions';
const tx = await new Transfer(recipient, amount)
.signWith(account)
.broadcastTo(lto.node);
Sponsoring transactions
A second account can offer to pay for the transaction fees by co-signing the transaction.
import { Anchor } from '@ltonetwork/lto/transactions';
const tx = await new Anchor(new Binary('foo').hash())
.signWith(someAccount)
.sponsorWith(mainAccount)
.broadcastTo(lto.node);
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
import { Transfer } from '@ltonetwork/lto/transactions';
const tx = new Transfer(recipient, amount, new Binary('attachment'))
Mass Transfer transaction
import { MassTransfer } from '@ltonetwork/lto/transactions';
const tx = new MassTransfer(
[
{recipient: recipient1, amount: amount1},
{recipient: recipient2, amount: amount2}
],
new Binary('attachment'),
);
Anchor transaction
import { Anchor } from '@ltonetwork/lto/transactions';
const hash1 = new Binary('hello').hash();
const hash2 = Binary.fromHex('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
const tx = new Anchor(hash1, hash2, ...);
Mapped Anchor transaction
import { MappedAnchor } from '@ltonetwork/lto/transactions';
const hashKey = new Binary('key').hash();
const hashValue = new Binary('value').hash();
const tx = new MappedAnchor({ key: hashKey, value: hashValue }, ...);
Lease transaction
import { Lease } from '@ltonetwork/lto/transactions';
const tx = new Lease(recipient, amount);
Cancel Lease transaction
import { CancelLease } from '@ltonetwork/lto/transactions';
const tx = new CancelLease(leaseId);
SetScript transaction
Create a SetScript transaction using the compile method of the public node.
const tx = lto.node.compile(script);
Clear a script by using null as compiled script.
import { SetScript } from '@ltonetwork/lto/transactions';
const tx = new SetScript(null);
Sponsorship transaction
import { SetScript } from '@ltonetwork/lto/transactions';
const tx = new Sponsorship(recipient);
Cancel Sponsorship transaction
import { CancelSponsorship } from '@ltonetwork/lto/transactions';
const tx = new CancelSponsorship(recipient);
Association transaction
import { Association } from '@ltonetwork/lto/transactions';
const tx = new Association(
association_type,
recipient,
new Binary('subject'),
expires,
data
);
Revoke Association transaction
import { RevokeAssociation } from '@ltonetwork/lto/transactions';
const tx = new RevokeAssociation(association_type, recipient, new Binary('subject'));
Statement transaction
import { Statement } from '@ltonetwork/lto/transactions';
const tx = new Statement(
statement_type,
recipient,
new Binary('subject'),
expires,
data
);
Data transaction
import { Data } from '@ltonetwork/lto/transactions';
const tx = new Data({
num: 100,
str: 'some string',
bin: new Binary('Hello').hash(),
bool: true,
});
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.
lto.nodeAddress = "http://localhost:6869";
The lto.node object will automatically be replaced when the node address is changed.