dispatch() (transaction)
Othent JS SDK dispatch() function
The dispatch()
function allows you to quickly sign and send a transaction to the network in a bundled format. It is best for smaller datas and contract interactions. If the bundled transaction cannot be submitted, it will fall back to a base layer transaction. The function returns the result of the API call.
This function assumes (and requires) a user is authenticated. See requireAuth()
.
API
dispatch(
transaction: Transaction,
options?: DispatchOptions,
): Promise<ArDriveBundledTransactionData | UploadedTransactionData>;
transaction: Transaction
transaction: Transaction
A valid Arweave Transaction
instance, without a keyfile.
options?: DispatchOptions
options?: DispatchOptions
options?.node?: UrlString
(string
)Node used for bundling transactions. Defaults to ArDrive Turbo's node.
Custom Arweave instance. Defaults to an instance connected to https://arweave.net:443.
return Promise<ArDriveBundledTransactionData | UploadedTransactionData>
return Promise<ArDriveBundledTransactionData | UploadedTransactionData>
A Promise
containing the result of the upload request, including the ID of the submitted transaction, as as well as a type
property indicating if it was uploaded by a bundle or directly to the base layer, as well as some additional properties:
interface ArDriveBundledTransactionData {
type: "BUNDLED";
id: string;
timestamp: number;
winc: string;
version: string;
deadlineHeight: number;
dataCaches: string[];
fastFinalityIndexes: string[];
public: string;
signature: string;
owner: string;
}
interface UploadedTransactionData {
type: "BASE";
id: string;
signature: string;
owner: string;
}
Example usage
import Arweave from "arweave";
import { Othent } from "@othent/kms";
const arweave = new Arweave({
host: "ar-io.net",
port: 443,
protocol: "https"
});
const othent = new Othent({ appInfo, throwErrors: false, ... });
// Make sure the user is authenticated, or prompt them to authenticate:
await othent.requireAuth();
// Create a transaction:
const transaction = await arweave.createTransaction({
data: '<html><head><meta charset="UTF-8"><title>Hello permanent world! This was signed via ArConnect!!!</title></head><body></body></html>'
});
// Dispatch (and sign) it using the default bundler:
const dispatchResult = await othent.dispatch(transaction);
console.log(`The transaction was dispatched as a ${ dispatchResult.type === "BUNDLED" ? "bundled" : "base layer" } Arweave transaction.`);
Last updated