@ar.io/sdk 3.9.1 → 3.10.0-alpha.2

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.
Files changed (51) hide show
  1. package/README.md +124 -140
  2. package/bundles/web.bundle.min.js +107 -99
  3. package/lib/cjs/cli/options.js +12 -0
  4. package/lib/cjs/cli/utils.js +33 -11
  5. package/lib/cjs/common/ant-versions.js +5 -5
  6. package/lib/cjs/common/faucet.js +150 -0
  7. package/lib/cjs/common/index.js +1 -0
  8. package/lib/cjs/common/io.js +107 -4
  9. package/lib/cjs/common/turbo.js +134 -0
  10. package/lib/cjs/types/faucet.js +2 -0
  11. package/lib/cjs/types/index.js +1 -0
  12. package/lib/cjs/types/io.js +4 -3
  13. package/lib/cjs/utils/ao.js +2 -0
  14. package/lib/cjs/utils/url.js +28 -0
  15. package/lib/cjs/utils/url.test.js +24 -0
  16. package/lib/cjs/version.js +1 -1
  17. package/lib/esm/cli/options.js +12 -0
  18. package/lib/esm/cli/utils.js +31 -10
  19. package/lib/esm/common/ant-versions.js +5 -5
  20. package/lib/esm/common/faucet.js +145 -0
  21. package/lib/esm/common/index.js +1 -0
  22. package/lib/esm/common/io.js +106 -3
  23. package/lib/esm/common/turbo.js +129 -0
  24. package/lib/esm/types/faucet.js +1 -0
  25. package/lib/esm/types/index.js +1 -0
  26. package/lib/esm/types/io.js +4 -3
  27. package/lib/esm/utils/ao.js +2 -0
  28. package/lib/esm/utils/url.js +24 -0
  29. package/lib/esm/utils/url.test.js +19 -0
  30. package/lib/esm/version.js +1 -1
  31. package/lib/types/cli/commands/antCommands.d.ts +3 -3
  32. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
  33. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
  34. package/lib/types/cli/commands/readCommands.d.ts +1 -0
  35. package/lib/types/cli/commands/transfer.d.ts +3 -3
  36. package/lib/types/cli/options.d.ts +9 -0
  37. package/lib/types/cli/types.d.ts +3 -0
  38. package/lib/types/cli/utils.d.ts +4 -0
  39. package/lib/types/common/ant-versions.d.ts +3 -6
  40. package/lib/types/common/faucet.d.ts +96 -0
  41. package/lib/types/common/index.d.ts +1 -0
  42. package/lib/types/common/io.d.ts +25 -25
  43. package/lib/types/common/turbo.d.ts +47 -0
  44. package/lib/types/types/common.d.ts +6 -1
  45. package/lib/types/types/faucet.d.ts +82 -0
  46. package/lib/types/types/index.d.ts +1 -0
  47. package/lib/types/types/io.d.ts +9 -8
  48. package/lib/types/utils/url.d.ts +19 -0
  49. package/lib/types/utils/url.test.d.ts +1 -0
  50. package/lib/types/version.d.ts +1 -1
  51. package/package.json +7 -7
package/README.md CHANGED
@@ -13,118 +13,14 @@ This is the home of [ar.io] SDK. This SDK provides functionality for interacting
13
13
  - [Installation](#installation)
14
14
  - [Quick Start](#quick-start)
15
15
  - [Usage](#usage)
16
- - [Networks (Mainnet, Testnet, etc.)](#networks-mainnet-testnet-etc)
17
- - [Web](#web)
18
- - [Bundlers (Webpack, Rollup, ESbuild, etc.)](#bundlers-webpack-rollup-esbuild-etc)
19
- - [Browser](#browser)
20
- - [Node](#node)
21
- - [ESM (NodeNext)](#esm-nodenext)
22
- - [CJS](#cjs)
23
- - [Typescript](#typescript)
24
- - [ARIOToken & mARIOToken](#ariotoken--mariotoken)
25
- - [Converting ARIO to mARIO](#converting-ario-to-mario)
26
- - [ARIO Process](#ario-process)
27
- - [General](#general)
28
- - [`init({ signer })`](#init-signer-)
29
- - [`getInfo()`](#getinfo)
30
- - [`getTokenSupply()`](#gettokensupply)
31
- - [`getBalance({ address })`](#getbalance-address-)
32
- - [`getBalances({ cursor, limit, sortBy, sortOrder })`](#getbalances-cursor-limit-sortby-sortorder-)
33
- - [`transfer({ target, qty })`](#transfer-target-qty-)
34
- - [Vaults](#vaults)
35
- - [`getVault({ address, vaultId })`](#getvault-address-vaultid-)
36
- - [`getVaults({ cursor, limit, sortBy, sortOrder })`](#getvaults-cursor-limit-sortby-sortorder-)
37
- - [`vaultedTransfer({ recipient, quantity, lockLengthMs, revokable })`](#vaultedtransfer-recipient-quantity-locklengthms-revokable-)
38
- - [`revokeVault({ recipient, vaultId })`](#revokevault-recipient-vaultid-)
39
- - [`createVault({ lockLengthMs, quantity })`](#createvault-locklengthms-quantity-)
40
- - [`extendVault({ vaultId, extendLengthMs })`](#extendvault-vaultid-extendlengthms-)
41
- - [`increaseVault({ vaultId, quantity })`](#increasevault-vaultid-quantity-)
42
- - [Gateways](#gateways)
43
- - [`getGateway({ address })`](#getgateway-address-)
44
- - [`getGateways({ cursor, limit, sortBy, sortOrder })`](#getgateways-cursor-limit-sortby-sortorder-)
45
- - [`getGatewayDelegates({ address, cursor, limit, sortBy, sortOrder })`](#getgatewaydelegates-address-cursor-limit-sortby-sortorder-)
46
- - [`joinNetwork(params)`](#joinnetworkparams)
47
- - [`leaveNetwork()`](#leavenetwork)
48
- - [`updateGatewaySettings({ ...settings })`](#updategatewaysettings-settings-)
49
- - [`increaseDelegateStake({ target, qty })`](#increasedelegatestake-target-qty-)
50
- - [`decreaseDelegateStake({ target, qty, instant })`](#decreasedelegatestake-target-qty-instant-)
51
- - [`getDelegations({ address, cursor, limit, sortBy, sortOrder })`](#getdelegations-address-cursor-limit-sortby-sortorder-)
52
- - [`instantWithdrawal({ gatewayAddress, vaultId })`](#instantwithdrawal-gatewayaddress-vaultid-)
53
- - [`cancelWithdrawal({ gatewayAddress, vaultId })`](#cancelwithdrawal-gatewayaddress-vaultid-)
54
- - [`getAllowedDelegates({ address, cursor, limit, sortBy, sortOrder })`](#getalloweddelegates-address-cursor-limit-sortby-sortorder-)
55
- - [`getGatewayVaults({ address, cursor, limit, sortBy, sortOrder })`](#getgatewayvaults-address-cursor-limit-sortby-sortorder-)
56
- - [`getAllGatewayVaults({ cursor, limit, sortBy, sortOrder })`](#getallgatewayvaults-cursor-limit-sortby-sortorder-)
57
- - [`increaseOperatorStake({ qty })`](#increaseoperatorstake-qty-)
58
- - [`decreaseOperatorStake({ qty })`](#decreaseoperatorstake-qty-)
59
- - [`redelegateStake({ target, source, stakeQty, vaultId })`](#redelegatestake-target-source-stakeqty-vaultid-)
60
- - [`getRedelegationFee({ address })`](#getredelegationfee-address-)
61
- - [`getAllDelegates({ cursor, limit, sortBy, sortOrder })`](#getalldelegates-cursor-limit-sortby-sortorder-)
62
- - [Arweave Name System (ArNS)](#arweave-name-system-arns)
63
- - [`buyRecord({ name, type, years, processId })`](#buyrecord-name-type-years-processid-)
64
- - [`getArNSRecord({ name })`](#getarnsrecord-name-)
65
- - [`getArNSRecords({ cursor, limit, sortBy, sortOrder })`](#getarnsrecords-cursor-limit-sortby-sortorder-)
66
- - [`increaseUndernameLimit({ name, qty })`](#increaseundernamelimit-name-qty-)
67
- - [`extendLease({ name, years })`](#extendlease-name-years-)
68
- - [`getTokenCost({ intent, ...args })`](#gettokencost-intent-args-)
69
- - [`getCostDetails({ intent, fromAddress, fundFrom, ...args})`](#getcostdetails-intent-fromaddress-fundfrom-args)
70
- - [`getDemandFactor()`](#getdemandfactor)
71
- - [`getArNSReturnedNames({ cursor, limit, sortBy, sortOrder })`](#getarnsreturnednames-cursor-limit-sortby-sortorder-)
72
- - [`getArNSReturnedName({ name })`](#getarnsreturnedname-name-)
73
- - [Epochs](#epochs)
74
- - [`getCurrentEpoch()`](#getcurrentepoch)
75
- - [`getEpoch({ epochIndex })`](#getepoch-epochindex-)
76
- - [`getEligibleEpochRewards({ epochIndex }, { cursor, limit, sortBy, sortOrder })](#geteligibleepochrewards-epochindex---cursor-limit-sortby-sortorder-)
77
- - [`getObservations({ epochIndex })`](#getobservations-epochindex-)
78
- - [`getDistributions({ epochIndex })`](#getdistributions-epochindex-)
79
- - [`saveObservations({ reportTxId, failedGateways })`](#saveobservations-reporttxid-failedgateways-)
80
- - [`getPrescribedObservers({ epochIndex })`](#getprescribedobservers-epochindex-)
81
- - [Primary Names](#primary-names)
82
- - [`getPrimaryNames({ cursor, limit, sortBy, sortOrder })`](#getprimarynames-cursor-limit-sortby-sortorder-)
83
- - [`getPrimaryName({ name, address })`](#getprimaryname-name-address-)
84
- - [`requestPrimaryName({ name })`](#requestprimaryname-name-)
85
- - [`getPrimaryNameRequest({ initiator })`](#getprimarynamerequest-initiator-)
86
- - [Configuration](#configuration)
16
+ - [Networks (Mainnet, Testnet, etc.)](#networks-mainnet-testnet-etc)
17
+ - [ARIO](#ario)
87
18
  - [Arweave Name Tokens (ANT's)](#arweave-name-tokens-ants)
88
- - [ANT APIs](#ant-apis)
89
- - [`init({ processId, signer })`](#init-processid-signer-)
90
- - [`getInfo()`](#getinfo-1)
91
- - [`getHandlers()`](#gethandlers)
92
- - [`getState()`](#getstate)
93
- - [`getOwner()`](#getowner)
94
- - [`getControllers()`](#getcontrollers)
95
- - [`getRecords()`](#getrecords)
96
- - [`transfer({ target })`](#transfer-target-)
97
- - [`setController({ controller })`](#setcontroller-controller-)
98
- - [`removeController({ controller })`](#removecontroller-controller-)
99
- - [`setBaseNameRecord({ transactionId, ttlSeconds })`](#setbasenamerecord-transactionid-ttlseconds-)
100
- - [`setUndernameRecord({ undername, transactionId, ttlSeconds })`](#setundernamerecord-undername-transactionid-ttlseconds-)
101
- - [`removeUndernameRecord({ undername })`](#removeundernamerecord-undername-)
102
- - [`setRecord({ undername, transactionId, ttlSeconds })`](#setrecord-undername-transactionid-ttlseconds-)
103
- - [`removeRecord({ undername })`](#removerecord-undername-)
104
- - [`setName({ name })`](#setname-name-)
105
- - [`setTicker({ ticker })`](#setticker-ticker-)
106
- - [`setDescription({ description })`](#setdescription-description-)
107
- - [`setKeywords({ keywords })`](#setkeywords-keywords-)
108
- - [`getLogo()`](#getlogo)
109
- - [`setLogo({ txId })`](#setlogo-txid-)
110
- - [`releaseName({ name, arioProcessId })`](#releasename-name-arioprocessid-)
111
- - [`reassignName({ name, arioProcessId, antProcessId })`](#reassignname-name-arioprocessid-antprocessid-)
112
- - [`approvePrimaryNameRequest({ name, address, arioProcessId })`](#approveprimarynamerequest-name-address-arioprocessid-)
113
- - [`removePrimaryNames({ names, arioProcessId, notifyOwners })`](#removeprimarynames-names-arioprocessid-notifyowners-)
114
- - [Configuration](#configuration-1)
19
+ - [Token Conversion](#token-conversion)
115
20
  - [Logging](#logging)
116
21
  - [Pagination](#pagination)
117
22
  - [Resources](#resources)
118
- - [Bundling](#bundling)
119
- - [AR.IO Gateways](#ario-gateways)
120
- - [Running a Gateway](#running-a-gateway)
121
- - [AO](#ao)
122
23
  - [Developers](#developers)
123
- - [Requirements](#requirements)
124
- - [Setup & Build](#setup--build)
125
- - [Testing](#testing)
126
- - [Linting & Formatting](#linting--formatting)
127
- - [Architecture](#architecture)
128
24
 
129
25
  <!-- tocstop -->
130
26
 
@@ -209,29 +105,6 @@ const gateways = await ario.getGateways();
209
105
 
210
106
  The SDK is provided in both CommonJS and ESM formats and is compatible with bundlers such as Webpack, Rollup, and ESbuild. Utilize the appropriately named exports provided by this SDK's [package.json] based on your project's configuration. Refer to the [examples] directory to see how to use the SDK in various environments.
211
107
 
212
- ### Networks (Mainnet, Testnet, etc.)
213
-
214
- The SDK provides the following process IDs for the mainnet and testnet environments:
215
-
216
- - `ARIO_MAINNET_PROCESS_ID` - Mainnet ARIO process ID (production)
217
- - `ARIO_TESTNET_PROCESS_ID` - Testnet ARIO process ID (testing and development)
218
- - `ARIO_DEVNET_PROCESS_ID` - Devnet ARIO process ID (for development purposes)
219
-
220
- As of `v3.8.1` the SDK defaults all API interactions to **mainnet**. To use the **testnet** or **devnet** provide the appropriate `ARIO_TESTNET_PROCESS_ID` or `ARIO_DEVNET_PROCESS_ID` when initializing the client.
221
-
222
- ```typescript
223
- import {
224
- ARIO,
225
- ARIO_DEVNET_PROCESS_ID,
226
- ARIO_MAINNET_PROCESS_ID,
227
- ARIO_TESTNET_PROCESS_ID,
228
- } from '@ar.io/sdk';
229
- ```
230
-
231
- ```typescript
232
- const ario = ARIO.init({ processId: ARIO_TESTNET_PROCESS_ID }); // use the testnet contract
233
- ```
234
-
235
108
  ### Web
236
109
 
237
110
  #### Bundlers (Webpack, Rollup, ESbuild, etc.)
@@ -293,25 +166,117 @@ The SDK provides TypeScript types. When you import the SDK in a TypeScript proje
293
166
  > [!NOTE]
294
167
  > Typescript version 5.3 or higher is recommended.
295
168
 
296
- ## ARIOToken & mARIOToken
169
+ ## Networks (Mainnet, Testnet, etc.)
297
170
 
298
- The ARIO process stores all values as mARIO (milli-ARIO) to avoid floating-point arithmetic issues. The SDK provides an `ARIOToken` and `mARIOToken` classes to handle the conversion between ARIO and mARIO, along with rounding logic for precision.
171
+ The SDK provides the following process IDs for the mainnet and testnet environments:
299
172
 
300
- **All process interactions expect values in mARIO. If numbers are provided as inputs, they are assumed to be in raw mARIO values.**
173
+ - `ARIO_MAINNET_PROCESS_ID` - Mainnet ARIO process ID (production)
174
+ - `ARIO_TESTNET_PROCESS_ID` - Testnet ARIO process ID (testing and development)
175
+ - `ARIO_DEVNET_PROCESS_ID` - Devnet ARIO process ID (development)
301
176
 
302
- ### Converting ARIO to mARIO
177
+ As of `v3.8.1` the SDK defaults all API interactions to **mainnet**. To use the **testnet** or **devnet** provide the appropriate `ARIO_TESTNET_PROCESS_ID` or `ARIO_DEVNET_PROCESS_ID` when initializing the client.
303
178
 
304
179
  ```typescript
305
- import { ARIOToken, mARIOToken } from '@ar.io/sdk';
180
+ import { ARIO, ARIO_TESTNET_PROCESS_ID } from '@ar.io/sdk';
181
+ ```
306
182
 
307
- const arioValue = 1;
308
- const mARIOValue = new ARIOToken(arioValue).toMARIO();
183
+ ```typescript
184
+ const testnet = ARIO.testnet();
185
+ ```
309
186
 
310
- const mARIOValue = 1_000_000;
311
- const arioValue = new mARIOToken(mARIOValue).toARIO();
187
+ ### Mainnet
188
+
189
+ As of `v3.8.1` the SDK defaults all API interactions to **mainnet**. To use the **testnet** or **devnet** provide the appropriate `ARIO_TESTNET_PROCESS_ID` or `ARIO_DEVNET_PROCESS_ID` when initializing the client.
190
+
191
+ ```typescript
192
+ import { ARIO } from '@ar.io/sdk';
193
+
194
+ const ario = ARIO.mainnet(); // or ARIO.init()
312
195
  ```
313
196
 
314
- ## ARIO Process
197
+ ### Testnet
198
+
199
+ ```typescript
200
+ import { ARIO } from '@ar.io/sdk';
201
+
202
+ const testnet = ARIO.testnet(); // or ARIO.init({ processId: ARIO_TESTNET_PROCESS_ID })
203
+ ```
204
+
205
+ #### Faucet
206
+
207
+ The SDK provides APIs for claiming tokens via a faucet on the AR.IO Testnet process (`tARIO`) via the [ar-io-testnet-faucet] service. All token requests require a captcha to be solved, and the faucet is rate limited to prevent abuse.
208
+
209
+ To claim testnet tokens from the testnet token faucet, you can use one of the following methods:
210
+
211
+ 1. Visit [faucet.ar.io](https://faucet.ar.io) - the easiest way to quickly get tokens for testing for a single address.
212
+
213
+ 2. Programmatically via the SDK - useful if you need to claim tokens for multiple addresses or dynamically within your application.
214
+
215
+ - `ARIO.testnet().faucet.captchaUrl()` - returns the captcha URL for the testnet faucet. Open this URL in a new browser window and listen for the `ario-jwt-success` event to be emitted.
216
+ - `ARIO.testnet().faucet.claimWithAuthToken({ authToken, recipient, quantity })` - claims tokens for the specified recipient address using the provided auth token.
217
+ - `ARIO.testnet().faucet.verifyAuthToken({ authToken })` - verifies if the provided auth token is still valid.
218
+
219
+ <details>
220
+ <summary><i>Example client-side code for claiming tokens</i></summary>
221
+
222
+ ```typescript
223
+ import { ARIO } from '@ar.io/sdk';
224
+
225
+ const testnet = ARIO.testnet();
226
+ const captchaUrl = await ario.faucet.captchaUrl();
227
+
228
+ // open the captcha URL in the browser, and listen for the auth token event
229
+ const captchaWindow = window.open(
230
+ captchaUrl.captchaUrl,
231
+ '_blank',
232
+ 'width=600,height=600',
233
+ );
234
+ /**
235
+ * The captcha URL includes a window.parent.postMessage event that is used to send the auth token to the parent window.
236
+ * You can store the auth token in localStorage and use it to claim tokens for the duration of the auth token's expiration (default 1 hour).
237
+ */
238
+ window.parent.addEventListener('message', async (event) => {
239
+ if (event.data.type === 'ario-jwt-success') {
240
+ localStorage.setItem('ario-jwt', event.data.token);
241
+ localStorage.setItem('ario-jwt-expires-at', event.data.expiresAt);
242
+ // close our captcha window
243
+ captchaWindow?.close();
244
+ // claim the tokens using the JWT token
245
+ const res = await testnet.faucet
246
+ .claimWithAuthToken({
247
+ authToken: event.data.token,
248
+ recipient: await window.arweaveWallet.getActiveAddress(),
249
+ quantity: new ARIOToken(100).toMARIO().valueOf(), // 100 ARIO
250
+ })
251
+ .then((res) => {
252
+ alert(
253
+ 'Successfully claimed 100 ARIO tokens! Transaction ID: ' + res.id,
254
+ );
255
+ })
256
+ .catch((err) => {
257
+ alert(`Failed to claim tokens: ${err}`);
258
+ });
259
+ }
260
+ });
261
+
262
+ /**
263
+ * Once you have a valid JWT, you can check if it is still valid and use it for subsequent requests without having to open the captcha again.
264
+ */
265
+ if (
266
+ localStorage.getItem('ario-jwt-expires-at') &&
267
+ Date.now() < parseInt(localStorage.getItem('ario-jwt-expires-at') ?? '0')
268
+ ) {
269
+ const res = await testnet.faucet.claimWithAuthToken({
270
+ authToken: localStorage.getItem('ario-jwt') ?? '',
271
+ recipient: await window.arweaveWallet.getActiveAddress(),
272
+ quantity: new ARIOToken(100).toMARIO().valueOf(), // 100 ARIO
273
+ });
274
+ }
275
+ ```
276
+
277
+ </details>
278
+
279
+ ## ARIO
315
280
 
316
281
  ### General
317
282
 
@@ -2468,6 +2433,24 @@ const ant = ANT.init({
2468
2433
  });
2469
2434
  ```
2470
2435
 
2436
+ ## Token Conversion
2437
+
2438
+ The ARIO process stores all values as mARIO (milli-ARIO) to avoid floating-point arithmetic issues. The SDK provides an `ARIOToken` and `mARIOToken` classes to handle the conversion between ARIO and mARIO, along with rounding logic for precision.
2439
+
2440
+ **All process interactions expect values in mARIO. If numbers are provided as inputs, they are assumed to be in raw mARIO values.**
2441
+
2442
+ ### Converting ARIO to mARIO
2443
+
2444
+ ```typescript
2445
+ import { ARIOToken, mARIOToken } from '@ar.io/sdk';
2446
+
2447
+ const arioValue = 1;
2448
+ const mARIOValue = new ARIOToken(arioValue).toMARIO();
2449
+
2450
+ const mARIOValue = 1_000_000;
2451
+ const arioValue = new mARIOToken(mARIOValue).toARIO();
2452
+ ```
2453
+
2471
2454
  ## Logging
2472
2455
 
2473
2456
  The library uses the [Winston] logger for node based projects, and `console` logger for web based projects by default. You can configure the log level via `setLogLevel()` API. Alternatively you can set a custom logger as the default logger so long as it satisfes the `ILogger` interface.
@@ -2589,3 +2572,4 @@ For more information on how to contribute, please see [CONTRIBUTING.md].
2589
2572
  [ar-io-node repository]: https://github.com/ar-io/ar-io-node
2590
2573
  [ar.io Gateway Documentation]: https://docs.ar.io/gateways/ar-io-node/overview/
2591
2574
  [ANS-104]: https://github.com/ArweaveTeam/arweave-standards/blob/master/ans/ANS-104.md
2575
+ [ar-io-testnet-faucet]: https://github.com/ar-io/ar-io-testnet-faucet?tab=readme-ov-file#asynchronous-workflow