Options
All
  • Public
  • Public/Protected
  • All
Menu

 

The JavaScript SDK for Terra


diagram

API Docs | NPM Package | GitHub

Installation

Grab the latest version off NPM:

yarn add @terra-money/terra.js

Features

  • Written in TypeScript, includes type definitions for core data objects
  • Cosmos SDK compatible Int and Dec numeric types
  • Includes BIP39 mnemonic key, with support for custom key types
  • Interoperable: Supports JSON-format Terra objects and native JavaScript objects
  • Simple and consistent API for converting to/from blockchain data
  • Works in both Node.js and in the browser

Usage

We highly suggest using Terra.js with TypeScript, or JavaScript in a code editor that has support for type declarations, so you can take advantage of the helpful type hints that are included with the package. Terra.js can be use in Node.js, as well as inside the browser. Currently, React Native is not fully supported, however a version of Terra.js that supports it will soon be made available.

Example

The best way to learn how to use Terra.js is to get started with a quick example and then explore the documentation on your own. Let's create our first transaction by generating a mnemonic, acquiring some testnet tokens, signing a simple transaction, and broadcast it on the network by using just our browser.

You can play with the complete example on JSFiddle here.

Loading Terra.js in the browser

You can access all the objects of the @terra-money/terra.js from the global Terra object if you load Terra.js with a <script> tag.

Include the following in your browser:

<script
  crossorigin
  src="https://unpkg.com/@terra-money/terra.js/dist/bundle.js"
></script>

You can find a small JSFiddle example that refreshes current Oracle votes here.

License

This software is licensed under the MIT license. See LICENSE for full disclosure.

© 2020 Terraform Labs, PTE.


 

Powering the innovation of money.

Index

Namespaces

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

AccAddress

AccAddress: string

terra- prefixed account address

AccPubKey

AccPubKey: string

terrapub- prefixed account public key

BasePool

BasePool: Type<"market", "basepool", Dec>

BaseProposerReward

BaseProposerReward: Type<"distribution", "baseproposerreward", Dec>

BondDenom

BondDenom: Type<"staking", "BondDenom", Denom>

BonusProposerReward

BonusProposerReward: Type<"distribution", "bonusproposerreward", Dec>

CommunityTax

CommunityTax: Type<"distribution", "communitytax", Dec>

DepositParamsParamChange

DepositParamsParamChange: Type<"gov", "depositparams", DepositParams>

DowntimeJailDuration

DowntimeJailDuration: Type<"slashing", "DowntimeJailDuration", number>

IlliquidTobinTaxList

IlliquidTobinTaxList: Type<"market", "illiquidtobintaxlist", TaxRate[]>

MaxEntries

MaxEntries: Type<"staking", "KeyMaxEntries", number>

MaxEvidenceAge

MaxEvidenceAge: Type<"slashing", "MaxEvidenceAge", number>

MaxValidators

MaxValidators: Type<"staking", "MaxValidators", number>

MinSignedPerWindow

MinSignedPerWindow: Type<"slashing", "MinSignedPerWindow", Dec>

MinSpread

MinSpread: Type<"market", "minspread", Dec>

MinValidPerWindow

MinValidPerWindow: Type<"oracle", "minvalidperwindow", Dec>

MiningIncrement

MiningIncrement: Type<"treasury", "miningincrement", Dec>

PoolRecoveryPeriod

PoolRecoveryPeriod: Type<"market", "poolrecoveryperiod", number>

RewardBand

RewardBand: Type<"oracle", "rewardband", Dec>

RewardDistributionWindow

RewardDistributionWindow: Type<"oracle", "rewarddistributionwindow", number>

RewardPolicy

RewardPolicy: Type<"treasury", "rewardpolicy", PolicyConstraints>

SeigniorageBurdenTarget

SeigniorageBurdenTarget: Type<"treasury", "seigniorageburdentarget", Dec>

SignedBlocksWindow

SignedBlocksWindow: Type<"slashing", "SignedBlocksWindow", number>

SlashFraction

SlashFraction: Type<"oracle", "slashfraction", Dec>

SlashFractionDoubleSign

SlashFractionDoubleSign: Type<"slashing", "SlashFractionDoubleSign", Dec>

SlashFractionDowntime

SlashFractionDowntime: Type<"slashing", "SlashFractionDowntime", Dec>

SlashWindow

SlashWindow: Type<"oracle", "slashwindow", number>

TallyParamsParamChange

TallyParamsParamChange: Type<"gov", "tallyparams", TallyParams>

TaxPolicy

TaxPolicy: Type<"treasury", "taxpolicy", PolicyConstraints>

UnbondingTime

UnbondingTime: Type<"staking", "UnbondingTime", number>

ValAddress

ValAddress: string

terravaloper- prefixed validator operator address

ValConsAddress

ValConsAddress: string

terravalcons- prefixed validator consensus address

ValConsPubKey

ValConsPubKey: string

terravalconspub- prefixed validator consensus public key

ValPubKey

ValPubKey: string

terravaloperpub- prefixed validator public key

VotePeriod

VotePeriod: Type<"oracle", "voteperiod", number>

VoteThreshold

VoteThreshold: Type<"oracle", "votethreshold", Dec>

VotingParamsParamChange

VotingParamsParamChange: Type<"gov", "votingparams", VotingParams>

Whitelist

Whitelist: Type<"oracle", "whitelist", Denom[]>

WindowLong

WindowLong: Type<"treasury", "windowlong", number>

WindowProbation

WindowProbation: Type<"treasury", "windowprobation", number>

WindowShort

WindowShort: Type<"treasury", "windowshort", number>

WithdrawAddrEnabled

WithdrawAddrEnabled: Type<"distribution", "withdrawaddrenabled", boolean>

Variables

Const BECH32_PUBKEY_DATA_PREFIX

BECH32_PUBKEY_DATA_PREFIX: "eb5ae98721" = "eb5ae98721"

Const DEC_PRECISION

DEC_PRECISION: 18 = 18

Const LUNA_COIN_TYPE

LUNA_COIN_TYPE: 330 = 330

Const _Dec

_Dec: Decimal = Decimal.clone()

Const _Int

_Int: Decimal = Decimal.clone()

Functions

addressFromPublicKey

  • addressFromPublicKey(publicKey: Buffer): Buffer
  • Gets a raw address from a compressed bytes public key.

    Parameters

    • publicKey: Buffer

      raw public key

    Returns Buffer

byteArrayToWordArray

  • byteArrayToWordArray(ba: Uint8Array): LibWordArray

hashAmino

  • hashAmino(txData: string): string
  • Calculates the transaction hash from Amino-encoded string.

    Parameters

    • txData: string

      Amino-encoded string (base64)

    Returns string

prepareSignBytes

  • prepareSignBytes(obj: any): any

pubKeyFromPublicKey

  • pubKeyFromPublicKey(publicKey: Buffer): Buffer
  • Gets a bech32-words pubkey from a compressed bytes public key.

    Parameters

    • publicKey: Buffer

      raw public key

    Returns Buffer

voteHash

  • voteHash(exchangeRate: string, denom: Denom, salt: string, validator: ValAddress): string

Object literals

Const DEFAULT_LCD_OPTIONS

DEFAULT_LCD_OPTIONS: object

gasAdjustment

gasAdjustment: number = 1.4

gasPrices

gasPrices: object

uluna

uluna: number = 0.015

Const DEFAULT_OPTIONS

DEFAULT_OPTIONS: object

account

account: number = 0

coinType

coinType: number = LUNA_COIN_TYPE

index

index: number = 0

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Static property
  • Static method
  • Property

Generated using TypeDoc