@theplatformpublishing/arweave-deploy
v1.2.1
Published
A simple npm module for deploying content to the Arweave network
Downloads
4
Readme
arweave-deploy 🚀
Usage
Initialise the deployer
import ArweaveDeploy from '@theplatformpublishing/arweave-deploy'
To start deploying content to Arweave you will need to specify:
- the Arweave network that will process the transactions,
- the wallet that will be used to sign and submit those transactions.
By default, ArweaveDeploy
will assume a local testnet environment and generate a development wallet.
Therefore, if this is your case, you may not pass any parameters.
const deployer = new ArweaveDeploy()
If the key is not specified, the development wallet will be generated once you submit your first transaction. After that, it will be accessible from
deployer.key
.
Otherwise, specify one or both parameters yourself.
/**
* @param {apiConfig} arweaveConfig - Arweave configuration
* @param {JWKInterface} key - Wallet or private key
*/
const deployer = new ArweaveDeploy({
host: 'arweave.net',
port: 443,
protocol: 'https'
}, key)
Deploy raw data
You can deploy any kind of data as long as its format is Uint8Array | Buffer | string
. You must also
provide a sensible MIME type
like application/json
so that browsers are able to display the content properly.
const data = JSON.stringify({ message: 'Hello World!' })
deployer.submit(data, 'application/json')
.then(tx => console.log(`Arweave link: ${deployer.getBaseURL()}${tx.id}`))
Deploy a single file
For single files you need to provide a Buffer
object.
const buffer = fs.readFileSync('image.png')
deployer.submit(buffer, 'image/png')
.then(tx => console.log(`Arweave link: ${deployer.getBaseURL()}${tx.id}`))
Deploy a zipped HTML project
However, the true power of Arweave deployer lies in publishing entire HTML projects (javascript, css, etc.) with just a few transactions. You must specify the index and an optional callback function that will be run on each successful file upload (useful for progress tracking).
const buffer = fs.readFileSync('frontend.zip')
const onUpdate = (tx: Transaction) => console.log(tx.id)
deployer.submitHTML(buffer, 'index.html', onUpdate)
.then(tx => console.log(`Arweave link: ${deployer.getBaseURL()}${tx.id}`))
Using tags
In both submit
& submitHTML
methods you may include an array of optional tags.
const buffer = fs.readFileSync('frontend.zip')
const onUpdate = (tx: Transaction) => console.log(tx.id)
const tags: Tag[] = [
new Tag("Project", "frontend"),
new Tag("Version", "1.0.2"),
new Tag("Milestone", "MVP")
]
deployer.submitHTML(buffer, 'index.html', onUpdate, tags)
.then(tx => console.log(`Arweave link: ${deployer.getBaseURL()}${tx.id}`))