TurboAuthenticatedClient
getBalance()
Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
const { winc: balance } = await turbo.getBalance();
signer.getNativeAddress()
Returns the [native address][docs/native-address] of the connected signer.
const address = await turbo.signer.getNativeAddress();
getWincForFiat()
Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount, and optional promo codes.
const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
await turbo.getWincForFiat({
amount: USD(100),
promoCodes: ['MY_PROMO_CODE'], // promo codes require an authenticated client
});
createCheckoutSession()
Creates a Stripe checkout session for a Turbo Top Up with the provided amount, currency, owner, and optional promo codes. The returned URL can be opened in the browser, all payments are processed by Stripe. Promo codes require an authenticated client.
const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
await turbo.createCheckoutSession({
amount: USD(10.0), // $10.00 USD
owner: publicArweaveAddress,
promoCodes: ['MY_PROMO_CODE'], // promo codes require an authenticated client
});
// open checkout session in a browser
window.open(url, '_blank');
upload()
The easiest way to upload data to Turbo. The signal
is an optional [AbortSignal] that can be used to cancel the upload or timeout the request. dataItemOpts
is an optional object that can be used to configure tags, target, and anchor for the data item upload.
const uploadResult = await turbo.upload({
data: 'The contents of my file!',
signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
dataItemOpts: {
// optional
},
events: {
// optional
},
});
uploadFile()
Signs and uploads a raw file. There are two ways to provide the file to the SDK:
- Using a
file
parameter - Using a
fileStreamFactory
andfileSizeFactory
Using file`
In Web with a file input:
const selectedFile = e.target.files[0];
const uploadResult = await turbo.uploadFile({
file: selectedFile,
dataItemOpts: {
tags: [{ name: 'Content-Type', value: 'text/plain' }],
},
events: {
onUploadProgress: ({ totalBytes, processedBytes }) => {
console.log('Upload progress:', { totalBytes, processedBytes });
},
onUploadError: (error) => {
console.log('Upload error:', { error });
},
onUploadSuccess: () => {
console.log('Upload success!');
},
},
});
In NodeJS with a file path:
const filePath = path.join(__dirname, './my-unsigned-file.txt');
const fileSize = fs.stateSync(filePath).size;
const uploadResult = await turbo.uploadFile({
file: filePath,
dataItemOpts: {
tags: [{ name: 'Content-Type', value: 'text/plain' }],
},
});
Using fileStreamFactoryand
fileSizeFactory`
Note: The provided fileStreamFactory
should produce a NEW file data stream each time it is invoked. The fileSizeFactory
is a function that returns the size of the file. The signal
is an optional [AbortSignal] that can be used to cancel the upload or timeout the request. dataItemOpts
is an optional object that can be used to configure tags, target, and anchor for the data item upload.
const filePath = path.join(__dirname, './my-unsigned-file.txt');
const fileSize = fs.stateSync(filePath).size;
const uploadResult = await turbo.uploadFile({
fileStreamFactory: () => fs.createReadStream(filePath),
fileSizeFactory: () => fileSize,
});
Customize Multi-Part Upload Behavior
By default, the Turbo upload methods will split files that are larger than 10 MiB into chunks and send them to the upload service multi-part endpoints. This behavior can be customized with the following inputs:
chunkByteCount
: The maximum size in bytes for each chunk. Must be between 5 MiB and 500 MiB. Defaults to 5 MiB.maxChunkConcurrency
: The maximum number of chunks to upload concurrently. Defaults to 5. Reducing concurrency will slow down uploads, but reduce memory utilization and serialize network calls. Increasing it will upload faster, but can strain available resources.chunkingMode
: The chunking mode to use. Can be 'auto', 'force', or 'disabled'. Defaults to 'auto'. Auto behavior means chunking is enabled if the file would be split into at least three chunks.maxFinalizeMs
: The maximum time in milliseconds to wait for the finalization of all chunks after the last chunk is uploaded. Defaults to 1 minute per GiB of the total file size.
// Customize chunking behavior
await turbo.upload({
...params,
chunkByteCount: 1024 * 1024 * 500, // Max chunk size
maxChunkConcurrency: 1, // Minimize concurrency
});
// Disable chunking behavior
await turbo.upload({
...params,
chunkingMode: 'disabled',
});
// Force chunking behavior
await turbo.upload({
...params,
chunkingMode: 'force',
});
On Demand Uploads
With the upload methods, you can choose to Top Up with selected crypto token on demand if the connected wallet does not have enough credits to complete the upload.
This is done by providing the OnDemandFunding
class to the fundingMode
parameter on upload methods. The maxTokenAmount
(optional) is the maximum amount of tokens in the token type's smallest unit value (e.g: Winston for arweave token type) to fund the wallet with. The topUpBufferMultiplier
(optional) is the multiplier to apply to the estimated top-up amount to avoid underpayment during on-demand top-ups due to price fluctuations on longer uploads. Defaults to 1.1, meaning a 10% buffer.
Note: On demand API currently only available for SOL (solana
), and $ETH on Base Network (base-eth
) token types.
const turbo = TurboFactory.authenticated({
signer: arweaveSignerWithARIO,
token: 'ario',
});
await turbo.upload({
...params,
fundingMode: new OnDemandFunding({
maxTokenAmount: ARIOToTokenAmount(500), // Max 500 $ARIO
topUpBufferMultiplier: 1.1, // 10% buffer to avoid underpayment
}),
});
uploadFolder()
Signs and uploads a folder of files. For NodeJS, the folderPath
of the folder to upload is required. For the browser, an array of files
is required. The dataItemOpts
is an optional object that can be used to configure tags, target, and anchor for the data item upload. The signal
is an optional [AbortSignal] that can be used to cancel the upload or timeout the request. The maxConcurrentUploads
is an optional number that can be used to limit the number of concurrent uploads. The throwOnFailure
is an optional boolean that can be used to throw an error if any upload fails. The manifestOptions
is an optional object that can be used to configure the manifest file, including a custom index file, fallback file, or whether to disable manifests altogether. Manifests are enabled by default.
NodeJS Upload Folder
const folderPath = path.join(__dirname, './my-folder');
const { manifest, fileResponses, manifestResponse } = await turbo.uploadFolder({
folderPath,
dataItemOpts: {
// optional
tags: [
{
// User defined content type will overwrite file content type
name: 'Content-Type',
value: 'text/plain',
},
{
name: 'My-Custom-Tag',
value: 'my-custom-value',
},
],
// no timeout or AbortSignal provided
},
manifestOptions: {
// optional
indexFile: 'custom-index.html',
fallbackFile: 'custom-fallback.html',
disableManifests: false,
},
});
Browser Upload Folder
<input type="file" id="folder" name="folder" webkitdirectory />
<script type="module">
const folderInput = document.getElementById('folder');
folderInput.addEventListener('change', async (event) => {
const selectedFiles = folderInput.files;
console.log('Folder selected:', selectedFiles);
const { manifest, fileResponses, manifestResponse } =
await turbo.uploadFolder({
files: Array.from(selectedFiles).map((file) => file),
});
console.log(manifest, fileResponses, manifestResponse);
});
</script>
topUpWithTokens()
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 Turbo Payment Service for top up processing.
- The
tokenAmount
is the amount of tokens in the token type's smallest unit value (e.g: Winston for arweave token type) to fund the wallet with. - The
feeMultiplier
(optional) is the multiplier to apply to the reward for the transaction to modify its chances of being mined. Credits will be added to the wallet balance after the transaction is confirmed on the given blockchain. Defaults to 1.0, meaning no multiplier.
Arweave (AR) Crypto Top Up
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
});
AR.IO Network (ARIO) Crypto Top Up
const turbo = TurboFactory.authenticated({ signer, token: 'ario' });
const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
tokenAmount: ARIOToTokenAmount(100), // 100 $ARIO
});
Ethereum (ETH) Crypto Top Up
const turbo = TurboFactory.authenticated({ signer, token: 'ethereum' });
const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
tokenAmount: ETHToTokenAmount(0.00001), // 0.00001 ETH
});
Polygon (POL / MATIC) Crypto Top Up
const turbo = TurboFactory.authenticated({ signer, token: 'pol' });
const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
tokenAmount: POLToTokenAmount(0.00001), // 0.00001 POL
});
Eth on Base Network Crypto Top Up
const turbo = TurboFactory.authenticated({ signer, token: 'base-eth' });
const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
tokenAmount: ETHToTokenAmount(0.00001), // 0.00001 ETH bridged on Base Network
});
Solana (SOL) Crypto Top Up
const turbo = TurboFactory.authenticated({ signer, token: 'solana' });
const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
tokenAmount: SOLToTokenAmount(0.00001), // 0.00001 SOL
});
KYVE Crypto Top Up
const turbo = TurboFactory.authenticated({ signer, token: 'kyve' });
const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
tokenAmount: KYVEToTokenAmount(0.00001), // 0.00001 KYVE
});
shareCredits()
Shares credits from the connected wallet to the provided native address and approved winc amount. This action will create a signed data item for the approval
const { approvalDataItemId, approvedWincAmount } = await turbo.shareCredits({
approvedAddress: '2cor...VUa',
approvedWincAmount: 800_000_000_000, // 0.8 Credits
expiresBySeconds: 3600, // Credits will expire back to original wallet in 1 hour
});
revokeCredits()
Revokes all credits shared from the connected wallet to the provided native address.
const revokedApprovals = await turbo.revokeCredits({
revokedAddress: '2cor...VUa',
});
getCreditShareApprovals()
Returns all given or received credit share approvals for the connected wallet or the provided native address.
const { givenApprovals, receivedApprovals } =
await turbo.getCreditShareApprovals({
userAddress: '2cor...VUa',
});
How is this guide?