LTO Network
  • Getting started
  • What is LTO Network?
  • Tutorials
    • Buying and staking LTO
      • Exchanges
        • Binance
        • AscendEX (Bitmax)
        • Uniswap
        • PancakeSwap
        • Other exchanges
      • Creating your LTO web wallet
      • Using the LTO token bridge
      • Staking LTO tokens
    • Mining
      • Setup your node wallets
      • Node management
      • Public community nodes
    • Anchoring
      • Hashing
    • LetsFlow
  • Wallets
    • LTO Web Wallet
      • Using Ledger
    • Universal Wallet
    • LTO CLI
    • Third-Party Wallets
      • Stakely.io wallet
        • Web wallet
        • Commandline
    • ERC20 Token Swap
  • Running a node
    • Public node
      • Installation Guide
        • Mainnet & Testnet
        • Requirements
        • Configuration
        • (Virtual) Machine
        • Nginx reverse proxy (optional)
        • Troubleshooting FAQ
      • Cloud installation
        • Alibaba Cloud
        • AWS Elastic Beanstalk
        • Google Cloud
        • IBM Cloud
        • Microsoft Azure
        • OKD (OpenShift)
        • Raspberry Pi (Expert)
        • Ubuntu Linux with Container
        • Windows with Container
      • REST API
        • Address
        • Wallet
        • Lease Transactions
        • Peers
        • Blocks
        • Utils
        • FAQ
      • Security Notes
      • FAQ
      • Exchange integration guide
    • Anchor node
      • Installation Guide
        • Linux
        • MacOS
        • Windows
      • REST API
    • Identity node
      • Installation guide
        • Linux
        • MacOs
        • Windows
      • Configuration
        • Trust network
      • REST API
    • Workflow node
      • Installation Guide
        • MacOS
        • Windows
        • Ubuntu Linux
      • REST API
  • Ownables
    • What are Ownables?
    • Making your first ownable
    • Ownables SDK
      • Prerequisites
      • Setup
    • Ownables Architecture
      • Smart Contract
      • Widget
    • Ownables Bridge
  • Templates Overview
  • Libraries
    • JavaScript
      • Accounts
      • Transactions
      • Event chain
      • Messages
      • Identities
      • HTTP Authentication
    • Python
      • Accounts
      • Public layer
    • PHP
      • Accounts
      • Identities
      • Public layer
      • Private layer
      • HTTP Authentication
      • Commandline scripts
    • Java
  • Protocol
    • Cryptography
    • Accounts
      • ED25519
      • secp256k1
      • secp256r1
    • Identities
      • Decentralized identifiers (DID)
      • Trust network
      • Verifiable credentials
    • Public layer
      • Transactions
        • Transfer
        • Lease
        • Cancel Lease
        • Mass Transfer
        • Set Script
        • Data
        • Anchor
        • Association
        • Revoke Association
        • Sponsorship
        • Cancel Sponsorship
        • Register
        • Burn
        • Mapped Anchor
        • Statement
      • Transaction fees
      • Consensus protocol
      • Activation Protocol
      • Data Structures
    • Private layer
      • Event chain
        • Event
      • Messaging
        • Sending messages
Powered by GitBook
On this page
  • Basic usage
  • Executing Transactions
  • Create transaction
  • Sign transaction
  • Broadcasting transaction
  • Fluent interface
  • Sponsoring transactions
  • Transaction types
  • Transfer transaction
  • Mass Transfer transaction
  • Anchor transaction
  • Mapped Anchor transaction
  • Lease transaction
  • Cancel Lease transaction
  • SetScript transaction
  • Sponsorship transaction
  • Cancel Sponsorship transaction
  • Association transaction
  • Revoke Association transaction
  • Statement transaction
  • Data transaction
  • Public Node
  1. Libraries
  2. JavaScript

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);

Amounts are in LTO * 10^8. Eg: 12.46 LTO is1246000000, which may be written as 12_46000000 in JavaScript.

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

import { Transfer } from '@ltonetwork/lto/transactions';

const transaction = new Transfer(recipient, amount);

Sign transaction

The Transaction needs then to be signed. In order to sign a transaction an account is needed.

account.sign(transaction);

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.

const broadcastedTx = await lto.node.broadcast(transaction);

Fluent interface

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.

PreviousAccountsNextEvent chain

Last updated 1 year ago