Skip to content

Commit

Permalink
chore(docs): update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Aug 7, 2024
1 parent d618458 commit bb826d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 62 deletions.
18 changes: 12 additions & 6 deletions examples/cjs/index.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const { IO, ioDevnetProcessId, Logger } = require('@ar.io/sdk');
const {
IO,
ioDevnetProcessId,
Logger,
IO_TESTNET_PROCESS_ID,
} = require('@ar.io/sdk');

(async () => {
// set the log level for the SDK
Expand All @@ -8,9 +13,13 @@ const { IO, ioDevnetProcessId, Logger } = require('@ar.io/sdk');
// testnet gateways
const testnetGateways = await arIO.getGateways();
const protocolBalance = await arIO.getBalance({
address: ioDevnetProcessId,
address: IO_TESTNET_PROCESS_ID,
});
const ardriveRecord = await arIO.getArNSRecord({ name: 'ardrive' });
const partialRecords = await arIO.getArNSRecords({
page: 10,
pageSize: 5,
});
const oldEpoch = await arIO.getEpoch({
epochIndex: 0,
});
Expand All @@ -23,11 +32,8 @@ const { IO, ioDevnetProcessId, Logger } = require('@ar.io/sdk');
{
testnetGateways,
ardriveRecord,
partialRecords: partialRecords.items,
protocolBalance,
arnsStats: {
'registered domains': Object.keys(allRecords).length,
ardrive: allRecords.ardrive,
},
oldEpoch,
epoch,
observations,
Expand Down
73 changes: 17 additions & 56 deletions examples/esm/index.mjs
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
import {
ANT,
ArNSEventEmitter,
ArweaveSigner,
IO,
createAoSigner,
ioDevnetProcessId,
spawnANT,
IO_TESTNET_PROCESS_ID,
getANTProcessesOwnedByWallet,
} from '@ar.io/sdk';
import Arweave from 'arweave';

(async () => {
const arIO = IO.init({
processId: ioDevnetProcessId,
});
// devnet gateways
const arIO = IO.init();
const testnetGateways = await arIO.getGateways();
const protocolBalance = await arIO.getBalance({
address: ioDevnetProcessId,
address: IO_TESTNET_PROCESS_ID,
});
const contractInfo = await arIO.getInfo();
const ardriveRecord = await arIO.getArNSRecord({ name: 'ardrive' });
const allRecords = await arIO.getArNSRecords();
const partialRecords = await arIO.getArNSRecords();
const epoch = await arIO.getCurrentEpoch();
const currentObservations = await arIO.getObservations();
const observations = await arIO.getObservations({ epochIndex: 19879 });
const distributions = await arIO.getDistributions({ epochIndex: 19879 });
const observations = await arIO.getObservations({ epochIndex: 0 });
const distributions = await arIO.getDistributions({ epochIndex: 0 });
const buyRecordCost = await arIO.getTokenCost({
intent: 'Buy-Record',
purchaseType: 'lease',
name: 'adriaaaaan',
name: 'ar-io-dapp-record',
years: 1,
});
const extendLeaseCost = await arIO.getTokenCost({
Expand All @@ -38,7 +31,7 @@ import Arweave from 'arweave';
});
const increaseUndernameCost = await arIO.getTokenCost({
intent: 'Increase-Undername-Limit',
name: 'vilenario',
name: 'ao',
quantity: 1,
});

Expand All @@ -52,33 +45,21 @@ import Arweave from 'arweave';
observations,
distributions,
protocolBalance,
names: Object.keys(allRecords),
records: partialRecords.items,
buyRecordCost,
extendLeaseCost,
increaseUndernameCost,
},
{ depth: 2 },
);

// io ant
const arweave = Arweave.init({
host: 'arweave.net',
port: 443,
protocol: 'https',
// fetching ants owned by a wallet using an event emitter
const address = 'ZjmB2vEUlHlJ7-rgJkYP09N5IzLPhJyStVrK5u9dDEo';
const affiliatedAnts = await getANTProcessesOwnedByWallet({
address,
});

const jwk = await arweave.wallets.generate();
let processId;
try {
processId = await spawnANT({
signer: createAoSigner(new ArweaveSigner(jwk)),
});
} catch (error) {
console.log(error);
}

const ant = ANT.init({
processId,
processId: affiliatedAnts[0],
});
const antRecords = await ant.getRecords();
const rootRecord = await ant.getRecord({ undername: '@' });
Expand All @@ -87,6 +68,8 @@ import Arweave from 'arweave';
const info = await ant.getInfo();
console.dir(
{
affiliatedAnts,
antProcessId: affiliatedAnts[0],
antRecords,
rootRecord,
controllers,
Expand All @@ -95,26 +78,4 @@ import Arweave from 'arweave';
},
{ depth: 2 },
);

// fetching ants owned by a wallet using an event emitter
const address = 'ZjmB2vEUlHlJ7-rgJkYP09N5IzLPhJyStVrK5u9dDEo';
const processEmitter = new ArNSEventEmitter({ contract: arIO });
processEmitter.on('error', (e) => {
console.error(e);
});
processEmitter.on('process', (processId, antState) =>
console.log(
`Discovered process owned by wallet called "${antState.names}": `,
processId,
),
);
processEmitter.on('end', (res) => {
console.log(
'Complete',
`${Object.keys(res).length} ids checked with ${antsInError} ants in error.`,
);
});

// kick off the retrieval of ants owned by a process
processEmitter.fetchProcessesOwnedByWallet({ address });
})();

0 comments on commit bb826d5

Please sign in to comment.