@terra-money/terra.js
Advanced tools
Comparing version 0.4.10 to 0.4.11
import { LCDClient } from './LCDClient'; | ||
import { Key } from '../../key'; | ||
import { Msg, StdFee, StdTx, StdSignMsg } from '../../core'; | ||
import { Msg, StdFee, StdTx, StdSignMsg, Coins, Numeric } from '../../core'; | ||
export interface CreateTxOptions { | ||
@@ -8,2 +8,4 @@ msgs: Msg[]; | ||
memo?: string; | ||
gasPrices?: Coins.Input; | ||
gasAdjustment?: Numeric.Input; | ||
} | ||
@@ -10,0 +12,0 @@ export declare class Wallet { |
@@ -76,3 +76,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var fee, memo, msgs, gasPrices, gasPricesCoins, stdTx, _a, _b; | ||
var fee, memo, msgs, estimateFeeOptions, balance, balanceOne, stdTx, _a, _b; | ||
return __generator(this, function (_c) { | ||
@@ -84,20 +84,24 @@ switch (_c.label) { | ||
memo = memo || ''; | ||
gasPrices = this.lcd.config.gasPrices || new core_1.Coins({}); | ||
gasPricesCoins = new core_1.Coins(gasPrices); | ||
// set each denom in gas prices to 1 | ||
gasPricesCoins = new core_1.Coins(gasPricesCoins.map(function (c) { return new core_1.Coin(c.denom, 1); })); | ||
if (!(fee === undefined)) return [3 /*break*/, 2]; | ||
stdTx = new core_1.StdTx(msgs, new core_1.StdFee(0, gasPricesCoins), [], memo); | ||
return [4 /*yield*/, this.lcd.tx.estimateFee(stdTx)]; | ||
estimateFeeOptions = { | ||
gasPrices: options.gasPrices || this.lcd.config.gasPrices, | ||
gasAdjustment: options.gasAdjustment || this.lcd.config.gasAdjustment, | ||
}; | ||
return [4 /*yield*/, this.lcd.bank.balance(this.key.accAddress)]; | ||
case 1: | ||
balance = _c.sent(); | ||
balanceOne = balance.map(function (c) { return new core_1.Coin(c.denom, 1); }); | ||
if (!(fee === undefined)) return [3 /*break*/, 3]; | ||
stdTx = new core_1.StdTx(msgs, new core_1.StdFee(0, balanceOne), [], memo); | ||
return [4 /*yield*/, this.lcd.tx.estimateFee(stdTx, estimateFeeOptions)]; | ||
case 2: | ||
fee = _c.sent(); | ||
_c.label = 2; | ||
case 2: | ||
_c.label = 3; | ||
case 3: | ||
_a = core_1.StdSignMsg.bind; | ||
_b = [void 0, this.lcd.config.chainID]; | ||
return [4 /*yield*/, this.accountNumber()]; | ||
case 3: | ||
case 4: | ||
_b = _b.concat([_c.sent()]); | ||
return [4 /*yield*/, this.sequence()]; | ||
case 4: return [2 /*return*/, new (_a.apply(core_1.StdSignMsg, _b.concat([_c.sent(), fee, | ||
case 5: return [2 /*return*/, new (_a.apply(core_1.StdSignMsg, _b.concat([_c.sent(), fee, | ||
msgs, | ||
@@ -104,0 +108,0 @@ memo])))()]; |
{ | ||
"version": "0.4.10", | ||
"version": "0.4.11", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
126
README.md
@@ -10,22 +10,36 @@ <p> </p> | ||
![diagram](https://raw.githubusercontent.com/terra-project/terra.js/master/img/terrajs-diagram.png) | ||
<br/> | ||
![diagram](https://raw.githubusercontent.com/terra-project/terra.js/master/img/terrajs-diagram.png) | ||
<p align="center"> | ||
<img alt="GitHub" src="https://img.shields.io/github/license/terra-project/terra.js"> | ||
<img alt="npm (scoped)" src="https://img.shields.io/npm/v/@terra-money/terra.js"> | ||
</p> | ||
<div align="center"> | ||
<h3> | ||
<a href="https://github.com/terra-project/terra.js/wiki"> | ||
Docs | ||
</a> | ||
<span> | </span> | ||
<a href="https://terra-project.github.io/terra.js/"> | ||
API | ||
</a> | ||
<span> | </span> | ||
<a href="https://www.npmjs.com/package/@terra-money/terra.js"> | ||
NPM Package | ||
</a> | ||
</h3> | ||
</div> | ||
<p align="center"> | ||
<a href="https://github.com/terra-project/terra.js/wiki"><strong>Explore the Docs »</strong></a> | ||
<br /> | ||
<br/> | ||
<a href="https://github.com/terra-project/terra.js/wiki">Examples</a> | ||
· | ||
<a href="https://terra-project.github.io/terra.js/">API Reference</a> | ||
· | ||
<a href="https://www.npmjs.com/package/@terra-money/terra.js">NPM Package</a> | ||
· | ||
<a href="https://github.com/terra-project/terra.js">GitHub</a> | ||
</p> | ||
Terra.js a JavaScript SDK for writing applications that interact with the Terra blockchain from either a Node.js or browser 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](https://github.com/terra-project/terra.js/wiki/Keys) solutions | ||
- Works in both Node.js and in the browser | ||
- Exposes the Terra API through [`LCDClient`](https://github.com/terra-project/terra.js/wiki/Querying) | ||
- 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 | ||
@@ -39,21 +53,77 @@ | ||
## Features | ||
## Usage | ||
- **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 | ||
Terra.js can be use in Node.js, as well as inside the browser. Please check the [GitHub Wiki](https://github.com/terra-project/terra.js/wiki) for notes on how to get up and running. | ||
## Usage | ||
### Getting blockchain data | ||
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. Please check the [GitHub Wiki](https://github.com/terra-project/terra.js/wiki) for notes on how to get up and running. | ||
```ts | ||
import { LCDClient, Coin } from '@terra-money/terra.js'; | ||
## Example | ||
// connect to soju testnet | ||
const terra = new LCDClient({ | ||
URL: 'https://soju-lcd.terra.dev', | ||
chainId: 'soju-0014', | ||
}); | ||
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. | ||
// To use LocalTerra | ||
// const terra = new LCDClient({ | ||
// URL: 'http://localhost:1317', | ||
// chainId: 'localterra' | ||
// }); | ||
You can play with the complete example on JSFiddle [here](https://jsfiddle.net/wchen298/y6roqbdw/63/). | ||
// get the current swap rate from 1 TerraUSD to TerraKRW | ||
const offerCoin = new Coin('uusd', '1000000'); | ||
terra.market.swap(offerCoin, 'ukrw').then(c => { | ||
console.log(`${offerCoin.toString()} can be swapped for ${c.toString()}`); | ||
}); | ||
``` | ||
### Broadcasting transactions | ||
First, [get](https://faucet.terra.money/) some testnet tokens for `terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v`, or use [LocalTerra](https://www.github.com/terra-project/LocalTerra). | ||
```ts | ||
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 soju testnet | ||
const terra = new LCDClient({ | ||
URL: 'https://soju-lcd.terra.dev', | ||
chainId: 'soju-0014', | ||
}); | ||
// 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: 1000000, ukrw: 1230201, uusd: 1312029 } | ||
); | ||
wallet | ||
.createAndSignTx({ | ||
msgs: [send], | ||
memo: 'test from terra.js!', | ||
}) | ||
.then(terra.tx.broadcast) | ||
.then(result => { | ||
console.log(`TX hash: ${result.txhash}`); | ||
}); | ||
``` | ||
## Terra.js in the browser | ||
@@ -60,0 +130,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
5811247
16171
157