From 9d15237f59d787c8e9f5e3d4fc75d3fe1c8fedbb Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Tue, 6 Aug 2024 19:04:44 -0600 Subject: [PATCH] chore(docs): update examples --- examples/cjs/index.cjs | 13 ++++---- examples/esm/index.mjs | 73 ++++++++++-------------------------------- 2 files changed, 24 insertions(+), 62 deletions(-) diff --git a/examples/cjs/index.cjs b/examples/cjs/index.cjs index 47207a0d..813665d0 100644 --- a/examples/cjs/index.cjs +++ b/examples/cjs/index.cjs @@ -1,4 +1,4 @@ -const { IO, ioDevnetProcessId, Logger } = require('@ar.io/sdk'); +const { IO, Logger, IO_TESTNET_PROCESS_ID } = require('@ar.io/sdk'); (async () => { // set the log level for the SDK @@ -8,9 +8,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, }); @@ -23,11 +27,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, diff --git a/examples/esm/index.mjs b/examples/esm/index.mjs index c6e7a881..7d6eead8 100644 --- a/examples/esm/index.mjs +++ b/examples/esm/index.mjs @@ -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({ @@ -38,7 +31,7 @@ import Arweave from 'arweave'; }); const increaseUndernameCost = await arIO.getTokenCost({ intent: 'Increase-Undername-Limit', - name: 'vilenario', + name: 'ao', quantity: 1, }); @@ -52,7 +45,7 @@ import Arweave from 'arweave'; observations, distributions, protocolBalance, - names: Object.keys(allRecords), + records: partialRecords.items, buyRecordCost, extendLeaseCost, increaseUndernameCost, @@ -60,25 +53,13 @@ import Arweave from 'arweave'; { 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: '@' }); @@ -87,6 +68,8 @@ import Arweave from 'arweave'; const info = await ant.getInfo(); console.dir( { + affiliatedAnts, + antProcessId: affiliatedAnts[0], antRecords, rootRecord, controllers, @@ -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 }); })();