@ar.io/sdk 3.21.0-alpha.1 → 3.21.1-alpha.1
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 +244 -16
- package/bundles/web.bundle.min.js +36 -35
- package/lib/cjs/utils/arweave.js +17 -6
- package/lib/cjs/version.js +1 -1
- package/lib/esm/utils/arweave.js +17 -6
- package/lib/esm/version.js +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2125,9 +2125,76 @@ ar.io spawn-ant --wallet-file wallet.json --module FKtQtOOtlcWCW2pXrwWFiCSlnuewM
|
|
|
2125
2125
|
|
|
2126
2126
|
### Versions
|
|
2127
2127
|
|
|
2128
|
+
#### `getModuleId({ graphqlUrl?, retries? })`
|
|
2129
|
+
|
|
2130
|
+
Gets the module ID of the current ANT process by querying its spawn transaction tags. Results are cached after the first successful fetch.
|
|
2131
|
+
|
|
2132
|
+
```typescript
|
|
2133
|
+
const moduleId = await ant.getModuleId();
|
|
2134
|
+
console.log(`ANT was spawned with module: ${moduleId}`);
|
|
2135
|
+
|
|
2136
|
+
// With custom GraphQL URL and retries
|
|
2137
|
+
const moduleId = await ant.getModuleId({
|
|
2138
|
+
graphqlUrl: 'https://arweave.net/graphql',
|
|
2139
|
+
retries: 5
|
|
2140
|
+
});
|
|
2141
|
+
```
|
|
2142
|
+
|
|
2143
|
+
<details>
|
|
2144
|
+
<summary>Output</summary>
|
|
2145
|
+
|
|
2146
|
+
```json
|
|
2147
|
+
"FKtQtOOtlcWCW2pXrwWFiCSlnuewMZOHCzhulVkyqBE"
|
|
2148
|
+
```
|
|
2149
|
+
|
|
2150
|
+
</details>
|
|
2151
|
+
|
|
2152
|
+
#### `getVersion({ antRegistryId?, graphqlUrl?, retries? })`
|
|
2153
|
+
|
|
2154
|
+
Gets the version string of the current ANT by matching its module ID with versions from the ANT registry.
|
|
2155
|
+
|
|
2156
|
+
```typescript
|
|
2157
|
+
const version = await ant.getVersion();
|
|
2158
|
+
console.log(`ANT is running version: ${version}`);
|
|
2159
|
+
|
|
2160
|
+
// With custom ANT registry
|
|
2161
|
+
const version = await ant.getVersion({
|
|
2162
|
+
antRegistryId: 'custom-ant-registry-id'
|
|
2163
|
+
});
|
|
2164
|
+
```
|
|
2165
|
+
|
|
2166
|
+
<details>
|
|
2167
|
+
<summary>Output</summary>
|
|
2168
|
+
|
|
2169
|
+
```json
|
|
2170
|
+
"23"
|
|
2171
|
+
```
|
|
2172
|
+
|
|
2173
|
+
</details>
|
|
2174
|
+
|
|
2175
|
+
#### `isLatestVersion({ antRegistryId?, graphqlUrl?, retries? })`
|
|
2176
|
+
|
|
2177
|
+
Checks if the current ANT version is the latest according to the ANT registry.
|
|
2178
|
+
|
|
2179
|
+
```typescript
|
|
2180
|
+
const isLatest = await ant.isLatestVersion();
|
|
2181
|
+
if (!isLatest) {
|
|
2182
|
+
console.log('ANT can be upgraded to the latest version');
|
|
2183
|
+
}
|
|
2184
|
+
```
|
|
2185
|
+
|
|
2186
|
+
<details>
|
|
2187
|
+
<summary>Output</summary>
|
|
2188
|
+
|
|
2189
|
+
```json
|
|
2190
|
+
true
|
|
2191
|
+
```
|
|
2192
|
+
|
|
2193
|
+
</details>
|
|
2194
|
+
|
|
2128
2195
|
#### `getANTVersions`
|
|
2129
2196
|
|
|
2130
|
-
|
|
2197
|
+
Static method that returns the full array of available ANT versions and the latest version from the ANT registry.
|
|
2131
2198
|
|
|
2132
2199
|
```typescript
|
|
2133
2200
|
import { ANT } from '@ar.io/sdk';
|
|
@@ -2155,12 +2222,17 @@ Result:
|
|
|
2155
2222
|
|
|
2156
2223
|
#### `getLatestANTVersion()`
|
|
2157
2224
|
|
|
2158
|
-
|
|
2225
|
+
Static method that returns the latest ANT version from the ANT registry.
|
|
2159
2226
|
|
|
2160
2227
|
```typescript
|
|
2161
2228
|
import { ANT } from '@ar.io/sdk';
|
|
2162
2229
|
|
|
2163
2230
|
// Get the latest ANT version
|
|
2231
|
+
import { ANT } from '@ar.io/sdk';
|
|
2232
|
+
|
|
2233
|
+
// Get all available ANT versions
|
|
2234
|
+
const antVersions = ANT.versions;
|
|
2235
|
+
const versions = await antVersions.getANTVersions();
|
|
2164
2236
|
const latestVersion = await antVersions.getLatestANTVersion();
|
|
2165
2237
|
```
|
|
2166
2238
|
|
|
@@ -2307,6 +2379,40 @@ const owner = await ant.getOwner();
|
|
|
2307
2379
|
|
|
2308
2380
|
</details>
|
|
2309
2381
|
|
|
2382
|
+
#### `getName()`
|
|
2383
|
+
|
|
2384
|
+
Returns the name of the ANT (not the same as ArNS name).
|
|
2385
|
+
|
|
2386
|
+
```typescript
|
|
2387
|
+
const name = await ant.getName();
|
|
2388
|
+
```
|
|
2389
|
+
|
|
2390
|
+
<details>
|
|
2391
|
+
<summary>Output</summary>
|
|
2392
|
+
|
|
2393
|
+
```json
|
|
2394
|
+
"ArDrive"
|
|
2395
|
+
```
|
|
2396
|
+
|
|
2397
|
+
</details>
|
|
2398
|
+
|
|
2399
|
+
#### `getTicker()`
|
|
2400
|
+
|
|
2401
|
+
Returns the ticker symbol of the ANT.
|
|
2402
|
+
|
|
2403
|
+
```typescript
|
|
2404
|
+
const ticker = await ant.getTicker();
|
|
2405
|
+
```
|
|
2406
|
+
|
|
2407
|
+
<details>
|
|
2408
|
+
<summary>Output</summary>
|
|
2409
|
+
|
|
2410
|
+
```json
|
|
2411
|
+
"ANT-ARDRIVE"
|
|
2412
|
+
```
|
|
2413
|
+
|
|
2414
|
+
</details>
|
|
2415
|
+
|
|
2310
2416
|
#### `getControllers()`
|
|
2311
2417
|
|
|
2312
2418
|
Returns the controllers of the configured ANT process.
|
|
@@ -2363,6 +2469,72 @@ const records = await ant.getRecords();
|
|
|
2363
2469
|
|
|
2364
2470
|
</details>
|
|
2365
2471
|
|
|
2472
|
+
#### `getRecord({ undername })`
|
|
2473
|
+
|
|
2474
|
+
Returns a specific record by its undername.
|
|
2475
|
+
|
|
2476
|
+
```typescript
|
|
2477
|
+
const record = await ant.getRecord({ undername: 'dapp' });
|
|
2478
|
+
```
|
|
2479
|
+
|
|
2480
|
+
<details>
|
|
2481
|
+
<summary>Output</summary>
|
|
2482
|
+
|
|
2483
|
+
```json
|
|
2484
|
+
{
|
|
2485
|
+
"transactionId": "432l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM",
|
|
2486
|
+
"ttlSeconds": 900,
|
|
2487
|
+
"owner": "alice-wallet-address-123...",
|
|
2488
|
+
"displayName": "Alice's Site",
|
|
2489
|
+
"logo": "avatar-tx-id-456...",
|
|
2490
|
+
"description": "Personal portfolio and blog",
|
|
2491
|
+
"keywords": ["portfolio", "personal", "blog"]
|
|
2492
|
+
}
|
|
2493
|
+
```
|
|
2494
|
+
|
|
2495
|
+
</details>
|
|
2496
|
+
|
|
2497
|
+
### Balances
|
|
2498
|
+
|
|
2499
|
+
#### `getBalances()`
|
|
2500
|
+
|
|
2501
|
+
Returns all token balances for the ANT.
|
|
2502
|
+
|
|
2503
|
+
```typescript
|
|
2504
|
+
const balances = await ant.getBalances();
|
|
2505
|
+
```
|
|
2506
|
+
|
|
2507
|
+
<details>
|
|
2508
|
+
<summary>Output</summary>
|
|
2509
|
+
|
|
2510
|
+
```json
|
|
2511
|
+
{
|
|
2512
|
+
"ccp3blG__gKUvG3hsGC2u06aDmqv4CuhuDJGOIg0jw4": 1,
|
|
2513
|
+
"aGzM_yjralacHIUo8_nQXMbh9l1cy0aksiL_x9M359f": 0
|
|
2514
|
+
}
|
|
2515
|
+
```
|
|
2516
|
+
|
|
2517
|
+
</details>
|
|
2518
|
+
|
|
2519
|
+
#### `getBalance({ address })`
|
|
2520
|
+
|
|
2521
|
+
Returns the balance of a specific address.
|
|
2522
|
+
|
|
2523
|
+
```typescript
|
|
2524
|
+
const balance = await ant.getBalance({
|
|
2525
|
+
address: 'ccp3blG__gKUvG3hsGC2u06aDmqv4CuhuDJGOIg0jw4',
|
|
2526
|
+
});
|
|
2527
|
+
```
|
|
2528
|
+
|
|
2529
|
+
<details>
|
|
2530
|
+
<summary>Output</summary>
|
|
2531
|
+
|
|
2532
|
+
```json
|
|
2533
|
+
1
|
|
2534
|
+
```
|
|
2535
|
+
|
|
2536
|
+
</details>
|
|
2537
|
+
|
|
2366
2538
|
### Transfer
|
|
2367
2539
|
|
|
2368
2540
|
#### `transfer({ target })`
|
|
@@ -2381,14 +2553,14 @@ const { id: txId } = await ant.transfer(
|
|
|
2381
2553
|
|
|
2382
2554
|
### Controllers
|
|
2383
2555
|
|
|
2384
|
-
#### `
|
|
2556
|
+
#### `addController({ controller })`
|
|
2385
2557
|
|
|
2386
2558
|
Adds a new controller to the list of approved controllers on the ANT. Controllers can set records and change the ticker and name of the ANT process.
|
|
2387
2559
|
|
|
2388
2560
|
_Note: Requires `signer` to be provided on `ANT.init` to sign the transaction._
|
|
2389
2561
|
|
|
2390
2562
|
```typescript
|
|
2391
|
-
const { id: txId } = await ant.
|
|
2563
|
+
const { id: txId } = await ant.addController(
|
|
2392
2564
|
{ controller: 'aGzM_yjralacHIUo8_nQXMbh9l1cy0aksiL_x9M359f' },
|
|
2393
2565
|
// optional additional tags
|
|
2394
2566
|
{ tags: [{ name: 'App-Name', value: 'My-Awesome-App' }] },
|
|
@@ -2595,7 +2767,7 @@ Sets the keywords of the ANT process.
|
|
|
2595
2767
|
_Note: Requires `signer` to be provided on `ANT.init` to sign the transaction._
|
|
2596
2768
|
|
|
2597
2769
|
```typescript
|
|
2598
|
-
const { id: txId } = await ant.
|
|
2770
|
+
const { id: txId } = await ant.setKeywords(
|
|
2599
2771
|
{ keywords: ['Game', 'FPS', 'AO'] },
|
|
2600
2772
|
// optional tags
|
|
2601
2773
|
{ tags: [{ name: 'App-Name', value: 'My-Awesome-App' }] },
|
|
@@ -2841,13 +3013,60 @@ const recordAfter = await ant.getRecord({ undername: 'alice' });
|
|
|
2841
3013
|
console.log(recordAfter.owner); // undefined (controlled by ANT owner again)
|
|
2842
3014
|
```
|
|
2843
3015
|
|
|
3016
|
+
### Static Methods
|
|
3017
|
+
|
|
3018
|
+
#### `ANT.fork({ signer, antProcessId, module?, scheduler?, state?, ao?, antRegistryId?, onSigningProgress? })`
|
|
3019
|
+
|
|
3020
|
+
Forks an existing ANT process to create a new one with the same state but potentially a different module. This is used for upgrading ANTs to new versions.
|
|
3021
|
+
|
|
3022
|
+
```typescript
|
|
3023
|
+
const newProcessId = await ANT.fork({
|
|
3024
|
+
signer: new ArweaveSigner(jwk),
|
|
3025
|
+
antProcessId: 'existing-ant-process-id',
|
|
3026
|
+
// Optional: specify a specific module ID, defaults to latest from registry
|
|
3027
|
+
module: 'new-module-id',
|
|
3028
|
+
onSigningProgress: (event, payload) => {
|
|
3029
|
+
console.log(`Fork progress: ${event}`);
|
|
3030
|
+
},
|
|
3031
|
+
});
|
|
3032
|
+
|
|
3033
|
+
console.log(`Forked ANT to new process: ${newProcessId}`);
|
|
3034
|
+
```
|
|
3035
|
+
|
|
3036
|
+
#### `ANT.upgrade({ signer, antProcessId, reassignAffiliatedNames?, names?, arioProcessId?, antRegistryId?, ao?, logger?, skipVersionCheck?, onSigningProgress?, hyperbeamUrl? })`
|
|
3037
|
+
|
|
3038
|
+
Static method to upgrade an ANT by forking it to the latest version and reassigning names.
|
|
3039
|
+
|
|
3040
|
+
```typescript
|
|
3041
|
+
// Upgrade and reassign all affiliated names
|
|
3042
|
+
const result = await ANT.upgrade({
|
|
3043
|
+
signer: new ArweaveSigner(jwk),
|
|
3044
|
+
antProcessId: 'existing-ant-process-id',
|
|
3045
|
+
reassignAffiliatedNames: true,
|
|
3046
|
+
arioProcessId: ARIO_MAINNET_PROCESS_ID
|
|
3047
|
+
});
|
|
3048
|
+
|
|
3049
|
+
// Upgrade and reassign specific names
|
|
3050
|
+
const result = await ANT.upgrade({
|
|
3051
|
+
signer: new ArweaveSigner(jwk),
|
|
3052
|
+
antProcessId: 'existing-ant-process-id',
|
|
3053
|
+
names: ['ardrive', 'example'],
|
|
3054
|
+
reassignAffiliatedNames: false,
|
|
3055
|
+
arioProcessId: ARIO_MAINNET_PROCESS_ID
|
|
3056
|
+
});
|
|
3057
|
+
|
|
3058
|
+
console.log(`Upgraded to process: ${result.forkedProcessId}`);
|
|
3059
|
+
console.log(`Successfully reassigned names: ${Object.keys(result.reassignedNames)}`);
|
|
3060
|
+
console.log(`Failed reassignments: ${Object.keys(result.failedReassignedNames)}`);
|
|
3061
|
+
```
|
|
3062
|
+
|
|
2844
3063
|
## Token Conversion
|
|
2845
3064
|
|
|
2846
3065
|
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.
|
|
2847
3066
|
|
|
2848
3067
|
**All process interactions expect values in mARIO. If numbers are provided as inputs, they are assumed to be in raw mARIO values.**
|
|
2849
3068
|
|
|
2850
|
-
|
|
3069
|
+
#### Converting ARIO to mARIO
|
|
2851
3070
|
|
|
2852
3071
|
```typescript
|
|
2853
3072
|
import { ARIOToken, mARIOToken } from '@ar.io/sdk';
|
|
@@ -2863,7 +3082,7 @@ const arioValue = new mARIOToken(mARIOValue).toARIO();
|
|
|
2863
3082
|
|
|
2864
3083
|
The library uses a lightweight console logger by default for both Node.js and web environments. The logger outputs structured JSON logs with timestamps. You can configure the log level via `setLogLevel()` API or provide a custom logger that satisfies the `ILogger` interface.
|
|
2865
3084
|
|
|
2866
|
-
|
|
3085
|
+
#### Default Logger
|
|
2867
3086
|
|
|
2868
3087
|
```typescript
|
|
2869
3088
|
import { Logger } from '@ar.io/sdk';
|
|
@@ -2875,7 +3094,7 @@ Logger.default.setLogLevel('debug');
|
|
|
2875
3094
|
const logger = new Logger({ level: 'debug' });
|
|
2876
3095
|
```
|
|
2877
3096
|
|
|
2878
|
-
|
|
3097
|
+
#### Custom Logger Implementation
|
|
2879
3098
|
|
|
2880
3099
|
You can provide any custom logger that implements the `ILogger` interface:
|
|
2881
3100
|
|
|
@@ -2894,15 +3113,18 @@ const customLogger: ILogger = {
|
|
|
2894
3113
|
};
|
|
2895
3114
|
|
|
2896
3115
|
// Use custom logger with any class
|
|
2897
|
-
const ario =
|
|
3116
|
+
const ario = ARIO.mainnet({ logger: customLogger });
|
|
3117
|
+
|
|
3118
|
+
// or set it as the default logger in the entire SDK
|
|
3119
|
+
Logger.default = customLogger;
|
|
2898
3120
|
```
|
|
2899
3121
|
|
|
2900
|
-
|
|
3122
|
+
#### Winston Logger (Optional)
|
|
2901
3123
|
|
|
2902
3124
|
For advanced logging features, you can optionally install Winston and use the provided Winston logger adapter:
|
|
2903
3125
|
|
|
2904
3126
|
```bash
|
|
2905
|
-
|
|
3127
|
+
yarn add winston
|
|
2906
3128
|
```
|
|
2907
3129
|
|
|
2908
3130
|
```typescript
|
|
@@ -2914,10 +3136,13 @@ const winstonLogger = new WinstonLogger({
|
|
|
2914
3136
|
});
|
|
2915
3137
|
|
|
2916
3138
|
// Use with any class that accepts a logger
|
|
2917
|
-
const ario =
|
|
3139
|
+
const ario = ARIO.mainnet({ logger: winstonLogger });
|
|
3140
|
+
|
|
3141
|
+
// or set it as the default logger in the entire SDK
|
|
3142
|
+
Logger.default = winstonLogger;
|
|
2918
3143
|
```
|
|
2919
3144
|
|
|
2920
|
-
|
|
3145
|
+
#### Other Popular Loggers
|
|
2921
3146
|
|
|
2922
3147
|
You can easily integrate other popular logging libraries:
|
|
2923
3148
|
|
|
@@ -2935,12 +3160,15 @@ const adapter: ILogger = {
|
|
|
2935
3160
|
setLogLevel: (level) => bunyanLogger.level(level),
|
|
2936
3161
|
};
|
|
2937
3162
|
|
|
2938
|
-
const ario =
|
|
3163
|
+
const ario = ARIO.mainnet({ logger: adapter });
|
|
3164
|
+
|
|
3165
|
+
// or set it as the default logger in the entire SDK
|
|
3166
|
+
Logger.default = adapter;
|
|
2939
3167
|
```
|
|
2940
3168
|
|
|
2941
3169
|
## Pagination
|
|
2942
3170
|
|
|
2943
|
-
|
|
3171
|
+
#### Overview
|
|
2944
3172
|
|
|
2945
3173
|
Certain APIs that could return a large amount of data are paginated using cursors. The SDK uses the `cursor` pattern (as opposed to pages) to better protect against changing data while paginating through a list of items. For more information on pagination strategies refer to [this article](https://www.getknit.dev/blog/api-pagination-best-practices#api-pagination-techniques-).
|
|
2946
3174
|
|
|
@@ -2967,7 +3195,7 @@ while (hasMore) {
|
|
|
2967
3195
|
}
|
|
2968
3196
|
```
|
|
2969
3197
|
|
|
2970
|
-
|
|
3198
|
+
#### Filtering
|
|
2971
3199
|
|
|
2972
3200
|
Paginated APIs also support filtering by providing a `filters` parameter. Filters can be applied to any field in the response. When multiple keys are provided, they are treated as AND conditions (all conditions must match). When multiple values are provided for a single key (as an array), they are treated as OR conditions (any value can match).
|
|
2973
3201
|
|