@injectivelabs/sdk-ts 1.0.206 → 1.0.207
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -172
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,173 +54,6 @@ Read more and find example usages on our [Transactions Wiki](https://github.com/
|
|
|
54
54
|
|
|
55
55
|
---
|
|
56
56
|
|
|
57
|
-
## 🎒 Usage
|
|
58
|
-
|
|
59
|
-
Let's go through couple of use-cases of the `sdk-ts` so developers can have a reference codebase that they can look at.
|
|
60
|
-
|
|
61
|
-
### Consuming data
|
|
62
|
-
|
|
63
|
-
- Fetching user's inj balance from the chain
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
// Importing only the needed API
|
|
67
|
-
import { ChainGrpcBankApi, Network } from '@injectivelabs/sdk-ts'
|
|
68
|
-
|
|
69
|
-
const network = Network.testnet()
|
|
70
|
-
const injectiveAddress = 'inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r'
|
|
71
|
-
const denom = 'inj'
|
|
72
|
-
const chainGrpcBankApi = new ChainGrpcBankApi(network.sentryGrpcApi)
|
|
73
|
-
console.log(await chainGrpcBankApi.fetchBalance({ injectiveAddress, denom }))
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
// Using the client
|
|
78
|
-
import { ChainGrpcClient, Network } from '@injectivelabs/sdk-ts'
|
|
79
|
-
|
|
80
|
-
const network = Network.testnet()
|
|
81
|
-
const injectiveAddress = 'inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r'
|
|
82
|
-
const denom = 'inj'
|
|
83
|
-
const chainGrpcClient = new ChainGrpcClient(network.sentryGrpcApi)
|
|
84
|
-
console.log(await chainGrpcClient.bank.fetchBalance({ injectiveAddress, denom }))
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
- Fetching all derivative markets from the exchange (indexer) API
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
// Importing only the needed API
|
|
91
|
-
import { IndexerGrpcDerivativesApi, Network } from '@injectivelabs/sdk-ts'
|
|
92
|
-
|
|
93
|
-
const network = Network.testnet()
|
|
94
|
-
const exchangeGrpcDerivativesApi = new IndexerGrpcDerivativesApi(network.indexerApi)
|
|
95
|
-
console.log(await exchangeGrpcDerivativesApi.fetchMarkets())
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
// Using the client
|
|
100
|
-
import { IndexerGrpcClient, Network } from '@injectivelabs/sdk-ts'
|
|
101
|
-
|
|
102
|
-
const network = Network.testnet()
|
|
103
|
-
const exchangeGrpcClient = new IndexerGrpcClient(network.indexerApi)
|
|
104
|
-
console.log(await exchangeGrpcClient.derivatives.fetchMarkets())
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Broadcasting Transactions
|
|
108
|
-
|
|
109
|
-
- Sending INJ to another address
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
import { getNetworkInfo, Network } from "@injectivelabs/networks";
|
|
113
|
-
import { ChainRestAuthApi } from "@injectivelabs/sdk-ts";
|
|
114
|
-
import {
|
|
115
|
-
PrivateKey,
|
|
116
|
-
privateKeyToPublicKeyBase64,
|
|
117
|
-
MsgSend,
|
|
118
|
-
DEFAULT_STD_FEE,
|
|
119
|
-
} from "@injectivelabs/sdk-ts";
|
|
120
|
-
import { createTransaction, TxGrpcClient, TxClient } from "@injectivelabs/sdk-ts/dist/core/transaction";
|
|
121
|
-
import { BigNumberInBase } from "@injectivelabs/utils";
|
|
122
|
-
|
|
123
|
-
/** MsgSend Example */
|
|
124
|
-
(async () => {
|
|
125
|
-
const network = getNetworkInfo(Network.Public);
|
|
126
|
-
const privateKeyHash =
|
|
127
|
-
"f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3";
|
|
128
|
-
const privateKey = PrivateKey.fromPrivateKey(privateKeyHash);
|
|
129
|
-
const injectiveAddress = privateKey.toBech32();
|
|
130
|
-
const publicKey = privateKeyToPublicKeyBase64(
|
|
131
|
-
Buffer.from(privateKeyHash.replace("0x", ""), "hex")
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
/** Account Details **/
|
|
135
|
-
const accountDetails = await new ChainRestAuthApi(
|
|
136
|
-
network.sentryHttpApi
|
|
137
|
-
).fetchAccount(injectiveAddress);
|
|
138
|
-
|
|
139
|
-
/** Prepare the Message */
|
|
140
|
-
const amount = {
|
|
141
|
-
amount: new BigNumberInBase(0.01).toWei().toFixed(),
|
|
142
|
-
denom: "inj",
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const msg = MsgSend.fromJSON({
|
|
146
|
-
amount,
|
|
147
|
-
srcInjectiveAddress: injectiveAddress,
|
|
148
|
-
dstInjectiveAddress: injectiveAddress,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
/** Prepare the Transaction */
|
|
152
|
-
const { signBytes, txRaw } = createTransaction({
|
|
153
|
-
message: msg.toDirectSign(),
|
|
154
|
-
memo: "",
|
|
155
|
-
fee: DEFAULT_STD_FEE,
|
|
156
|
-
pubKey: publicKey,
|
|
157
|
-
sequence: parseInt(accountDetails.account.base_account.sequence, 10),
|
|
158
|
-
accountNumber: parseInt(
|
|
159
|
-
accountDetails.account.base_account.account_number,
|
|
160
|
-
10
|
|
161
|
-
),
|
|
162
|
-
chainId: network.chainId,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
/** Sign transaction */
|
|
166
|
-
const signature = await privateKey.sign(signBytes);
|
|
167
|
-
|
|
168
|
-
/** Append Signatures */
|
|
169
|
-
txRaw.setSignaturesList([signature]);
|
|
170
|
-
|
|
171
|
-
/** Calculate hash of the transaction */
|
|
172
|
-
console.log(`Transaction Hash: ${await TxClient.hash(txRaw)}`);
|
|
173
|
-
|
|
174
|
-
const txService = new TxGrpcClient(network.sentryGrpcApi);
|
|
175
|
-
|
|
176
|
-
/** Simulate transaction */
|
|
177
|
-
const simulationResponse = await txService.simulate(txRaw);
|
|
178
|
-
console.log(
|
|
179
|
-
`Transaction simulation response: ${JSON.stringify(
|
|
180
|
-
simulationResponse.gasInfo
|
|
181
|
-
)}`
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
/** Broadcast transaction */
|
|
185
|
-
const txResponse = await txService.broadcast(txRaw);
|
|
186
|
-
console.log(
|
|
187
|
-
`Broadcasted transaction hash: ${JSON.stringify(txResponse.txhash)}`
|
|
188
|
-
);
|
|
189
|
-
})();
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Streaming Data
|
|
193
|
-
|
|
194
|
-
- Streaming users subaccount balances from the indexer API
|
|
195
|
-
|
|
196
|
-
```ts
|
|
197
|
-
import { getNetworkInfo, Network } from "@injectivelabs/networks";
|
|
198
|
-
import { IndexerGrpcStreamClient } from "@injectivelabs/sdk-ts/dist/client/indexer/IndexerGrpcStreamClient";
|
|
199
|
-
|
|
200
|
-
(async () => {
|
|
201
|
-
const network = getNetworkInfo(Network.TestnetK8s);
|
|
202
|
-
|
|
203
|
-
const subaccountId =
|
|
204
|
-
"0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000";
|
|
205
|
-
|
|
206
|
-
const exchangeClient = new IndexerGrpcStreamClient(
|
|
207
|
-
network.indexerApi
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
await exchangeClient.account.streamSubaccountBalance({
|
|
211
|
-
subaccountId,
|
|
212
|
-
callback: (subaccountBalance) => {
|
|
213
|
-
console.log(subaccountBalance);
|
|
214
|
-
},
|
|
215
|
-
onEndCallback: (status) => {
|
|
216
|
-
console.log("Stream has ended with status: " + status);
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
})();
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
---
|
|
223
|
-
|
|
224
57
|
## 📜 Contribution
|
|
225
58
|
|
|
226
59
|
**Contribution guides and practices will be available once there is a stable foundation of the whole package set within the `injective-ts` repo.**
|
|
@@ -240,9 +73,11 @@ Reach out to us at one of the following places!
|
|
|
240
73
|
|
|
241
74
|
## 🔓 License
|
|
242
75
|
|
|
243
|
-
|
|
76
|
+
Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
|
|
77
|
+
|
|
78
|
+
<a href="https://iili.io/mNneZN.md.png"><img src="https://iili.io/mNneZN.md.png" style="width: 300px; max-width: 100%; height: auto" />
|
|
244
79
|
|
|
245
|
-
<
|
|
246
|
-
<
|
|
247
|
-
|
|
248
|
-
|
|
80
|
+
Originally released by Injective Labs Inc. under: <br />
|
|
81
|
+
Apache License <br />
|
|
82
|
+
Version 2.0, January 2004 <br />
|
|
83
|
+
http://www.apache.org/licenses/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/sdk-ts",
|
|
3
3
|
"description": "SDK in TypeScript for building Injective applications in a browser, node, and react native environment.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.207",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Bojan Angjelkoski",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"shx": "^0.3.2",
|
|
67
67
|
"snakecase-keys": "^5.4.1"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "bb29719c1167ff802d1ff45a12b1fd4bc03dc9b7",
|
|
70
70
|
"typedoc": {
|
|
71
71
|
"entryPoint": "./src/index.ts",
|
|
72
72
|
"readmeFile": "./README.md",
|