Language
Docs

Documentation

Contributors: bobinstein, Justin Shaw
Last Updated:

Posting Transactions using Ardrive Turbo

Posting transactions using Turbo can be accomplished using the @ardrive/turbo-sdk JavaScript package.

Installing the @ardrive/turbo-sdk

To install @ardrive/turbo-sdk run

npm install @ardrive/turbo-sdk
yarn add @ardrive/turbo-sdk

Initializing Turbo Client

There are multiple ways to upload data using the turbo sdk. You can:

  • upload a file
  • upload a data-item

When uploading a data-item with the turbo sdk, you will use ar-bundles to create the data-item and add tags.

import fs from 'node:fs'
import { TurboFactory } from '@ardrive/turbo-sdk/node';
import { ArweaveSigner, createData } from 'arbundles';


if (!process.env.PATH_TO_WALLET) {
  console.error("Please set PATH_TO_WALLET in your env.")
  process.exit()
}

const JWK = JSON.parse(fs.readFileSync(process.env.PATH_TO_WALLET).toString());

const turbo = TurboFactory.authenticated({ privateKey: JWK, });

const signer = new ArweaveSigner(JWK);

File

import { TurboFactory } from '@ardrive/turbo-sdk/node';
import fs from 'fs';

if (!process.env.PATH_TO_WALLET) {
  console.error("Please set PATH_TO_WALLET in your env.")
  process.exit()
}

const JWK = JSON.parse(fs.readFileSync(process.env.PATH_TO_WALLET).toString());

const turbo = TurboFactory.authenticated({ privateKey: JWK });

const filePath = new URL('path/to/file', import.meta.url).pathname;
const fileSize = fs.statSync(filePath).size;
const dataItemOpts = {
    //target: ,
    // anchor: ,
    tags: [{name: 'test', value: 'test'}] // add tags
  }
  const uploadResult = await turbo.uploadFile({
    fileStreamFactory: () => fs.createReadStream(filePath),
    fileSizeFactory: () => fileSize,
    signal: AbortSignal.timeout(10_000), // Optional: cancel the upload after 10 seconds
    dataItemOpts // Optional
  });
  console.log(JSON.stringify(uploadResult, null, 2));

Example Output:

{
  "id": "1mPoz28tMAnYecZTya4g6cHSIQz37zAAwr_uC0IUcxU",
  "timestamp": 1704990130970,
  "winc": "0",
  "version": "0.2.0",
  "deadlineHeight": 1341385,
  "dataCaches": [
    "arweave.net"
  ],
  "fastFinalityIndexes": [
    "arweave.net"
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j2XzfpIENdlhVxjmmWmIiMtrr58oOws9mB5yyIFHeXUbk1U4EZc7mbNDEEmDjTpHnAIVM83aGDOux7H2UpDV9UMBPYS1CX_huW4ACXJ6XqLH5E6Kc6_WXWUwEsoGKarK0A1WiDpKhGkA41KgKHLZ5CbACJ0bWoaa4YBLQgFjowZXwDsn3s6t78aAqpx_meVI67Eg4P7ELDish8CY9NcMHMXeEBHsctNHtCdJXQLRWf6CyYkmf2T7ym1DP4R58FkpBpkVXEUadFyshJe0nfB9ie17f_njuPpKWN3d2OODZVarxtRsI",
  "owner": "GtDQcrr2QRdoZ-lKto_S_SpzEwiZiHVaj3x4jAgRh4o"
}
const signer = new ArweaveSigner(JWK);
const signedDataItem = createData(JSON.stringify({ "some": "data" }), signer, {
  tags: [{ name: 'test', value: 'test' }] // add tags
});
await signedDataItem.sign(signer);

const uploadResult = await turbo.uploadSignedDataItem({
  dataItemStreamFactory: () => signedDataItem.getRaw(),
  dataItemSizeFactory: () => signedDataItem.getRaw().length,
  signal: AbortSignal.timeout(10_000), // Optional: cancel the upload after 10 seconds

});

console.log(JSON.stringify(uploadResult, null, 2));

Example Output:

{
  "id": "agcPXVfw92w_JI5v8o6C_Gsixd_BDMaHqNSStX4Eed8",
  "timestamp": 1704990453564,
  "winc": "0",
  "version": "0.2.0",
  "deadlineHeight": 1341387,
  "dataCaches": [
    "arweave.net"
  ],
  "fastFinalityIndexes": [
    "arweave.net"
  ],
  "public": "j0Ki2cJHca6HoC4B3y0ZxFKEe9c539AO5KlfDj76KpWOSx5xtbiDUndEWmJxE-p9ayAI8nF5sSJeRfNpuD4g831fmUbTFvUXKNKcfLJ4knDewyY7YNtVGcjBrNRDbsMPhC6UKiquyewRhBlu3YNyEvC9hV4otuwgGI1QcPQmqL9lztpSbwtV00qQIhYAyDbUCmPU6GMPjgk3o-YTDam0rny80tJnxQu5xvLAH3x-nnaAYVsc4-oDvpKKDzq-i5GzSZAFfiWXlYs80fts0Y-T2w3649IgHIjvPy72jYS6y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LAOQ_43PMefla7OE",
  "owner": "GtDQcrr2QRdoZ-lKto_S_SpzEwiZiHVaj3x4jAgRh4o"
}

Posting a File

const filePath = new URL('path/to/file', import.meta.url).pathname;
const fileSize = fs.statSync(filePath).size;
const dataItemOpts = {
    //target: 'string',
    // anchor: 'string',
    tags: [{name: 'test', value: 'test'}] // add tags
  }
const uploadResult = await turbo.uploadFile({
	fileStreamFactory: () => fs.createReadStream(filePath),
	fileSizeFactory: () => fileSize,
	signal: AbortSignal.timeout(10_000), // Optional: cancel the upload after 10 seconds
  dataItemOpts // Optional
});
console.log(JSON.stringify(uploadResult, null, 2));

Example Output:

{
  "id": "68h8-kGbKGJMQD8nOCsRl_0mJKpxQSpmL42OJq5nCxQ",
  "timestamp": 1704990009421,
  "winc": "0",
  "version": "0.2.0",
  "deadlineHeight": 1341384,
  "dataCaches": [
    "arweave.net"
  ],
  "fastFinalityIndexes": [
    "arweave.net"
  ],
  "public": "j0Ki2cJHca6HoC4B3y0ZxFKEe9c539AO5KlfDj76KpWOSx5xtbiDUndEWmJxE-p9ayAI8nF5sSJeRfNpuD4g831fmUbTFvUXKNKcfLJ4knDewyY7YNtVGcjBrNRDbsMPhC6UKiquyewRhBlu3YNyEvC9hV4otuwgGI1QcPQmqL9lztpSbwtV00qQIhYAyDbUCmPU6GMPjgk3o-YTDam0rny80tJnxQu5xvLAH3x-nnaAYVsc4-oDvpKKDzq-i5GzSZAFfiWXlYs80fts0Y-T2w3649IgHIjvPy72jYS6y02HKaL9guTczSQfa5ILhE0XotIFgjTkP0LEhHNVmrG7XA5XyKdgV3tyWi1qPrHs-Se5miuZsD0Mz_tBiVZ_AmqQbUYAmyYmEnuB_NpWJoBj18ItZfP1Bq7BvjriJJmpsOab95hEkQCEJHSHRAkH72aS_oz-bM6lymNtOj68NGzTZ0y0hq9b2FSKFhQbrxQpGSbQQ4p6tnoKF_B2n1xTE1xAU3R5Ju-2CZsGCW6kf2JBVTvyQrU5njVHeAS5niOkaJEzlEoaHvaS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