Installations
npm install @terra-money/terra.js
Developer
terra-money
Developer Guide
Module System
CommonJS
Min. Node Version
>=14
Typescript Support
No
Node Version
16.19.1
NPM Version
9.6.4
Statistics
262 Stars
550 Commits
153 Forks
33 Watching
18 Branches
38 Contributors
Updated on 09 Oct 2024
Languages
TypeScript (99.74%)
JavaScript (0.26%)
Total Downloads
Cumulative downloads
Total Downloads
3,085,336
Last day
16.1%
3,597
Compared to previous day
Last week
3.1%
19,902
Compared to previous week
Last month
2.6%
77,962
Compared to previous month
Last year
4.6%
943,916
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
14
Dev Dependencies
25
Â
The JavaScript SDK for Terra
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:
1npm 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
:exclamation: 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
.
1import { LCDClient, Coin } from '@terra-money/terra.js';
2
3// connect to pisco testnet
4const terra = new LCDClient({
5 URL: 'https://pisco-lcd.terra.dev',
6 chainID: 'pisco-1',
7 isClassic: false // if it is unset, LCDClient assumes the flag is false.
8});
9
10// connect to columbus-5 terra classic network
11const terra = new LCDClient({
12 URL: 'https://columbus-lcd.terra.dev',
13 chainID: 'columbus-5',
14 isClassic: true // *set to true to connect terra-classic chain*
15});
16
17// To use LocalTerra
18// const terra = new LCDClient({
19// URL: 'http://localhost:1317',
20// chainID: 'localterra'
21// });
22
23// get the current balance of `terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v`
24const balance = terra.bank.balance('terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v');
25console.log(balance);
Broadcasting transactions
First, get some testnet tokens for terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v
, or use LocalTerra.
1import { LCDClient, MsgSend, MnemonicKey } from '@terra-money/terra.js';
2
3// create a key out of a mnemonic
4const mk = new MnemonicKey({
5 mnemonic:
6 'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius',
7});
8
9// connect to bombay testnet
10const terra = new LCDClient({
11 URL: 'https://pisco-lcd.terra.dev',
12 chainID: 'pisco-1',
13});
14
15// To use LocalTerra
16// const terra = new LCDClient({
17// URL: 'http://localhost:1317',
18// chainID: 'localterra'
19// });
20
21// a wallet can be created out of any key
22// wallets abstract transaction building
23const wallet = terra.wallet(mk);
24
25// create a simple message that moves coin balances
26const send = new MsgSend(
27 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
28 'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp',
29 { uluna: 1200000}
30);
31
32wallet
33 .createAndSignTx({
34 msgs: [send],
35 memo: 'test from terra.js!',
36 })
37 .then(tx => terra.tx.broadcast(tx))
38 .then(result => {
39 console.log(`TX hash: ${result.txhash}`);
40 });
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:
1<script 2 crossorigin 3 src="https://unpkg.com/@terra-money/terra.js/dist/bundle.js" 4></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
.
1yarn 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
:
1import 'node-libs-react-native/globals'; 2import 'react-native-get-random-values';
Also, add resolvers to your metro.config.js
1module.exports { 2 // ... 3 resolver: { 4 // ... 5 extraNodeModules: require('node-libs-react-native'), 6 }, 7 // ... 8}
License
This software is licensed under the MIT license. See LICENSE for full disclosure.
© 2020 Terraform Labs, PTE.
Â
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 12/15 approved changesets -- score normalized to 8
Reason
binaries present in source code
Details
- Warn: binary detected: integration-tests/contract.wasm.7:1
- Warn: binary detected: integration-tests/contract.wasm.8:1
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/npm-publish.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/npm-publish.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/npm-publish.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/typedoc.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/typedoc.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/typedoc.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/typedoc.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/typedoc.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/terra-money/terra.js/typedoc.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/npm-publish.yml:15
- Info: 0 out of 7 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 2 out of 3 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1
- Warn: no topLevel permission defined: .github/workflows/typedoc.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 27 are checked with a SAST tool
Reason
19 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-h755-8qp9-cq85
- Warn: Project is vulnerable to: GHSA-584q-6j8j-r5pm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
3.6
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @terra-money/terra.js
@terra-money/wallet-types
This is a separate package because it is used for [`@terra-money/use-wallet`](https://www.npmjs.com/package/@terra-money/use-wallet), [`@terra-money/wallet-controller`](https://www.npmjs.com/package/@terra-money/wallet-controller), and [`@terra-money/wall
@terra-money/feather.js
TypeScript SDK for Terra and Cosmos chains
@anchor-protocol/anchor.js
Anchor.js is a client SDK for building applications that can interact with Anchor Protocol from within JavaScript runtimes, such as web browsers, server backends, and on mobile through React Native.
@terra-money/wallet-provider
Library to make React dApps easier using Terra Station Extension or Terra Station Mobile.