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:
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. Adata
type transaction uploads data on Arweave whereas awallet
type 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 theuseBundlr
orsignAndPost
option is set totrue
. The wallet key file can be loaded as follows:
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).
It is important to JSON.parse
the read file as this returns the key
in the correct format (object
) for further use.
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.
An arlocal
instance must be running on port 1984
for the function to work with the local environment. To create one, simply run npx arlocal
in the command line. Learn more about arlocal
here.
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.
The target
must be accompanied with a quantity
, else it sends a transaction with 0
tokens by default.
quantity: string
(optional) : The quantity specifies the units of Winston to be sent in a wallet to wallet transaction.
The quantity
must be accompanied with a target
wallet address.
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
,Uint8Array
or 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:The
name
is the key for a givenvalue
that 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. Onlydata
type 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
useBundlr
isfalse
):An object of type Transaction is returned by Arweave.
The data related key value pairs hold information when
data
prop is passed in.The target and quantity fields have in formation for wallet-to-wallet transactions.
The
signature
key has no information until the transaction is signed.The
id
of a transaction is only received after calling thepostTransaction
function (basically, when the transaction is posted on Arweave).On selecting the
signAndPost
option the function returns a status object along with the transaction object.status: 200
andstatusText: 'OK'
indicates a successful post request on Arweave.The transaction is created on the selected
environment
(local
ormainnet
).
When the
useBundlr
option is set totrue:
An object of type Bundlr Transaction and an object containing the
id
of the posted transaction and thetimestamp
are returned.The
Bundlr Transaction
object consists information regarding the network, currency, data to be posted, tags, etc.The
environment
is alwaysmainnet
.
A few errors help identify the correct parameters in case any might be missing or not as expected.
Last updated