Gathering detailed insights and metrics for @terra-money/feather.js
Gathering detailed insights and metrics for @terra-money/feather.js
Gathering detailed insights and metrics for @terra-money/feather.js
Gathering detailed insights and metrics for @terra-money/feather.js
💻 JavaScript SDK for Station, written in TypeScript
npm install @terra-money/feather.js
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
19 Stars
777 Commits
27 Forks
12 Watching
9 Branches
16 Contributors
Updated on 08 Oct 2024
TypeScript (99.77%)
JavaScript (0.23%)
Cumulative downloads
Total Downloads
Last day
5.2%
3,660
Compared to previous day
Last week
68%
27,865
Compared to previous week
Last month
58.2%
67,170
Compared to previous month
Last year
316.5%
301,025
Compared to previous year
18
26
The JavaScript SDK for Terra and Feather chains
Explore the Docs »
Examples
·
API Reference
·
NPM Package
·
GitHub
Feather.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.
LCDClient
We highly suggest using Feather.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.
Grab the latest version off NPM:
1npm install @terra-money/feather.js
Feather.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.
1import { LCDClient, Coin } from '@terra-money/feather.js';
2
3// connect to testnet
4const lcd = LCDClient.fromDefaultConfig('testnet');
5
6// connect to mainnet
7const lcd = LCDClient.fromDefaultConfig('mainnet');
8
9// To use LocalTerra or a custom endpoint
10const lcd = new LCDClient({
11 localterra: {
12 // key must be the chainID
13 lcd: 'http://localhost:1317',
14 chainID: 'localterra',
15 gasAdjustment: 1.75,
16 gasPrices: { uluna: 0.15 },
17 prefix: 'terra', // bech32 prefix, used by the LCD to understand which is the right chain to query
18 },
19});
20
21// get the current balance of `terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v`
22// LCD understand automatically the chain to query using the bech32 prefix of the address
23const balance = lcd.bank.balance(
24 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v'
25);
26console.log(balance);
27
28// get the total circulation supply
29// LCD needs a chainID to understand the chain it should query
30const total = lcd.bank.total('phoenix-1');
31console.log(total);
First, get some testnet tokens for terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v
, or use LocalTerra.
1import { LCDClient, MsgSend, MnemonicKey } from '@terra-money/feather.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 testnet
10const lcd = LCDClient.fromDefaultConfig('testnet');
11
12// a wallet can be created out of any key
13// wallets abstract transaction building
14const wallet = lcd.wallet(mk);
15
16// create a simple message that moves coin balances
17const send = new MsgSend(
18 mk.accAddress('terra'), // .accAddress is now a function which require the prefix as parameter
19 'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp',
20 { uluna: 1200000 }
21);
22
23wallet
24 .createAndSignTx({
25 msgs: [send],
26 memo: 'test from feather.js!',
27 chainID: 'pisco-1', // now here a chainID must be specified
28 })
29 .then(tx => lcd.tx.broadcast(tx, 'pisco-1')) // same here
30 .then(result => {
31 console.log(`TX hash: ${result.txhash}`);
32 });
1wallet 2 // feather js detect that the tx contains a MsgAminoCustom and will use SIGN_MODE_AMINO_JSON instead of SIGN_MODE_DIRECT 3 .createAndSignTx({ 4 msgs: [ 5 new MsgAminoCustom({ 6 type: 'osmosis/gamm/swap-exact-amount-in', 7 value: { 8 sender: 'osmo1...', 9 routes: [ 10 { 11 pool_id: '2', 12 token_out_denom: 'uion', 13 }, 14 ], 15 token_in: { 16 denom: 'uosmo', 17 amount: '10000000', 18 }, 19 token_out_min_amount: '8538', 20 }, 21 }), 22 // you can add more messages here if needed 23 ], 24 memo: 'test from feather.js!', 25 chainID: 'osmosis-1', 26 }) 27 .then(tx => lcd.tx.broadcast(tx, 'osmosis-1')) 28 .then(result => { 29 console.log(`TX hash: ${result.txhash}`); 30 });
You can access all the objects of the @terra-money/feather.js
from the global Feather
object if you load Feather.js with a <script>
tag.
Include the following in your browser:
1<script 2 crossorigin 3 src="https://unpkg.com/@terra-money/feather.js/dist/bundle.js" 4></script>
You can find a small JSFiddle example that refreshes current Oracle votes here.
In order to use Feather.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}
This software is licensed under the MIT license. See LICENSE for full disclosure.
© 2022 Terraform Labs, PTE.
No vulnerabilities found.
No security vulnerabilities found.