Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Aug 29, 2023
1 parent 56269be commit 254b457
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
27 changes: 20 additions & 7 deletions examples/node/index.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
const Arweave = require('arweave');
const TurboFactory = require('../../lib/index.js');

(async () => {
const { default: Arweave } = await import('arweave');
const { TurboFactory, TurboUnauthenticatedPaymentService } = await import(
'../../lib/index.js'
);
/**
* Fetching rates using an unauthenticated Turbo client.
*/
const turbo = TurboFactory.init();
const rates = await turbo.getRates();
const turbo = TurboFactory.public();
const rates = await turbo.getFiatRates();
console.log('Fetched rates:', JSON.stringify(rates, null, 2));

/**
* Alternatively instantiate your own clients independently.
*/
const paymentService = new TurboUnauthenticatedPaymentService({
url: 'https://payment.ardrive.dev',
});
const supportedCurrencies = await paymentService.getSupportedCurrencies();
console.log(
'Supported currencies:',
JSON.stringify(supportedCurrencies, null, 2),
);

/**
* Create a new arweave private key
*/
const arweave = Arweave.init();
const arweave = new Arweave({});
const jwk = await Arweave.crypto.generateJWK();
const address = await arweave.wallets.jwkToAddress(jwk);

/**
* Use the arweave key to create an authenticated turbo client
*/
const turboAuthClient = TurboFactory.init({ privateKey: jwk });
const turboAuthClient = TurboFactory.private({ privateKey: jwk });

/**
* Fetch the balance for the private key.
Expand Down
23 changes: 19 additions & 4 deletions examples/node/index.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import Arweave from 'arweave';
import fs from 'fs';

import { TurboFactory } from '../../lib/index.js';
import {
TurboFactory,
TurboUnauthenticatedPaymentService,
} from '../../lib/index.js';

(async () => {
/**
* Fetching rates using an unauthenticated Turbo client.
*/
const turbo = TurboFactory.init();
const turbo = TurboFactory.public();
const rates = await turbo.getFiatRates();
console.log('Fetched rates:', JSON.stringify(rates, null, 2));

/*
* Alternatively instantiate your own clients independently.
*/
const paymentService = new TurboUnauthenticatedPaymentService({
url: 'https://payment.ardrive.dev',
});
const supportedCurrencies = await paymentService.getSupportedCurrencies();
console.log(
'Supported currencies:',
JSON.stringify(supportedCurrencies, null, 2),
);

/**
* Fetching balance using an authenticated Turbo client.
*/
const arweave = Arweave.init();
const arweave = new Arweave.init();
const jwk = await Arweave.crypto.generateJWK();
const address = await arweave.wallets.jwkToAddress(jwk);
const turboAuthClient = TurboFactory.init({ privateKey: jwk });
const turboAuthClient = TurboFactory.private({ privateKey: jwk });
const balance = await turboAuthClient.getBalance();
console.log(
'Balance:',
Expand Down
2 changes: 1 addition & 1 deletion examples/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1>Upload File</h1>
});
const jwk = await arweave.crypto.generateJWK();
const address = await arweave.wallets.jwkToAddress(jwk);
const turbo = TurboFactory.init({
const turbo = TurboFactory.private({
privateKey: jwk,
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"test": "c8 mocha --config .mocharc",
"prepare": "husky install",
"example:mjs": "yarn build:esm && node examples/node/index.mjs",
"example:cjs": "yarn build:esm && node examples/node/index.mjs",
"example:cjs": "yarn build:esm && node examples/node/index.cjs",
"example:web": "yarn build:web && cp -r bundles/* examples/web && http-server --port 8080 --host -o examples/web"
},
"dependencies": {
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TurboFactory {
static public({
paymentServiceConfig = {},
uploadServiceConfig = {},
}: TurboPublicConfiguration) {
}: TurboPublicConfiguration = {}) {
const paymentService = new TurboUnauthenticatedPaymentService({
...paymentServiceConfig,
});
Expand Down Expand Up @@ -76,3 +76,6 @@ export class TurboFactory {
});
}
}

// additionally export classes
export * from './common/index.js';

0 comments on commit 254b457

Please sign in to comment.