Tezos Bundler Node
tezos-bundler is a JavaScript/TypeScript library, currently stable at version 1.0.2, designed to facilitate cross-chain interactions between the Tezos and Arweave ecosystems. It provides a REST API endpoint for accepting Arweave ANS-104 bundles that have been cryptographically signed using a Tezos wallet keypair. This functionality enables developers to build applications where Tezos users can directly and securely publish immutable data to the Arweave permaweb. The library's core differentiator is its integrated Tezos signature verification for Arweave bundles, simplifying the deployment of decentralized applications that leverage both chains. It requires a specific Node.js environment (v16.13.2) and relies on a configured Arweave instance (e.g., a production gateway or a local ArLocal server) to function correctly. While a formal release cadence isn't explicitly stated, its current version suggests active development and maintenance.
Common errors
-
Error: Cannot find module 'arweave'
cause The 'arweave' package is not installed as a dependency.fixRun `npm install arweave` or `yarn add arweave` in your project directory. -
TypeError: TezosBundler is not a constructor
cause Attempting to import `TezosBundler` as a named export when it is a default export.fixChange `import { TezosBundler } from 'tezos-bundler'` to `import TezosBundler from 'tezos-bundler'`. -
UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:1984
cause The configured Arweave instance (e.g., ArLocal) is not running or is inaccessible at the specified host and port.fixEnsure your Arweave gateway or ArLocal instance is running and reachable. Check firewall rules and the `Arweave` client configuration (host, port, protocol). -
Failed to load arweave JWK: SyntaxError: Unexpected token 'o' in JSON at position 1
cause The `arweaveJWK` variable does not contain a valid JSON Web Key object, or the file path to the JWK is incorrect/corrupted.fixVerify that your `my-arweave-keyfile.json` is a valid JSON file containing your Arweave JWK, and that the path to it is correct.
Warnings
- breaking The package explicitly requires Node.js `v16.13.2`. Using other major or minor Node.js versions might lead to compatibility issues or unexpected behavior, especially with underlying dependencies.
- gotcha Handling of the Arweave JWK keyfile (e.g., `my-arweave-keyfile.json`) requires extreme caution. Exposing this file can compromise your Arweave wallet and funds. The quickstart code merely simulates loading.
- gotcha When running `tezos-bundler` locally for development, `ArLocal` is a required dev dependency. Ensure `ArLocal` is running and the wallet address used with `TezosBundler` is sufficiently funded (via `mint/<address>/<amount>` on ArLocal).
- gotcha Incorrect configuration of the `Arweave` client (host, port, protocol) can prevent `tezos-bundler` from connecting to the Arweave network, leading to failed bundle submissions.
Install
-
npm install tezos-bundler -
yarn add tezos-bundler -
pnpm add tezos-bundler
Imports
- TezosBundler
import { TezosBundler } from 'tezos-bundler'import TezosBundler from 'tezos-bundler'
- Arweave
const Arweave = require('arweave')import Arweave from 'arweave'
- app.callback
export default tezosBundler.app.callback
const callback = tezosBundler.app.callback()
Quickstart
import Arweave from 'arweave'
import TezosBundler from 'tezos-bundler'
import path from 'path'
import fs from 'fs'
// In a real application, securely load your Arweave JWK, e.g., from environment variables or a secure vault.
// For this example, we'll simulate loading from a local file.
// DO NOT commit your private keys to version control.
const arweaveJWKPath = path.join(process.cwd(), 'my-arweave-keyfile.json');
let arweaveJWK;
try {
if (fs.existsSync(arweaveJWKPath)) {
arweaveJWK = JSON.parse(fs.readFileSync(arweaveJWKPath, 'utf-8'));
} else {
console.warn(`Warning: Arweave JWK file not found at ${arweaveJWKPath}. Using placeholder; this will likely fail.`)
arweaveJWK = { /* Placeholder for invalid JWK */ };
}
} catch (error) {
console.error('Failed to load arweave JWK:', error);
arweaveJWK = { /* Placeholder for invalid JWK */ };
}
// Configure Arweave client. Use ArLocal defaults for testing, or a production gateway.
const arweave = new Arweave({
host: process.env.ARWEAVE_HOST ?? '127.0.0.1', // e.g., 'arweave.net'
port: parseInt(process.env.ARWEAVE_PORT ?? '1984'), // e.g., 443
protocol: process.env.ARWEAVE_PROTOCOL ?? 'http' // e.g., 'https'
});
const tezosBundler = new TezosBundler(arweaveJWK, arweave);
async function startBundler() {
try {
await tezosBundler.start();
console.log('Tezos Bundler Node started successfully.');
console.log('REST API available at POST /bundle/xtz');
} catch (error) {
console.error('Failed to start Tezos Bundler Node:', error);
// Gracefully handle startup failure, perhaps exit the process or retry.
process.exit(1);
}
}
startBundler();
// Example for server middleware (e.g., Next.js API route or Nuxt.js server middleware)
// export default tezosBundler.app.callback();