• Stars
    star
    264
  • Rank 155,103 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript SDK for Terra, written in TypeScript

Β 

The JavaScript SDK for Terra

diagram


GitHub npm (scoped)

Explore the Docs Β»

Examples Β· API Reference Β· NPM Package Β· GitHub

Terra.js is a JavaScript SDK for writing applications that interact with the Terra blockchain from either Node.js, browser, or React Native environments and provides simple abstractions over core data structures, serialization, key management, and API request generation.

Features

  • Written in TypeScript, with type definitions
  • Versatile support for key management solutions
  • Works in Node.js, in the browser, and React Native
  • Exposes the Terra API through LCDClient
  • Parses responses into native JavaScript types

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.

Installation

Grab the latest version off NPM:

npm install @terra-money/terra.js

Usage

Terra.js can be used in Node.js, as well as inside the browser. Please check the docs for notes on how to get up and running.

Getting blockchain data

❗ terra.js can connect both terra-classic and terra network. If you want to communicate with classic chain, you have to set isClassic as true.

import { LCDClient, Coin } from '@terra-money/terra.js';

// connect to pisco testnet
const terra = new LCDClient({
  URL: 'https://pisco-lcd.terra.dev',
  chainID: 'pisco-1',
  isClassic: false  // if it is unset, LCDClient assumes the flag is false.
});

// connect to columbus-5 terra classic network
const terra = new LCDClient({
  URL: 'https://columbus-lcd.terra.dev',
  chainID: 'columbus-5',
  isClassic: true  // *set to true to connect terra-classic chain*
});

// To use LocalTerra
// const terra = new LCDClient({
//   URL: 'http://localhost:1317',
//   chainID: 'localterra'
// });

// get the current balance of `terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v`
const balance = terra.bank.balance('terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v');
console.log(balance);

Broadcasting transactions

First, get some testnet tokens for terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v, or use LocalTerra.

import { LCDClient, MsgSend, MnemonicKey } from '@terra-money/terra.js';

// create a key out of a mnemonic
const mk = new MnemonicKey({
  mnemonic:
    'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius',
});

// connect to bombay testnet
const terra = new LCDClient({
  URL: 'https://pisco-lcd.terra.dev',
  chainID: 'pisco-1',
});

// To use LocalTerra
// const terra = new LCDClient({
//   URL: 'http://localhost:1317',
//   chainID: 'localterra'
// });

// a wallet can be created out of any key
// wallets abstract transaction building
const wallet = terra.wallet(mk);

// create a simple message that moves coin balances
const send = new MsgSend(
  'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
  'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp',
  { uluna: 1200000}
);

wallet
  .createAndSignTx({
    msgs: [send],
    memo: 'test from terra.js!',
  })
  .then(tx => terra.tx.broadcast(tx))
  .then(result => {
    console.log(`TX hash: ${result.txhash}`);
  });

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.

Terra.js in React Native

In order to use Terra.js inside React Native, you need to add the node-libs-react-native package and react-native-get-random-values package to your React Native app's package.json.

yarn add node-libs-react-native react-native-get-random-values

You will need to register Node.js native modules in an entry point of your application, such as index.tsx:

import 'node-libs-react-native/globals';
import 'react-native-get-random-values';

Also, add resolvers to your metro.config.js

module.exports {
  // ...
  resolver: {
    // ...
    extraNodeModules: require('node-libs-react-native'),
  },
  // ...
}

License

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

Β© 2020 Terraform Labs, PTE.


Β 

More Repositories

1

classic-core

GO implementation of the Terra Protocol
JavaScript
986
star
2

core

GO implementation of the Terra Protocol
JavaScript
357
star
3

LocalTerra

One-click local Terra testnet and ecosystem for rapid prototyping
Dockerfile
177
star
4

terra.py

Python SDK for Terra
Python
136
star
5

docs

πŸ—‚ The official documentation for the Terra blockchain
SCSS
112
star
6

station

πŸ›°οΈ Station wallet
TypeScript
93
star
7

wallet-provider

Library to make React dApps easier using Terra Station Extension or Terra Station Mobile.
TypeScript
89
star
8

shuttle

TypeScript
85
star
9

bridge-web-app

πŸͺ Terra Bridge web app
TypeScript
82
star
10

validator-profiles

Profiles for Validators of the Terra Blockchain
Jinja
81
star
11

station-legacy

Web Application to interact with Terra Core
TypeScript
67
star
12

mantlemint

Go
65
star
13

fcd-classic

Terra ETL + RestFul API Server
HTML
62
star
14

assets

JavaScript
57
star
15

cosmwasm-contracts

Rust
51
star
16

finder

The Terra Finder is a tool to search through blocks, transactions, and accounts on the Terra blockchain.
TypeScript
50
star
17

oracle-feeder

Oracle Feeder Daemon
TypeScript
49
star
18

terra-cosmwasm

Terra bindings for CosmWasm
Rust
49
star
19

alliance

🀝 Alliance chain with x/alliance module
Go
49
star
20

terrain

πŸ›  A Terra development environment for seamless smart contract development
TypeScript
46
star
21

research

Models and simulations
Python
44
star
22

classic-testnet

Configuration files for Terra testnet releases
Python
44
star
23

station-mobile

πŸ›°οΈ Station wallet mobile
TypeScript
34
star
24

faucet

Faucet to get free coins for the Terra testnet
Go
34
star
25

station-extension

πŸ›°οΈ Station Chrome and Firefox extension
TypeScript
33
star
26

station-desktop

JavaScript
27
star
27

houston

A development environment, testing framework and smart contract pipeline for Terra, aiming to make life as a Terra developer easier.
TypeScript
27
star
28

terraswap-graph

Terraswap Indexer + GraphQL
TypeScript
25
star
29

mantle-sdk

All type definition of Terra, database scheme, and extract scripts
Go
25
star
30

my-terra-token

Simple CosmWasm smart contract on Terra
Rust
21
star
31

documentation

White paper & protocol specifications
TeX
20
star
32

terra.go

Go library for terra blockchain
Go
19
star
33

hive-graph

GraphQL interface for Terra blockchain
TypeScript
17
star
34

mantle

Go
16
star
35

warp-contracts

Rust
15
star
36

jigu

The Python SDK for Terra.
Python
14
star
37

genesis-tools

Genesis Build Script for Terra 2.0
Python
10
star
38

enterprise-contracts

Rust
10
star
39

tefi-oracle-contracts

Oracle SmartContracts for TeFi projects
Rust
10
star
40

smart-contract-webapp-template

This is a basic template for developing smart contract and web app together. This template is based on cw-template of CosmWasm.
TypeScript
10
star
41

react-native-mnemonic-key

Performant replacement for MnemonicKey for React Native
Swift
9
star
42

use-station

TypeScript
8
star
43

warp-sdk

TypeScript
8
star
44

station-assets

πŸ›°οΈ Assets for Station
JavaScript
8
star
45

feather.js

πŸ’» JavaScript SDK for Station, written in TypeScript
TypeScript
8
star
46

terrain-frontend-template

Frontend template for developing frontends on Terra
TypeScript
7
star
47

terra.proto

proto generator env for multiple languages
TypeScript
7
star
48

wallet-kit

new version of wallet-provider
TypeScript
7
star
49

enterprise-app

TypeScript
7
star
50

feather-core

Templates for feather chain scaffolding
Go
7
star
51

bridge-sdk

Javascript Terra Bridge SDK
TypeScript
7
star
52

terra.kt

Kotlin, Java SDK for Terra
Kotlin
6
star
53

warp-web-app

TypeScript
6
star
54

terra-wallet-java

Native Terra wallet library for Android
Java
6
star
55

testnet

Testnet Infos of Terra 2.0
6
star
56

api-public

API for some Station features
TypeScript
5
star
57

fcd

HTML
5
star
58

terrain-desktop

TypeScript
4
star
59

libp2p-episub

Episub: Proximity Aware Epidemic PubSub for libp2p
Rust
4
star
60

core-genesis-exporter

temp
JavaScript
4
star
61

delegations

[WIP] Hub for managing Terraform Labs delegations
4
star
62

deposit-tracker

Track deposit transactions of an address
TypeScript
4
star
63

mainnet

3
star
64

warp-docs

The official Warp documentation.
JavaScript
3
star
65

classic-docs

CSS
3
star
66

amino-js

TypeScript
3
star
67

TIPs

Terra Improvement Proposals (TIPs) main repository
3
star
68

oracle-feeder-go

Oracle Feeder Daemon
Go
3
star
69

terrain-core-template

Core template for @terra-money/terrain to instantiate projects
TypeScript
3
star
70

level-to-rocks

LevelDB to RocksDB converter
Go
3
star
71

enterprise-sdk

TypeScript
2
star
72

cra-react18-wallet-provider-template

TypeScript
2
star
73

react-base-components

TypeScript
2
star
74

bounties

2
star
75

mantle-compatibility

bells and whistles required for mantle to operate with different versions of cosmos/tendermint
Go
2
star
76

alliance-estimator

TypeScript
2
star
77

alliance-docs

SCSS
2
star
78

msg-reader

JavaScript
2
star
79

santa

Santa subsidizes block rewards on Columbus!
Go
2
star
80

ledger-station-js

TypeScript
2
star
81

terra-web-extensions

Next Browser extensions (In development)
TypeScript
2
star
82

validator-images

JavaScript
2
star
83

key-utils

TypeScript
2
star
84

nostr-bindings

Smart contract to bind terra <-> nostr keys
Rust
2
star
85

new-docs

New docs site
JavaScript
2
star
86

synthetic-assets

TypeScript
2
star
87

station-docs

SCSS
2
star
88

terra-tutorials

A collection of example code used for tutorials
2
star
89

templates

Terra app template registry
1
star
90

alliance-nft-collection

Code to create a collection to reward participants for the Game Of Alliance
TypeScript
1
star
91

log-finder-ruleset

TypeScript
1
star
92

templates.terra.money

TypeScript
1
star
93

terrariums

TypeScript
1
star
94

screening-test-backend

1
star
95

gitcoin-onboarding

1
star
96

cosmwasm-cache-rebuilder

Simple runtime dedicated for rebuilding cosmwasm cache
Rust
1
star
97

ics-proxy

Rust
1
star
98

terra-wallet-ios

Native Terra wallet library for iOS
Swift
1
star
99

alliance-landing

Landing page for the Alliance an open-source Cosmos SDK module.
TypeScript
1
star
100

amino-decoder

rest server for amino decoding
Go
1
star