Skip to content

Commit

Permalink
Merge branch 'alpha' into PE-5758
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta authored Mar 20, 2024
2 parents 18f2b58 + da0df51 commit 79fe9f8
Show file tree
Hide file tree
Showing 6 changed files with 344 additions and 79 deletions.
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn format:fix
yarn lint
yarn lint-staged
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# [1.0.0-alpha.9](https://github.com/ar-io/ar-io-sdk/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2024-03-18)


### Bug Fixes

* **ario:** re-add contract default config ([2296cc3](https://github.com/ar-io/ar-io-sdk/commit/2296cc3e152c136e2df45481340a625a80a0be3f))
* **build:** remove redundant exported type ([134319b](https://github.com/ar-io/ar-io-sdk/commit/134319b8707cd479dc91d6832bf078bdb5c5e886))
* **readme:** update ant header ([77235ce](https://github.com/ar-io/ar-io-sdk/commit/77235ce077ef4a12dfa6b403968b6ab148ebf196))
* **readme:** update ANT usage description ([70c8520](https://github.com/ar-io/ar-io-sdk/commit/70c852087f75a17c494cc12719d1dc9f96da39f2))
* **signer:** remove signer, will do in other pr ([d02276d](https://github.com/ar-io/ar-io-sdk/commit/d02276dd9fa166d254eb76a45e2c6025f632c0ba))
* **types:** add @ to records ([53601c1](https://github.com/ar-io/ar-io-sdk/commit/53601c1d08f7bf3e522f25b58e514b0c809ad195))
* **types:** remove any types ([d8d910b](https://github.com/ar-io/ar-io-sdk/commit/d8d910b9f2d0b95232ccf3c52e74f57b086df435))
* **types:** use string instead of any ([014a262](https://github.com/ar-io/ar-io-sdk/commit/014a26210b2482b3aa5150b4fd37925760f39dd8))


### Features

* **ant:** add ANT read interface ([c941c96](https://github.com/ar-io/ar-io-sdk/commit/c941c96cd201983270cc9e04c0fcaa5b4dc3b798))
* **PE-5825:** ANT read interface ([#19](https://github.com/ar-io/ar-io-sdk/issues/19)) ([6a0c477](https://github.com/ar-io/ar-io-sdk/commit/6a0c47754689071d292eaebfa7b3af6c8e851fa4))

# [1.0.0-alpha.8](https://github.com/ar-io/ar-io-sdk/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2024-03-15)


Expand Down
178 changes: 130 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@ This is the home of [ar.io] SDK. This SDK provides functionality for interacting
- [NodeJS Environments](#node)
- [Web Environments](#web)
- [Typescript](#typescript)
- [APIs](#apis)
- [getBalance](#getbalance-address-evaluationoptions-)
- [getBalances](#getbalances-evaluationoptions-)
- [getGateway](#getgateway-address-evaluationoptions-)
- [getGateways](#getgateways-evaluationoptions-)
- [getArNSRecord](#getarnsrecord-domain-evaluationoptions-)
- [getArNSRecords](#getarnsrecords-evaluationoptions-)
- [ArIO Contract](#ario-contract)
- [APIs](#apis)
- [getBalance](#getbalance-address-evaluationoptions-)
- [getBalances](#getbalances-evaluationoptions-)
- [getGateway](#getgateway-address-evaluationoptions-)
- [getGateways](#getgateways-evaluationoptions-)
- [getArNSRecord](#getarnsrecord-domain-evaluationoptions-)
- [getArNSRecords](#getarnsrecords-evaluationoptions-)
- [getObservations](#getobservations-evaluationoptions-)
- [getDistributions](#getdistributions-evaluationoptions-)
- [getEpoch](#getepoch-evaluationoptions-)
- [getCurrentEpoch](#getcurrentepoch-evaluationoptions-)
- [getPrescribedObservers](#getprescribedobservers-evaluationoptions-)
- [getAuction](#getauction-domain-evaluationoptions-)
- [getAuctions](#getauctions-evauluationoptions-)
- [Custom Contracts](#custom-contracts)
- [ANT Contracts](#arweave-name-tokens-ants)
- [APIs](#apis-1)
- [getRecords](#getrecords-evaluationoptions-)
- [getOwner](#getowner-evaluationoptions-)
- [getControllers](#getcontrollers-evaluationoptions-)
- [Configuration](#configuration)
- [Examples](./examples)
- [Developers](#developers)
- [Requirements](#requirements)
Expand Down Expand Up @@ -126,48 +141,37 @@ const gateways = arIO.getGateways();

#### Node

##### ESM (NodeNext)

```javascript
const { ArIO } = require('@ar-io/sdk');
import { ArIO } from '@ar-io/sdk/node';

// set up client
const arIO = new ArIO();
// fetch gateways
const gateways = await arIO.getGateways();
```

## Typescript

The SDK provides TypeScript types. When you import the SDK in a TypeScript project types are exported from `./lib/types/[node/web]/index.d.ts` and should be automatically recognized by package managers, offering benefits such as type-checking and autocompletion.

## Configuration
##### CJS

### Custom Contracts
```javascript
import { ArIO } from '@ar-io/sdk';

The ArIO contract client class exposes APIs relevant to the ar.io contract. It can be configured to use any contract ID that adheres to the spec of the ar.io contract. In the default case, it will automatically build and utilize a contract data provider interface that is configured to point the the known mainnet contract ID at construction time. You can provide custom contract data provider or, alternatively, a `contractTxId` to the ArIO constructor to use a different, ar.io-spec-compatible contract.
// set up client
const arIO = new ArIO();
// fetch gateways
const gateways = await arIO.getGateways();
```

```typescript
// provide a custom contractTxId to the client and default to remote evaluation
const remoteCustomArIO = new ArIO({
contractTxId: 'TESTNET_CONTRACT_TX_ID',
});
## Typescript

// provide a custom contract to the client, and specify local evaluation using warp
const localCustomArIO = new ArIO({
contract: new WarpContract<ArIOState>({
contractTxId: 'TESTNET_CONTRACT_TX_ID',
}),
});
The SDK provides TypeScript types. When you import the SDK in a TypeScript project types are exported from `./lib/types/[node/web]/index.d.ts` and should be automatically recognized by package managers, offering benefits such as type-checking and autocompletion.

// provide a custom contract to the client, and specify local evaluation using remote cache
const remoteCacheCustomArIO = new ArIO({
contract: new RemoteContract<ArIOState>({
contractTxId: 'TESTNET_CONTRACT_TX_ID',
}),
});
```
## ArIO Contract

## APIs
### APIs

### `getBalance({ address, evaluationOptions })`
#### `getBalance({ address, evaluationOptions })`

Retrieves the balance of the specified wallet address.

Expand All @@ -180,7 +184,7 @@ const balance = arIO.getBalance({
// outputs: 0
```

### `getBalances({ evaluationOptions })`
#### `getBalances({ evaluationOptions })`

Retrieves the balances of the ArIO contract.

Expand All @@ -204,7 +208,7 @@ const balances = arIO.getBalances();
// }
```

### `getGateway({ address, evaluationOptions })`
#### `getGateway({ address, evaluationOptions })`

Retrieves a gateway's info by its staking wallet address.

Expand Down Expand Up @@ -249,7 +253,7 @@ const gateway = arIO.getGateway({
// }
```

### `getGateways({ evaluationOptions })`
#### `getGateways({ evaluationOptions })`

Retrieves the registered gateways of the ArIO contract.

Expand Down Expand Up @@ -299,7 +303,7 @@ const gateways = arIO.getGateways();
// }
```

### `getArNSRecord({ domain, evaluationOptions })`
#### `getArNSRecord({ domain, evaluationOptions })`

Retrieves the record info of the specified ArNS name.

Expand All @@ -318,7 +322,7 @@ const record = arIO.getArNSRecord({ domain: 'ardrive' });
// }
```

### `getArNSRecords({ evaluationOptions })`
#### `getArNSRecords({ evaluationOptions })`

Retrieves all registered ArNS records of the ArIO contract.

Expand Down Expand Up @@ -347,7 +351,7 @@ const records = arIO.getArNSRecords();
// }
```

### `getObservations({ evaluationOptions })`
#### `getObservations({ evaluationOptions })`

Returns the epoch-indexed observation list.

Expand All @@ -371,7 +375,7 @@ const observations = await arIO.getObservations();
// }
```

### `getDistributions({ evaluationOptions })`
#### `getDistributions({ evaluationOptions })`

Returns the current rewards distribution information. The resulting object is pruned, to get older distributions use the `evaluationOptions` to `evalTo` a previous state.

Expand All @@ -390,7 +394,7 @@ const distributions = await arIO.getDistributions();
// }
```

### `getEpoch({ evaluationOptions })`
#### `getEpoch({ evaluationOptions })`

Returns the epoch data for the specified block height.

Expand All @@ -410,7 +414,7 @@ const epoch = await arIO.getEpoch({ blockHeight: 1382230 });
// }
```

### `getCurrentEpoch({ evaluationOptions })`
#### `getCurrentEpoch({ evaluationOptions })`

Returns the current epoch data.

Expand All @@ -430,7 +434,7 @@ const epoch = await arIO.getCurrentEpoch();
// }
```

### `getPrescribedObservers({ evaluationOptions })`
#### `getPrescribedObservers({ evaluationOptions })`

Retrieves the prescribed observers of the ArIO contract. To fetch prescribed observers for a previous epoch set the `evaluationOptions` to the desired epoch.

Expand Down Expand Up @@ -480,7 +484,7 @@ const previousEpochObservers = arIO.getPrescribedObservers({
// ]
```

### `getAuction({ domain, evaluationOptions })`
#### `getAuction({ domain, evaluationOptions })`

Return the auction info for the supplied domain, be it in auction, registered, or available to auction.

Expand Down Expand Up @@ -515,7 +519,7 @@ const auction = await arIO.getAuction({ domain });
// }
```

### `getAuctions({ evauluationOptions })`
#### `getAuctions({ evauluationOptions })`

Retrieves all active auctions.

Expand Down Expand Up @@ -546,11 +550,62 @@ const auctions = await arIO.getAuctions({ evaluationOptions });
// }
```

### Custom Contracts

The ArIO contract client class exposes APIs relevant to the ar.io contract. It can be configured to use any contract ID that adheres to the spec of the ar.io contract. In the default case, it will automatically build and utilize a contract data provider interface that is configured to point the the known mainnet contract ID at construction time. You can provide custom contract data provider or, alternatively, a `contractTxId` to the ArIO constructor to use a different, ar.io-spec-compatible contract.

```typescript
// provide a custom contractTxId to the client and default to remote evaluation
const remoteCustomArIO = new ArIO({
contractTxId: 'TESTNET_CONTRACT_TX_ID',
});

// provide a custom contract to the client, and specify local evaluation using warp
const localCustomArIO = new ArIO({
contract: new WarpContract<ArIOState>({
contractTxId: 'TESTNET_CONTRACT_TX_ID',
}),
});

// provide a custom contract to the client, and specify local evaluation using remote cache
const remoteCacheCustomArIO = new ArIO({
contract: new RemoteContract<ArIOState>({
contractTxId: 'TESTNET_CONTRACT_TX_ID',
}),
});
```

## Arweave Name Tokens (ANT's)

The ANT contract client class exposes APIs relevant to compliant Arweave Name Token contracts. It can be configured to use any contract ID that adheres to the ANT contract spec. You must provide either a custom contract data provider or a contractTxId to the ANT class constructor to use.

### `getRecords({ evaluationOptions })`
### APIs

#### `getOwner({ evaluationOptions })`

Returns the owner of the configured ANT contract.

```typescript
const contractTxId = 'bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM';
const ant = new ANT({ contractTxId });
const owner = await ant.getOwner();

// output: "bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM"
```

#### `getControllers({ evaluationOptions })`

Returns the controllers of the configured ANT contract.

```typescript
const contractTxId = 'bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM';
const ant = new ANT({ contractTxId });
const controllers = await ant.getControllers();

// output: ["bh9l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM"]
```

#### `getRecords({ evaluationOptions })`

Returns all records on the configured ANT contract, including the required `@` record that resolve connected ArNS names.

Expand All @@ -572,6 +627,33 @@ const records = await ANT.getRecords();
// }
```

### Configuration

ANT clients can be configured to use custom contract evaluator. By default they will use the remote evaluator that leverages the [arns-service].

```typescript
// provide a contractTxId to the client and default to remote evaluation
const remoteANT = new ANT({
contractTxId: 'ANT_CONTRACT_TX_ID',
});

// provide a custom contract to the client, and specify local evaluation using warp
const warpEvaluatedANT = new ANT({
contract: new WarpContract<ANTState>({
contractTxId: 'ANT_CONTRACT_TX_ID',
}),
});

// provide a custom contract to the client, and specify local evaluation using remote cache
const remoteANTContract = new ANT({
contract: new RemoteContract<ANTState>({
contractTxId: 'ANT_CONTRACT_TX_ID',
// the remote api that returns warp compliant contract evaluation
url: 'https://api.arns.app/v1/contract',
}),
});
```

## Developers

### Requirements
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ar.io/sdk",
"version": "1.0.0-alpha.8",
"version": "1.0.0-alpha.9",
"repository": {
"type": "git",
"url": "git+https://github.com/ar-io/ar-io-sdk.git"
Expand Down Expand Up @@ -102,6 +102,7 @@
"http-server": "^14.1.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^15.2.2",
"prettier": "^3.0.2",
"rimraf": "^5.0.1",
"semantic-release": "^21.0.7",
Expand All @@ -117,5 +118,10 @@
"setimmediate": "^1.0.5",
"warp-contracts": "^1.4.38",
"winston": "^3.11.0"
},
"lint-staged": {
"**/*.{ts,js,mjs,cjs,md,json}": [
"prettier --write ."
]
}
}
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

// AUTOMATICALLY GENERATED FILE - DO NOT TOUCH

export const version = '1.0.0-alpha.8';
export const version = '1.0.0-alpha.9';
Loading

0 comments on commit 79fe9f8

Please sign in to comment.