-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(init): Remove connect workflow and create factory init method #33
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
68b555a
chore(connect): update connect workflow
beb8610
fix(mixin): filter private methods in mixin util
765f39c
fix(connect): add init static function on ario class to create intera…
8458185
fix(tests): add test cases as a const
c7860ed
fix(exports): add arweavesigner and arconnectsigner to exports, clean…
e3c97e9
fix(overloads): only accept warp contract as a contract config for ar…
e9985dd
fix(types): update tests, readme, and types
ad9bc56
fix(contract functions): correct contract function names
059653c
fix(tests): update client instantiation test to check read vs write c…
b68ad02
chore(readme): update init description
atticusofsparta 2a0a38b
chore(readme): abreviate description of ariowritable
atticusofsparta f64c97f
chore(readme): comment for ariowritable describing apis
atticusofsparta 26b9f53
chore(tests): add arIoWritable tests and testing for write functions …
d324158
chore(tests): add more testing coverage
977312a
chore(readme): update readme examples and comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ This is the home of [ar.io] SDK. This SDK provides functionality for interacting | |
- [Typescript](#typescript) | ||
- [ArIO Contract](#ario-contract) | ||
- [APIs](#apis) | ||
- [connect](#connectsigner) | ||
- [init](#init-signer) | ||
- [getBalance](#getbalance-address-evaluationoptions-) | ||
- [getBalances](#getbalances-evaluationoptions-) | ||
- [getGateway](#getgateway-address-evaluationoptions-) | ||
|
@@ -66,7 +66,7 @@ yarn add @ar-io/sdk | |
```typescript | ||
import { ArIO } from '@ar-io/sdk'; | ||
|
||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const gateways = arIO.getGateways(); | ||
|
||
// outputs: | ||
|
@@ -123,7 +123,7 @@ The SDK is provided in both CommonJS and ESM formats and is compatible with bund | |
import { ArIO } from '@ar-io/sdk'; | ||
|
||
// set up client | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
// fetch gateways | ||
const gateways = arIO.getGateways(); | ||
``` | ||
|
@@ -135,7 +135,7 @@ const gateways = arIO.getGateways(); | |
import { ArIO } from 'https://unpkg.com/@ar-io/sdk'; | ||
|
||
// set up client | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
// fetch gateways | ||
const gateways = await arIO.getGateways(); | ||
</script> | ||
|
@@ -149,7 +149,7 @@ const gateways = arIO.getGateways(); | |
import { ArIO } from '@ar-io/sdk/node'; | ||
|
||
// set up client | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
// fetch gateways | ||
const gateways = await arIO.getGateways(); | ||
``` | ||
|
@@ -160,7 +160,7 @@ const gateways = await arIO.getGateways(); | |
import { ArIO } from '@ar-io/sdk'; | ||
|
||
// set up client | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
// fetch gateways | ||
const gateways = await arIO.getGateways(); | ||
``` | ||
|
@@ -173,29 +173,29 @@ The SDK provides TypeScript types. When you import the SDK in a TypeScript proje | |
|
||
### APIs | ||
|
||
#### `connect(signer)` | ||
|
||
Connects an `ArweaveSigner` or `ArConnectSigner` instance to the client for performing `writeInteraction` calls. | ||
Supported only on clients configured with a `WarpContract` instance. | ||
#### `init({ signer })` | ||
|
||
NOTE: if you have a client configured with a `RemoteContract` instance, it will be overriden with a `WarpContract` instance using the existing configuration of the `RemoteContract` instance when `connect` is executed. | ||
Factory function to that creates a read-only or writeabe client. By providing a `signer` additional write APIs that require signing, like `joinNetwork` and `delegateStake` are available. By default, a read-only client is returned and no write APIs are available. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
dtfiedler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// read-only client that has access to all read APIs | ||
const arIOReadable = ArIO.init() | ||
|
||
const browserSigner = new ArConnectSigner(window.arweaveWallet); | ||
arIO.connect(browserSigner); | ||
const arIOWriteable = ArIO.init({ signer: browserSigner}); | ||
|
||
const nodeSigner = new ArweaveSigner(JWK); | ||
arIO.connect(nodeSigner); | ||
// read and write client that has access to all APIs | ||
const arIOWriteable = ArIO.init({ signer: nodeSigner}); | ||
atticusofsparta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
|
||
#### `getBalance({ address, evaluationOptions })` | ||
|
||
Retrieves the balance of the specified wallet address. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const balance = arIO.getBalance({ | ||
address: 'INSERT_WALLET_ADDRESS', | ||
}); | ||
|
@@ -214,7 +214,7 @@ Retrieves the balances of the ArIO contract. | |
--> | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const balances = arIO.getBalances(); | ||
|
||
// outputs: | ||
|
@@ -232,7 +232,7 @@ const balances = arIO.getBalances(); | |
Retrieves a gateway's info by its staking wallet address. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const gateway = arIO.getGateway({ | ||
address: 'INSERT_GATEWAY_ADDRESS', | ||
}); | ||
|
@@ -277,7 +277,7 @@ const gateway = arIO.getGateway({ | |
Retrieves the registered gateways of the ArIO contract. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const gateways = arIO.getGateways(); | ||
|
||
// outputs: | ||
|
@@ -327,7 +327,7 @@ const gateways = arIO.getGateways(); | |
Retrieves the record info of the specified ArNS name. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const record = arIO.getArNSRecord({ domain: 'ardrive' }); | ||
|
||
// outputs | ||
|
@@ -346,7 +346,7 @@ const record = arIO.getArNSRecord({ domain: 'ardrive' }); | |
Retrieves all registered ArNS records of the ArIO contract. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const records = arIO.getArNSRecords(); | ||
|
||
// outputs: | ||
|
@@ -375,7 +375,7 @@ const records = arIO.getArNSRecords(); | |
Returns the epoch-indexed observation list. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const observations = await arIO.getObservations(); | ||
|
||
// output | ||
|
@@ -399,7 +399,7 @@ const observations = await arIO.getObservations(); | |
Returns the current rewards distribution information. The resulting object is pruned, to get older distributions use the `evaluationOptions` to `evalTo` a previous state. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const distributions = await arIO.getDistributions(); | ||
|
||
// output | ||
|
@@ -418,7 +418,7 @@ const distributions = await arIO.getDistributions(); | |
Returns the epoch data for the specified block height. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const epoch = await arIO.getEpoch({ blockHeight: 1382230 }); | ||
|
||
// output | ||
|
@@ -438,7 +438,7 @@ const epoch = await arIO.getEpoch({ blockHeight: 1382230 }); | |
Returns the current epoch data. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const epoch = await arIO.getCurrentEpoch(); | ||
|
||
// output | ||
|
@@ -458,7 +458,7 @@ const epoch = await arIO.getCurrentEpoch(); | |
Retrieves the prescribed observers of the ArIO contract. To fetch prescribed observers for a previous epoch set the `evaluationOptions` to the desired epoch. | ||
|
||
```typescript | ||
const arIO = new ArIO(); | ||
const arIO = ArIO.init(); | ||
const observers = arIO.getPrescribedObservers(); | ||
|
||
// outputs: | ||
|
@@ -569,7 +569,7 @@ const auctions = await arIO.getAuctions({ evaluationOptions }); | |
// } | ||
``` | ||
|
||
#### `joinNetwork({ ...JoinNetworkParams})` | ||
#### `joinNetwork(params) ~ Requires signer during init()` | ||
|
||
Joins a gateway to the ar.io network via its associated wallet. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add that this requires |
||
|
||
|
@@ -592,8 +592,8 @@ const jointNetworkParams = { | |
protocol: 'https', | ||
}; | ||
const signer = new ArweaveSigner(jwk); | ||
// connection required for write interactions | ||
const authenticatedArIO = arIO.connect(signer); | ||
// signer required for write interactions APIs | ||
const authenticatedArIO = ArIO.init({ signer }); | ||
dtfiedler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const joinNetworkTx = await authenticatedArIO.joinNetwork(joinNetworkParams); | ||
|
||
// joinNetworkTx is an Arweave transaction. | ||
|
@@ -602,28 +602,29 @@ const joinNetworkTx = await authenticatedArIO.joinNetwork(joinNetworkParams); | |
// t4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3 | ||
``` | ||
|
||
#### `updateGatewaySettings({ ...UpdateGatewaySettingsParams})` | ||
#### `updateGatewaySettings(gatewaySettings) ~ Requires signer during init()` | ||
|
||
Writes new gateway settings to the callers gateway configuration. | ||
|
||
```typescript | ||
const params = { | ||
const updateGatewaySettingsParams = { | ||
minDelegatedStake: 100, | ||
}; | ||
|
||
const signer = new ArweaveSigner(jwk); | ||
// connection required for write interactions | ||
const authenticatedArIO = arIO.connect(signer); | ||
const updateGatewaySettingsTx = | ||
await authenticatedArIO.updateGatewaySettings(params); | ||
// signer required for write interactions APIs | ||
const authenticatedArIO = ArIO.init({ signer }); | ||
const updateGatewaySettingsTx = await authenticatedArIO.updateGatewaySettings( | ||
updateGatewaySettingsParams, | ||
); | ||
|
||
// updateGatewaySettingsTx is an Arweave transaction. | ||
// example: | ||
// updateGatewaySettingsTx.id | ||
// t4Xr0_J4Iurt7caNST02cMotaz2FIbWQ4Kbj616RHl3 | ||
``` | ||
|
||
#### `increaseDelegateStake({ target, qty })` | ||
#### `increaseDelegateStake({ target, qty }) ~ Requires signer during init()` | ||
|
||
Increases the callers stake on the target gateway. | ||
|
||
|
@@ -634,8 +635,8 @@ const params = { | |
}; | ||
|
||
const signer = new ArweaveSigner(jwk); | ||
// connection required for write interactions | ||
const authenticatedArIO = arIO.connect(signer); | ||
// signer required for write interactions APIs | ||
const authenticatedArIO = ArIO.init({ signer }); | ||
dtfiedler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const increaseDelegateStakeTx = | ||
await authenticatedArIO.increaseDelegateStake(params); | ||
|
||
|
@@ -645,7 +646,7 @@ const increaseDelegateStakeTx = | |
// fDrr0_J4Iurt7caNST02cMotaz2FIbWQ4Kcj616RHl3 | ||
``` | ||
|
||
#### `decreaseDelegateStake({ target, qty })` | ||
#### `decreaseDelegateStake({ target, qty }) ~ Requires signer during init()` | ||
|
||
Decreases the callers stake on the target gateway. | ||
|
||
|
@@ -656,8 +657,8 @@ const params = { | |
}; | ||
|
||
const signer = new ArweaveSigner(jwk); | ||
// connection required for write interactions | ||
const authenticatedArIO = arIO.connect(signer); | ||
// signer required for write interactions APIs | ||
const authenticatedArIO = ArIO.init({ signer }); | ||
const decreaseDelegateStakeTx = | ||
await authenticatedArIO.decreaseDelegateStake(params); | ||
|
||
|
@@ -667,7 +668,7 @@ const decreaseDelegateStakeTx = | |
// fDrr0_J4Iurt7caNST02cMotaz2FIbWQ4Kcj616RHl3 | ||
``` | ||
|
||
#### `increaseOperatorStake({ qty })` | ||
#### `increaseOperatorStake({ qty }) ~ Requires signer during init()` | ||
|
||
Increases the callers operator stake. Must be executed with a wallet registered as a gateway operator. | ||
|
||
|
@@ -677,8 +678,8 @@ const params = { | |
}; | ||
|
||
const signer = new ArweaveSigner(jwk); | ||
// connection required for write interactions | ||
const authenticatedArIO = arIO.connect(signer); | ||
// signer required for write interactions APIs | ||
const authenticatedArIO = ArIO.init({ signer }); | ||
const increaseOperatorStakeTx = | ||
await authenticatedArIO.increaseOperatorStake(params); | ||
|
||
|
@@ -688,7 +689,7 @@ const increaseOperatorStakeTx = | |
// fDrr0_J4Iurt7caNST02cMotaz2FIbWQ4Kcj616RHl3 | ||
``` | ||
|
||
#### `decreaseOperatorStake({ qty })` | ||
#### `decreaseOperatorStake({ qty }) ~ Requires signer during init()` | ||
|
||
Decreases the callers operator stake. Must be executed with a wallet registered as a gateway operator. | ||
|
||
|
@@ -698,8 +699,8 @@ const params = { | |
}; | ||
|
||
const signer = new ArweaveSigner(jwk); | ||
// connection required for write interactions | ||
const authenticatedArIO = arIO.connect(signer); | ||
// signer required for write interactions APIs | ||
const authenticatedArIO = ArIO.init({ signer }); | ||
const decreaseOperatorStakeTx = | ||
await authenticatedArIO.decreaseOperatorStake(params); | ||
|
||
|
@@ -715,19 +716,19 @@ The ArIO contract client class exposes APIs relevant to the ar.io contract. It c | |
|
||
```typescript | ||
// provide a custom contractTxId to the client and default to remote evaluation | ||
const remoteCustomArIO = new ArIO({ | ||
const remoteCustomArIO = ArIO.init({ | ||
contractTxId: 'TESTNET_CONTRACT_TX_ID', | ||
}); | ||
|
||
// provide a custom contract to the client, and specify local evaluation using warp | ||
const localCustomArIO = new ArIO({ | ||
const localCustomArIO = ArIO.init({ | ||
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({ | ||
const remoteCacheCustomArIO = ArIO.init({ | ||
contract: new RemoteContract<ArIOState>({ | ||
contractTxId: 'TESTNET_CONTRACT_TX_ID', | ||
}), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the comment below - mention that signer is optional. and if provided
ArIOWriteable
class is returned that supports write interaction APIs; otherwise anArIOReadable
class is returned and supports read apis only.