### Install Dependencies Source: https://github.com/ardriveapp/turbo-sdk/blob/main/examples/vite/README.md Run this command to install project dependencies. ```bash yarn ``` -------------------------------- ### Run Web Example Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Opens the example web page for the Turbo SDK. ```bash yarn example:web ``` -------------------------------- ### Start Development Server Source: https://github.com/ardriveapp/turbo-sdk/blob/main/examples/next/README.md Run this command to start the Next.js development server. ```bash yarn dev ``` -------------------------------- ### Start Development Server Source: https://github.com/ardriveapp/turbo-sdk/blob/main/examples/vite/README.md Run this command to start the Vite development server. ```bash yarn start ``` -------------------------------- ### Install @ardrive/turbo-sdk with yarn Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use this command to install the SDK using yarn. ```shell yarn add @ardrive/turbo-sdk ``` -------------------------------- ### Install @ardrive/turbo-sdk with npm Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use this command to install the SDK using npm. ```shell npm install @ardrive/turbo-sdk ``` -------------------------------- ### Run CJS Node Example Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Runs the example CommonJS Node.js script. ```bash yarn example:cjs ``` -------------------------------- ### Install Dependencies Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Installs project dependencies using Yarn. ```bash yarn install ``` -------------------------------- ### Install Turbo SDK Globally Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Install the ArDrive Turbo SDK globally on your system using npm or yarn. This allows you to use the `turbo` command from any directory. ```shell npm install -g @ardrive/turbo-sdk ``` ```shell yarn global add @ardrive/turbo-sdk ``` -------------------------------- ### Run ESM Node Example Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Runs the example ECMAScript Module (ESM) Node.js script. ```bash yarn example:esm ``` -------------------------------- ### Install Turbo SDK Locally Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Install the ArDrive Turbo SDK as a development dependency in your project using npm or yarn. This is recommended for project-specific usage. ```shell npm install --save-dev @ardrive/turbo-sdk ``` ```shell yarn add -D @ardrive/turbo-sdk ``` -------------------------------- ### Run Turbo CLI Help Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Display the help information for the Turbo CLI to understand available commands and options. This can be run globally or from a local installation. ```shell turbo --help ``` ```shell yarn turbo --help ``` ```shell npx turbo --help ``` -------------------------------- ### Quick Start: Upload Data with Turbo SDK Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Demonstrates uploading simple data and a file using the Turbo SDK, including detailed event logging for progress, errors, signing, and upload status. Ensure you have your JWK file and an image file ready. ```typescript import { ArweaveSigner, TurboFactory } from '@ardrive/turbo-sdk'; import Arweave from 'arweave'; import fs from 'fs'; import open from 'open'; import path from 'path'; async function uploadWithTurbo() { const jwk = JSON.parse(fs.readFileSync('./my-jwk.json', 'utf-8')); const signer = new ArweaveSigner(jwk); const turbo = TurboFactory.authenticated({ signer }); try { // upload some simple data - log upload progress events const { id, owner, dataCaches, fastFinalityIndexes } = await turbo.upload({ data: 'Hello, world!', events: { // overall events (includes signing and upload events) onProgress: ({ totalBytes, processedBytes, step }) => { console.log('Overall progress:', { totalBytes, processedBytes, step }); }, onError: ({ error, step }) => { console.log('Overall error:', { error, step }); }, }, }); // upload a file - log signing and upload events const filePath = path.join(__dirname, './my-image.png'); const fileSize = fs.statSync(filePath).size; const { id, owner, dataCaches, fastFinalityIndexes } = await turbo.uploadFile({ fileStreamFactory: () => fs.createReadStream(filePath), fileSizeFactory: () => fileSize, events: { // overall events (includes signing and upload events) onProgress: ({ totalBytes, processedBytes, step }) => { console.log('Overall progress:', { totalBytes, processedBytes, step }); }, onError: ({ error, step }) => { console.log('Overall error:', { error, step }); }, // signing events onSigningProgress: ({ totalBytes, processedBytes }) => { console.log('Signing progress:', { totalBytes, processedBytes }); }, onSigningError: (error) => { console.log('Signing error:', { error }); }, onSigningSuccess: () => { console.log('Signing success!'); }, // upload events onUploadProgress: ({ totalBytes, processedBytes }) => { console.log('Upload progress:', { totalBytes, processedBytes }); }, onUploadError: (error) => { console.log('Upload error:', { error }); }, onUploadSuccess: () => { console.log('Upload success!'); }, }, }); // upload complete! console.log('Successfully upload data item!', { id, owner, dataCaches, fastFinalityIndexes, }); } catch (error) { // upload failed console.error('Failed to upload data item!', error); } } ``` -------------------------------- ### Testnet Configuration Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Guides on configuring the SDK to use various blockchain testnets for development and testing purposes. ```APIDOC ## Testnet Configuration ### Description Configure the SDK to use blockchain testnets for development and testing. The SDK defaults to mainnet; `gatewayUrl` must be explicitly set for testnets. ### Base Sepolia (Recommended) ```typescript import { TurboFactory } from '@ardrive/turbo-sdk'; const turbo = TurboFactory.authenticated({ privateKey: process.env.BASE_SEPOLIA_PRIVATE_KEY, token: 'base-eth', gatewayUrl: 'https://sepolia.base.org', // Required for testnet paymentServiceConfig: { url: 'https://payment.ardrive.dev', // Dev payment service }, uploadServiceConfig: { url: 'https://upload.ardrive.dev', // Dev upload service } }); ``` ### Solana Devnet ```typescript import bs58 from 'bs58'; // Assuming bs58 is available import { TurboFactory } from '@ardrive/turbo-sdk'; const secretKey = new Uint8Array([ ... ]); // Your Solana secret key const turbo = TurboFactory.authenticated({ privateKey: bs58.encode(secretKey), token: 'solana', gatewayUrl: 'https://api.devnet.solana.com', paymentServiceConfig: { url: 'https://payment.ardrive.dev', }, uploadServiceConfig: { url: 'https://upload.ardrive.dev', } }); ``` ### Ethereum Sepolia ```typescript import { TurboFactory } from '@ardrive/turbo-sdk'; const turbo = TurboFactory.authenticated({ privateKey: process.env.SEPOLIA_PRIVATE_KEY, token: 'ethereum', gatewayUrl: 'https://sepolia.gateway.tenderly.co', paymentServiceConfig: { url: 'https://payment.ardrive.dev', }, uploadServiceConfig: { url: 'https://upload.ardrive.dev', } }); ``` ### Supported Testnets - **Base Sepolia** (`base-eth`) - Supports on-demand funding - **Solana Devnet** (`solana`) - Supports on-demand funding - **Ethereum Sepolia** (`ethereum`) - Manual top-up only - **Polygon Amoy** (`pol`) - Manual top-up only ``` -------------------------------- ### Initialize Turbo SDK for NodeJS (CommonJS) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Import and instantiate an unauthenticated Turbo client for Node.js environments using CommonJS module syntax. Ensure the SDK is installed in your project. ```typescript import { TurboFactory } from '@ardrive/turbo-sdk'; const turbo = TurboFactory.unauthenticated(); const rates = await turbo.getFiatRates(); ``` -------------------------------- ### Get Price Estimate in USD Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use this command to get the current credit price estimate for a given value in USD. Ensure the value and type are correctly specified. ```shell turbo price --value 10.50 --type usd ``` -------------------------------- ### Initialize Turbo SDK for Bundlers Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Instantiate an unauthenticated Turbo client for use with bundlers like Webpack, Rollup, or ESbuild. No specific setup is required beyond standard module imports. ```typescript import { TurboFactory } from '@ardrive/turbo-sdk/web'; const turbo = TurboFactory.unauthenticated(); const rates = await turbo.getFiatRates(); ``` -------------------------------- ### Get Supported Currencies Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Retrieve a list of currencies supported by the Turbo Payment Service for topping up AR Credits. The amounts are measured in Winston Credits (winc). ```typescript const currencies = await turbo.getSupportedCurrencies(); ``` -------------------------------- ### Get Token Price for Upload Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Calculate the cost in a specified token for uploading a given number of bytes. Requires byte count and the target token. ```shell turbo token-price --byte-count 102400 --token solana ``` -------------------------------- ### Get Price Estimate in Bytes Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Retrieve the current credit price estimate for a specified byte count. The default price type is 'bytes'. ```shell turbo price --value 1024 --type bytes ``` -------------------------------- ### getFiatEstimateForBytes Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Gets the estimated price in a specified fiat currency for uploading a given number of bytes to Turbo. ```APIDOC ## getFiatEstimateForBytes ### Description Get the current price from the Turbo Payment Service, denominated in the specified fiat currency, for uploading a specified number of bytes to Turbo. ### Method POST ### Endpoint /turbo/getFiatEstimateForBytes ### Parameters #### Request Body - **byteCount** (number) - Required - The number of bytes to estimate the cost for. - **currency** (string) - Required - The fiat currency to denominate the price in (e.g., 'usd'). ### Request Example ```typescript const turbo = TurboFactory.unauthenticated(); const { amount } = await turbo.getFiatEstimateForBytes({ byteCount: 1024 * 1024 * 1024, // 1 GiB currency: 'usd', }); console.log(amount); // Estimated usd price for 1 GiB ``` ### Response #### Success Response (200) - **amount** (number) - The estimated price in the specified fiat currency. - **currency** (string) - The fiat currency used for the estimate. - **byteCount** (number) - The number of bytes for the estimate. - **winc** (string) - The equivalent amount in Winston Credits. #### Response Example ```json { "byteCount": 1073741824, "amount": 20.58, "currency": "usd", "winc": "2402378997310" } ``` ``` -------------------------------- ### Get Credit Share Approvals with Turbo SDK Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Retrieves all credit share approvals, either given or received, for a connected wallet or a specified native address. ```typescript const { givenApprovals, receivedApprovals } = await turbo.getCreditShareApprovals({ userAddress: '2cor...VUa', }); ``` -------------------------------- ### TypeScript Import Statement Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Example import statement for the Turbo SDK in a TypeScript project. The SDK automatically provides type definitions for enhanced development experience. ```typescript import { TurboFactory } from '@ardrive/turbo-sdk/'; ``` -------------------------------- ### Get Upload Costs in Winston Credits Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Calculate the estimated cost in Winston Credits for uploading files of specified sizes, including all adjustments and fees. ```typescript const [uploadCostForFile] = await turbo.getUploadCosts({ bytes: [1024] }); const { winc, adjustments } = uploadCostForFile; ``` -------------------------------- ### Get Fiat Estimate for Upload Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Obtain the estimated cost in a specified fiat currency for uploading a given number of bytes. Requires byte count and currency. ```shell turbo fiat-estimate --byte-count 102400 --currency usd ``` -------------------------------- ### Get Winston Credits for Fiat Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount, and optional promo codes. Promo codes require an authenticated client. ```typescript const { winc, paymentAmount, quotedPaymentAmount, adjustments } = await turbo.getWincForFiat({ amount: USD(100), promoCodes: ['MY_PROMO_CODE'], // promo codes require an authenticated client }); ``` -------------------------------- ### Upload Data with Paid By Option (CLI) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md When uploading data using the Turbo CLI, use the `--paid-by` flag followed by an array of wallet addresses that have provided credit share approvals. These credits will be used in the order provided. ```bash turbo upload --paid-by 0x123...,0x456... ``` -------------------------------- ### Get Wallet Balance Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc). ```typescript const { winc: balance } = await turbo.getBalance(); ``` -------------------------------- ### NodeJS Upload Folder Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Demonstrates how to upload a folder from a local filesystem using the Turbo SDK in a NodeJS environment. ```APIDOC ## NodeJS Upload Folder ### Description Uploads a folder from the local filesystem to the Turbo service. ### Method `turbo.uploadFolder` ### Parameters #### Request Body - **folderPath** (string) - Required - The local path to the folder to upload. - **dataItemOpts** (object) - Optional - Options for data items, including tags. - **tags** (array) - Optional - Array of tag objects to associate with the uploaded data. - **name** (string) - Required - The name of the tag. - **value** (string) - Required - The value of the tag. - **manifestOptions** (object) - Optional - Options for generating manifests. - **indexFile** (string) - Optional - Specifies the index file for the manifest. - **fallbackFile** (string) - Optional - Specifies the fallback file for the manifest. - **disableManifests** (boolean) - Optional - If true, disables manifest generation. - **events** (object) - Optional - Event handlers for tracking upload progress. - **onFileStart** (function) - Callback for when a file upload starts. - **onFileProgress** (function) - Callback for file upload progress. - **onFileComplete** (function) - Callback for when a file upload completes. - **onFileError** (function) - Callback for file upload errors. - **onFolderProgress** (function) - Callback for overall folder upload progress. - **onFolderError** (function) - Callback for folder upload errors. - **onFolderSuccess** (function) - Callback for when the folder upload is successful. ### Response - **manifest** (object) - The generated manifest for the uploaded folder. - **fileResponses** (array) - An array of responses for each uploaded file. - **manifestResponse** (object) - The response for the manifest upload. ### Request Example ```typescript const folderPath = path.join(__dirname, './my-folder'); const { manifest, fileResponses, manifestResponse } = await turbo.uploadFolder({ folderPath, dataItemOpts: { tags: [ { name: 'Content-Type', value: 'text/plain', }, { name: 'My-Custom-Tag', value: 'my-custom-value', }, ], }, manifestOptions: { indexFile: 'custom-index.html', fallbackFile: 'custom-fallback.html', disableManifests: false, }, }); ``` ``` -------------------------------- ### Initialize Turbo SDK in Browser via CDN Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Reference the web bundle directly from a CDN to use the Turbo SDK in a browser environment. Ensure you are using the latest version or a specific release. ```html ``` -------------------------------- ### Get Winston Credits for Token Amount Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use this function to get the current amount of Winston Credits equivalent to a given token amount, including all adjustments. ```typescript const { winc, actualTokenAmount, equivalentWincTokenAmount } = await turbo.getWincForToken({ tokenAmount: WinstonToTokenAmount(100_000_000), }); ``` -------------------------------- ### Get Winston Credits for Fiat Amount Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use this function to get the current amount of Winston Credits equivalent to a given fiat amount, including all adjustments. ```typescript const { winc, actualPaymentAmount, quotedPaymentAmount, adjustments } = await turbo.getWincForFiat({ amount: USD(100), }); ``` -------------------------------- ### Initialize and Authenticate Turbo SDK Source: https://github.com/ardriveapp/turbo-sdk/blob/main/examples/web/index.html Sets up an authenticated Arweave client factory using JWK for local development. Ensure the CDN path is updated for production environments. ```javascript import { TurboFactory, developmentTurboConfiguration, } from '../../bundles/web.bundle.min.js'; const arweave = new Arweave({ host: 'ar-io.dev', port: 443, protocol: 'https', }); const jwk = await arweave.crypto.generateJWK(); const address = await arweave.wallets.jwkToAddress(jwk); const turbo = TurboFactory.authenticated({ privateKey: jwk, ...developmentTurboConfiguration, }); ``` -------------------------------- ### Get Native Address Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Returns the native address of the connected signer. ```typescript const address = await turbo.signer.getNativeAddress(); ``` -------------------------------- ### Fiat Estimation API Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Get fiat estimations for uploading a specified number of bytes. ```APIDOC ## GET /fiat-estimate ### Description Get the current fiat estimation from the Turbo Payment Service, denominated in the specified fiat currency, for uploading a specified number of bytes to Turbo. ### Method GET ### Endpoint /fiat-estimate ### Query Parameters - **byte-count** (integer) - Required - Byte count of data to get the fiat estimate for - **currency** (string) - Required - Currency unit of the reported price (e.g: 'usd', 'eur', 'gbp') ### Request Example ```shell turbo fiat-estimate --byte-count 102400 --currency usd ``` ``` -------------------------------- ### Build Project Outputs Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Builds the web, Node.js, and bundled outputs for the project using Yarn. ```bash yarn build ``` -------------------------------- ### Token Price API Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Get token price estimations for uploading a specified number of bytes. ```APIDOC ## GET /token-price ### Description Get the current price from the Turbo Payment Service, denominated in the specified token, for uploading a specified number of bytes to Turbo. ### Method GET ### Endpoint /token-price ### Query Parameters - **byte-count** (integer) - Required - Byte count of data to get the token price for - **token** (string) - Required - The token to denominate the price in (e.g., 'solana') ### Request Example ```shell turbo token-price --byte-count 102400 --token solana ``` ``` -------------------------------- ### getTokenPriceForBytes Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Gets the estimated price in a specified token for uploading a given number of bytes to Turbo. ```APIDOC ## getTokenPriceForBytes ### Description Get the current price from the Turbo Payment Service, denominated in the specified token, for uploading a specified number of bytes to Turbo. ### Method POST ### Endpoint /turbo/getTokenPriceForBytes ### Parameters #### Request Body - **byteCount** (number) - Required - The number of bytes to estimate the cost for. ### Request Example ```typescript const turbo = TurboFactory.unauthenticated({ token: 'solana' }); const { tokenPrice } = await turbo.getTokenPriceForBytes({ byteCount: 1024 * 1024 * 100, // 100 MiB }); console.log(tokenPrice); // Estimated SOL Price for 100 MiB ``` ### Response #### Success Response (200) - **tokenPrice** (string) - The estimated price in the specified token. #### Response Example ```json { "tokenPrice": "0.005" } ``` ``` -------------------------------- ### Browser Integration (CDN) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md How to use the Turbo SDK in a web browser by referencing the bundle directly via a CDN like jsDelivr. ```APIDOC ## Browser Integration (CDN) ### Description Use the web bundle directly from a CDN for browser-based applications. ### Usage ```html ``` Alternatively, download the bundle from [GitHub Releases](https://github.com/ardriveapp/turbo-sdk/releases) and serve it locally. ``` -------------------------------- ### List Credit Shares with Turbo CLI Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use the `list-shares` command in the Turbo CLI to list all Credit Share Approvals for a specified wallet address or the connected wallet. ```bash turbo list-shares --wallet-address 0x123... ``` -------------------------------- ### Get Price Estimate in AR Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Fetch the current credit price estimate for a given value in AR. Specify 'arweave' as the price type. ```shell turbo price --value 1.1 --type arweave ``` -------------------------------- ### Browser Upload Folder Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Demonstrates how to upload a folder selected by the user in a web browser using the Turbo SDK. ```APIDOC ## Browser Upload Folder ### Description Allows users to select a folder via an HTML input element and upload its contents using the Turbo SDK in a browser. ### Method `turbo.uploadFolder` ### Parameters #### Request Body - **files** (array) - Required - An array of File objects representing the files in the selected folder. ### Request Example ```html ``` ``` -------------------------------- ### Get Wallet Balance Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Retrieve the balance of a connected wallet or native address in Turbo Credits. Specify the token type for the balance query. ```shell turbo balance --address 'crypto-wallet-public-native-address' --token solana ``` ```shell turbo balance --wallet-file '../path/to/my/wallet.json' --token arweave ``` -------------------------------- ### Top Up Wallet with Fiat Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Initiate a top-up for a wallet using a supported fiat currency. This command opens a Stripe checkout session in the browser. Ensure the currency and value are correctly specified. ```shell # Open Stripe hosted checkout session in browser to top up for 10.00 USD worth of Turbo Credits turbo top-up --address 'crypto-wallet-public-native-address' --token ethereum --currency USD --value 10 ``` -------------------------------- ### topUpWithTokens Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Details the process of topping up a wallet with Credits using various token types and optional parameters. ```APIDOC ## topUpWithTokens ### Description Tops up the connected wallet with Credits by submitting a payment transaction for the token amount to the Turbo wallet and then submitting that transaction ID to the Turbo Payment Service for top-up processing. Credits are added to the wallet balance after the transaction is confirmed on the blockchain. ### Method `turbo.topUpWithTokens({ tokenAmount, feeMultiplier, turboCreditDestinationAddress })` ### Parameters #### Request Body - **tokenAmount** (number) - Required - The amount of tokens in the token type's smallest unit value (e.g., Winston for Arweave) to fund the wallet with. - **feeMultiplier** (number) - Optional - A multiplier to apply to the transaction fee to increase its chances of being mined. Defaults to 1.0. - **turboCreditDestinationAddress** (string) - Optional - The native address to credit the funds to. If not provided, the connected wallet's native address will be used. Not available for KYVE token type. ### Response - **winc** (number) - The amount of tokens in Winston (or equivalent smallest unit). - **status** (string) - The status of the top-up operation. - **id** (string) - The transaction ID. - **fundResult** (object) - Additional funding results. ### Request Example (Arweave) ```typescript const turbo = TurboFactory.authenticated({ signer, token: 'arweave' }); const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({ tokenAmount: WinstonToTokenAmount(100_000_000), // 0.0001 AR feeMultiplier: 1.1, // 10% increase in reward for improved mining chances turboCreditDestinationAddress: '0xabc...123', // Any custom EVM / SOL / AR / KYVE native destination address }); ``` ``` -------------------------------- ### Share Credits with Turbo CLI Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use the `share-credits` command in the Turbo CLI to create a Credit Share Approval. Provide the recipient's wallet address and the amount of Credits. ```bash turbo share-credits --recipient-wallet-address 0x123... --amount 1000 ``` -------------------------------- ### Create Checkout Session for Ethereum Fiat Top Up Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Creates a Stripe checkout session for topping up Ethereum (ETH) with fiat currency. Requires an unauthenticated client configured for Ethereum. ```typescript const turbo = TurboFactory.unauthenticated({ token: 'ethereum' }); const { url, winc, paymentAmount } = await turbo.createCheckoutSession({ amount: USD(10.0), // $10.00 USD owner: publicEthereumAddress, }); ``` -------------------------------- ### Configure Turbo SDK for Ethereum Sepolia Testnet Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Configure the Turbo SDK to use the Ethereum Sepolia testnet. Ensure the private key, token, gateway URL, and development service URLs are correctly set. ```typescript // Ethereum Sepolia const turbo = TurboFactory.authenticated({ privateKey: process.env.SEPOLIA_PRIVATE_KEY, token: 'ethereum', gatewayUrl: 'https://sepolia.gateway.tenderly.co', paymentServiceConfig: { url: 'https://payment.ardrive.dev', }, uploadServiceConfig: { url: 'https://upload.ardrive.dev', }); ``` -------------------------------- ### Run Integration Tests (Docker) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Runs integration tests against locally running Docker containers. This is the recommended method for testing. ```bash yarn test:docker ``` -------------------------------- ### Initialize Turbo SDK for NodeJS (ESM) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Import and instantiate an unauthenticated Turbo client for Node.js environments using ECMAScript Modules (ESM) syntax. Specify the node entry point for imports. ```typescript import { TurboFactory } from '@ardrive/turbo-sdk/node'; const turbo = TurboFactory.unauthenticated(); const rates = await turbo.getFiatRates(); ``` -------------------------------- ### Get Fiat Estimate for Bytes Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Retrieve the estimated price in a specified fiat currency for uploading a given number of bytes to Turbo. Requires an unauthenticated client. ```typescript const turbo = TurboFactory.unauthenticated(); const { amount } = await turbo.getFiatEstimateForBytes({ byteCount: 1024 * 1024 * 1024, currency: 'usd', // specify the currency for the price }); console.log(amount); // Estimated usd price for 1 GiB ``` -------------------------------- ### Upload Data with Paid By Option (SDK) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md When uploading data using the Turbo SDK, you can specify an array of wallet addresses in the `paidBy` option. These addresses have provided credit share approvals, and their credits will be used in the order provided. ```typescript await turboClient.upload(dataItem, { dataOptions: { ...opts, paidBy: ["0x123...", "0x456..."] } }); ``` -------------------------------- ### Configure Turbo SDK for Base Sepolia Testnet Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Configure the Turbo SDK to use the Base Sepolia testnet. This requires specifying the private key, token, gateway URL, and development service endpoints. ```typescript // Base Sepolia (recommended for testing) const turbo = TurboFactory.authenticated({ privateKey: process.env.BASE_SEPOLIA_PRIVATE_KEY, token: 'base-eth', gatewayUrl: 'https://sepolia.base.org', // Required for testnet paymentServiceConfig: { url: 'https://payment.ardrive.dev', // Dev payment service }, uploadServiceConfig: { url: 'https://upload.ardrive.dev', // Dev upload service } }); ``` -------------------------------- ### Get Token Price for Bytes Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Retrieve the estimated price in a specified token for uploading a given number of bytes to Turbo. Requires an unauthenticated client configured with a token. ```typescript const turbo = TurboFactory.unauthenticated({ token: 'solana' }); const { tokenPrice } = await turbo.getTokenPriceForBytes({ byteCount: 1024 * 1024 * 100, }); console.log(tokenPrice); // Estimated SOL Price for 100 MiB ``` -------------------------------- ### Upload Folder to Turbo Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Upload a folder and its contents, creating a manifest file for the upload. Options include specifying index/fallback files, concurrency, and enabling on-demand top-up for supported tokens. ```shell turbo upload-folder --folder-path '../path/to/my/folder' --token solana --wallet-file ../path/to/sol/sec/key.json ``` -------------------------------- ### Get Supported Countries Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Fetch the list of countries supported by the Turbo Payment Service for its top-up workflow. This is useful for validating user location or displaying relevant options. ```typescript const countries = await turbo.getSupportedCountries(); ``` -------------------------------- ### Create Checkout Session for KYVE Fiat Top Up Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Creates a Stripe checkout session for topping up KYVE with fiat currency. Requires an unauthenticated client configured for KYVE. ```typescript const turbo = TurboFactory.unauthenticated({ token: 'kyve' }); const { url, winc, paymentAmount } = await turbo.createCheckoutSession({ amount: USD(10.0), // $10.00 USD owner: publicKyveAddress, }); ``` -------------------------------- ### Create Checkout Session for Solana Fiat Top Up Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Creates a Stripe checkout session for topping up Solana (SOL) with fiat currency. Requires an unauthenticated client configured for Solana. ```typescript const turbo = TurboFactory.unauthenticated({ token: 'solana' }); const { url, winc, paymentAmount } = await turbo.createCheckoutSession({ amount: USD(10.0), // $10.00 USD owner: publicSolanaAddress, }); ``` -------------------------------- ### Get Fiat Rates for Data Storage Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Retrieve the current fiat rates for 1 GiB of data storage. This includes all applicable top-up adjustments and fees for supported currencies. ```typescript const rates = await turbo.getFiatRates(); ``` -------------------------------- ### Share Credits with Turbo SDK Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use the `shareCredits` method to create a Credit Share Approval. Specify the recipient's wallet address and the amount of Credits to share. ```typescript await turboClient.shareCredits({ walletAddress: recipientWalletAddress, amount: amountOfCreditsToShare, expiresInSeconds: 60 * 60 * 24 * 30 // 30 days }); ``` -------------------------------- ### Get Fiat to AR Conversion Rate Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Obtain the current raw conversion rate between a specified fiat currency and AR (Arweave tokens). Rates are sourced from third-party pricing oracles. ```typescript const fiatToAR = await turbo.getFiatToAR({ currency: 'USD' }); ``` -------------------------------- ### Create Authenticated Turbo Client Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Instantiate a Turbo client for accessing both authenticated and unauthenticated services. Requires a signer or private key for authentication. ```typescript const signer = new ArweaveSigner(jwk); const turbo = TurboFactory.authenticated({ signer }); ``` -------------------------------- ### Upload Folder with Progress Events Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Demonstrates how to track the progress of a folder upload using event listeners for both individual files and the entire folder. This is useful for UI feedback like progress bars. ```typescript const folderPath = path.join(__dirname, './my-folder'); const { manifest, fileResponses, manifestResponse } = await turbo.uploadFolder({ folderPath, events: { // Per-file events onFileStart: ({ fileName, fileSize, fileIndex, totalFiles }) => { console.log( `Starting file ${ fileIndex + 1 }/${totalFiles}: ${fileName} (${fileSize} bytes)`, ); }, onFileProgress: ({ fileName, fileIndex, totalFiles, fileProcessedBytes, fileTotalBytes, step, }) => { const percentComplete = (fileProcessedBytes / fileTotalBytes) * 100; console.log( `File ${ fileIndex + 1 }/${totalFiles} (${fileName}) ${step}: ${percentComplete.toFixed(2)}%`, ); }, onFileComplete: ({ fileName, fileIndex, totalFiles, id }) => { console.log( `Completed file ${fileIndex + 1}/${totalFiles}: ${fileName} (${id})`, ); }, onFileError: ({ fileName, fileIndex, totalFiles, error }) => { console.error( `Error uploading file ${fileIndex + 1}/${totalFiles}: ${fileName}`, error, ); }, // Folder-level aggregate events onFolderProgress: ({ processedFiles, totalFiles, processedBytes, totalBytes, currentPhase, }) => { const percentComplete = (processedBytes / totalBytes) * 100; console.log( `Folder progress (${currentPhase}): ${processedFiles}/${totalFiles} files, ${percentComplete.toFixed( 2, )}%`, ); }, onFolderError: (error) => { console.error('Folder upload error:', error); }, onFolderSuccess: () => { console.log('Folder upload complete!'); }, }, }); ``` -------------------------------- ### Use Signer Balance First with Turbo CLI Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use the `--use-signer-balance-first` flag with Turbo CLI upload commands to prioritize using the signer's balance before utilizing any available Credit Share Approvals. ```bash turbo upload --use-signer-balance-first ``` -------------------------------- ### Fund Wallet with Crypto Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Fund a wallet with Turbo Credits by submitting a crypto payment transaction. This command can also process existing funding transaction IDs. Private key or wallet file is required for funding. ```shell # Fund any valid destination wallet with 10 USDC worth of Turbo Credits on Base Network turbo crypto-fund --value 10 --token base-usdc --private-key '0xabc...123' --address 'any-valid-evm-sol-ar-kyve-native-address' ``` ```shell turbo crypto-fund --value 0.0001 --token kyve --private-key 'b27...45c' ``` ```shell turbo crypto-fund --tx-id 'my-valid-arweave-fund-transaction-id' --token arweave ``` ```shell turbo crypto-fund --value 100 --token ario --wallet-file ../path/to/arweave/wallet/with/ario.json ``` ```shell # Use a custom AO process ID and compute unit: turbo crypto-fund --value 100 --token ario --process-id agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA --cu-url https://cu.ao-testnet.xyz ``` ```shell # Send to custom destination address turbo crypto-fund --value 100 --token ario --wallet-file ../path/to/arweave/wallet/with/ario.json --address 'Any-Valid-AR-EVM-SOL-KYVE-Native-Address' ``` -------------------------------- ### Upload Folder with Progress Events Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Details how to use event listeners to track the progress of folder uploads, both at the file and folder level. ```APIDOC ## Upload Folder with Progress Events ### Description Provides detailed event callbacks for monitoring the progress and status of folder uploads, including per-file and aggregate folder events. ### Method `turbo.uploadFolder` with `events` option ### Parameters #### Events - **onFileStart** (function) - Called when a file upload begins. Provides `fileName`, `fileSize`, `fileIndex`, `totalFiles`. - **onFileProgress** (function) - Called during file upload. Provides `fileName`, `fileIndex`, `totalFiles`, `fileProcessedBytes`, `fileTotalBytes`, `step`. - **onFileComplete** (function) - Called when a file upload finishes. Provides `fileName`, `fileIndex`, `totalFiles`, `id`. - **onFileError** (function) - Called if a file upload fails. Provides `fileName`, `fileIndex`, `totalFiles`, `error`. - **onFolderProgress** (function) - Called for overall folder progress. Provides `processedFiles`, `totalFiles`, `processedBytes`, `totalBytes`, `currentPhase`. - **onFolderError** (function) - Called if the entire folder upload fails. Provides `error`. - **onFolderSuccess** (function) - Called when the entire folder upload completes successfully. ### Request Example ```typescript const folderPath = path.join(__dirname, './my-folder'); const { manifest, fileResponses, manifestResponse } = await turbo.uploadFolder({ folderPath, events: { onFileStart: ({ fileName, fileSize, fileIndex, totalFiles }) => { console.log(`Starting file ${fileIndex + 1}/${totalFiles}: ${fileName} (${fileSize} bytes)`); }, onFileProgress: ({ fileName, fileIndex, totalFiles, fileProcessedBytes, fileTotalBytes, step }) => { const percentComplete = (fileProcessedBytes / fileTotalBytes) * 100; console.log(`File ${fileIndex + 1}/${totalFiles} (${fileName}) ${step}: ${percentComplete.toFixed(2)}%`); }, onFileComplete: ({ fileName, fileIndex, totalFiles, id }) => { console.log(`Completed file ${fileIndex + 1}/${totalFiles}: ${fileName} (${id})`); }, onFileError: ({ fileName, fileIndex, totalFiles, error }) => { console.error(`Error uploading file ${fileIndex + 1}/${totalFiles}: ${fileName}`, error); }, onFolderProgress: ({ processedFiles, totalFiles, processedBytes, totalBytes, currentPhase }) => { const percentComplete = (processedBytes / totalBytes) * 100; console.log(`Folder progress (${currentPhase}): ${processedFiles}/${totalFiles} files, ${percentComplete.toFixed(2)}%`); }, onFolderError: (error) => { console.error('Folder upload error:', error); }, onFolderSuccess: () => { console.log('Folder upload complete!'); }, }, }); ``` ``` -------------------------------- ### NodeJS Integration (CommonJS) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Instructions for using the Turbo SDK in a Node.js environment with CommonJS module system. ```APIDOC ## NodeJS Integration (CommonJS) ### Description Utilize the Turbo SDK in Node.js applications using the CommonJS module format. ### Usage ```typescript import { TurboFactory } from '@ardrive/turbo-sdk'; const turbo = TurboFactory.unauthenticated(); const rates = await turbo.getFiatRates(); ``` Refer to the [examples/typescript/cjs] directory for a full example. ``` -------------------------------- ### Fetch Wallet Balance with Turbo SDK Source: https://github.com/ardriveapp/turbo-sdk/blob/main/examples/web/index.html Fetches the wallet balance using the Turbo SDK and displays it in the DOM element with ID 'balance'. ```javascript const balance = await turbo.getBalance(); document.getElementById('balance').innerText = JSON.stringify( balance, null, 2, ).catch((err) => console.log('Error fetching balance!', err)); ``` -------------------------------- ### Run Integration Tests (Dev Environment) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Runs integration tests against the development environment, typically pointing to `https://payment.ardrive.dev` and `https://upload.ardrive.dev`. ```bash yarn test ``` -------------------------------- ### Bundler Integration (Webpack, Rollup, ESbuild) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Instructions for integrating the Turbo SDK with common JavaScript bundlers like Webpack, Rollup, and ESbuild. ```APIDOC ## Bundlers (Webpack, Rollup, ESbuild, etc.) ### Description Integrate the Turbo SDK into your project using bundlers like Webpack, Rollup, or ESbuild. ### Usage ```typescript import { TurboFactory } from '@ardrive/turbo-sdk/web'; const turbo = TurboFactory.unauthenticated(); const rates = await turbo.getFiatRates(); ``` ``` -------------------------------- ### Authenticate with Solana Web Wallet Adapter Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Authenticate with the Turbo SDK using the Solana Web Wallet Adapter. This is suitable for browser environments where the wallet is available globally. ```typescript const turbo = TurboFactory.authenticated({ walletAdapter: window.solana, token: 'solana', }); ``` -------------------------------- ### Configure Turbo SDK for Solana Devnet Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Configure the Turbo SDK to use the Solana Devnet. This involves providing the private key (encoded), token, gateway URL, and development service endpoints. ```typescript // Solana Devnet const turbo = TurboFactory.authenticated({ privateKey: bs58.encode(secretKey), token: 'solana', gatewayUrl: 'https://api.devnet.solana.com', paymentServiceConfig: { url: 'https://payment.ardrive.dev', }, uploadServiceConfig: { url: 'https://upload.ardrive.dev', } }); ``` -------------------------------- ### Top Up Ethereum (ETH) Crypto Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Top up Ethereum (ETH) using the Turbo SDK. Ensure the correct signer and token identifier are provided. ```typescript const turbo = TurboFactory.authenticated({ signer, token: 'ethereum' }); const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({ tokenAmount: ETHToTokenAmount(0.00001), // 0.00001 ETH }); ``` -------------------------------- ### List Credit Shares with Turbo SDK Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Use the `listShares` method to retrieve all Credit Share Approvals for a specified wallet address or the connected wallet. ```typescript await turboClient.listShares({ walletAddress: recipientWalletAddress }); ``` -------------------------------- ### NodeJS Integration (ESM) Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Instructions for using the Turbo SDK in a Node.js environment with the ECMAScript Modules (ESM) system. ```APIDOC ## NodeJS Integration (ESM) ### Description Integrate the Turbo SDK into Node.js projects leveraging the ECMAScript Modules (ESM) standard. ### Usage ```typescript import { TurboFactory } from '@ardrive/turbo-sdk/node'; const turbo = TurboFactory.unauthenticated(); const rates = await turbo.getFiatRates(); ``` Refer to the [examples/typescript/esm] directory for a full example. ``` -------------------------------- ### Vite Configuration with Polyfills Source: https://github.com/ardriveapp/turbo-sdk/blob/main/examples/vite/README.md Configure Vite to include necessary polyfills for @ardrive/turbo-sdk using vite-plugin-node-polyfills. ```javascript import react from '@vitejs/plugin-react'; import { defineConfig } from 'vite'; import { nodePolyfills } from 'vite-plugin-node-polyfills'; export default defineConfig({ build: {}, base: '/', plugins: [react(), nodePolyfills()], }); ``` -------------------------------- ### TurboFactory - authenticated() Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Creates an authenticated client instance for accessing all Turbo services, requiring a signer or private key. ```APIDOC ## TurboFactory `authenticated()` ### Description Creates an instance of a client that accesses Turbo's authenticated and unauthenticated services. Requires either a signer, or private key to be provided. ### Method `TurboFactory.authenticated({ signer })` ### Parameters #### Request Body - **signer** (object) - Required - An object implementing the signer interface (e.g., `ArweaveSigner`). ### Usage ```typescript import { ArweaveSigner } from '@ardrive/turbo-sdk'; // Assuming ArweaveSigner is exported const jwk = { ... }; // Your JWK private key const signer = new ArweaveSigner(jwk); const turbo = TurboFactory.authenticated({ signer }); ``` See the [Signers] section for all supported signers and authentication methods. ``` -------------------------------- ### Create Checkout Session for Polygon Fiat Top Up Source: https://github.com/ardriveapp/turbo-sdk/blob/main/README.md Creates a Stripe checkout session for topping up Polygon (POL / MATIC) with fiat currency. Requires an unauthenticated client configured for Polygon. ```typescript const turbo = TurboFactory.unauthenticated({ token: 'pol' }); const { url, winc, paymentAmount } = await turbo.createCheckoutSession({ amount: USD(10.0), // $10.00 USD owner: publicPolygonAddress, }); ```