Create and Sign Transactions
masterTransactions are the building blocks of the Arweave permaweb. You can create data transactions (to store data) or wallet-to-wallet transactions (to transfer AR).
Workflow:
- Call
createTransactionto get an unsigned transaction object. - (Optional) Add metadata using
addTag. - Call
transactions.signto sign the transaction with a key. - Call
transactions.submitor use an uploader to send it to the network.
Important:
- Modifying a transaction object after signing it will invalidate the signature.
- If no
keyis passed tocreateTransaction, Arweave.js will attempt to use a browser-based wallet extension (like ArConnect). - For large data uploads, use ArBundles instead of standard transactions.
let key = await arweave.wallets.generate();
// Create a data transaction
let transaction = await arweave.createTransaction({
data: 'Hello World'
}, key);
// Add metadata tags
transaction.addTag('Content-Type', 'text/plain');
// Sign the transaction
await arweave.transactions.sign(transaction, key);
// Submit the transaction
const response = await arweave.transactions.post(transaction);