Create Transaction
Create a transaction on Arweave
The createTransaction function creates a transaction based on the input parameters. The transaction can either be a data upload transaction or a wallet to wallet (token transfer) transaction.
Basic Syntax
The function is called as follows:
import { createTransaction } from 'arweavekit/transaction'
const transaction = await createTransaction({params});Input Parameters
The following params are available for this function and they must be passed in as an object:
type: 'data' | 'wallet': The type of transaction to be created. Adatatype transaction uploads data on Arweave whereas awallettype transaction transfers tokens from one wallet to another.key: JWKInterface(optional) : The private key for the wallet address to be fetched. The wallet key is optional for default transaction creation as no key is needed until signing a transaction, however, it must be passed in if theuseBundlrorsignAndPostoption is set totrue. The wallet key file can be loaded as follows:
import { readFileSync } from 'fs';
const key = JSON.parse(readFileSync('wallet.json').toString());Private keys must be kept secure at all times. Please ensure that the wallet.json file is not pushed to a version control (eg. GitHub).
environment: 'local' | 'mainnet': The environment for creating transactions. As this is only one part of the three step process of uploading transactions to Arweave, it is important that the transaction is signed and posted in the same environment it is created on.
Currently, the Bundlr SDK only supports the mainnet environment.
target: string(optional) : The wallet address to which the wallet to wallet transaction must be sent.
quantity: string(optional) : The quantity specifies the units of Winston to be sent in a wallet to wallet transaction.
data: string | Uint8Array | ArrayBuffer(optional) : To create a data type transaction, this optional parameter can be passed in. The data can be passed as astring,Uint8Arrayor anArrayBuffer(as preferred by the network).options: Additional options can be passed in as a JSON object.tags: array(optional) : Tags can be added to any transaction for ease of indexing and querying. The syntax for adding tags is as follows:tags: [{ 'name': key_name, 'value': some_value}, { 'name': key_name2, 'value': some_value2}]The
nameis the key for a givenvaluethat can be used for querying the transaction in the future. By default the library adds the'ArweaveKit' : '1.5.1'tag on the backend to help identify the library and version used to deploy the function.signAndPost: boolean(optional) : By default, the transaction process on Arweave has three steps to reduce the computation time, and provide convenience and customisation. However, by setting this option totrue, the function signs and posts the transaction on chain in the same function call.useBundlr: boolean(optional) : Creates the transaction using bundlr network. Onlydatatype transactions can use this option. If the data size is under 100kB the transaction does not require any fees for processing through Bundlr.
Currently, the Bundlr SDK only supports data based transactions and only on the mainnet.
The option to signAndPost must be set to true for using Bundlr. Transactions using Bundlr will be signed and posted to the network by default as there is no support for signing and uploading Bundlr transactions in separate steps.
Web Transactions using Bundlr will fallback on Arweave in case of failure.
Returned Data
The function call returns the following data depending on input parameters:
Default transaction (when
useBundlrisfalse):An object of type Transaction is returned by Arweave.
The data related key value pairs hold information when
dataprop is passed in.The target and quantity fields have in formation for wallet-to-wallet transactions.
The
signaturekey has no information until the transaction is signed.The
idof a transaction is only received after calling thepostTransactionfunction (basically, when the transaction is posted on Arweave).On selecting the
signAndPostoption the function returns a status object along with the transaction object.status: 200andstatusText: 'OK'indicates a successful post request on Arweave.The transaction is created on the selected
environment(localormainnet).
When the
useBundlroption is set totrue:An object of type Bundlr Transaction and an object containing the
idof the posted transaction and thetimestampare returned.The
Bundlr Transactionobject consists information regarding the network, currency, data to be posted, tags, etc.The
environmentis alwaysmainnet.
A few errors help identify the correct parameters in case any might be missing or not as expected.
Last updated
Was this helpful?