1.2.1 • Published 1 year ago

@theplatformpublishing/arweave-deploy v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

arweave-deploy 🚀

Usage

Initialise the deployer

import ArweaveDeploy from '@theplatformpublishing/arweave-deploy'

To start deploying content to Arweave you will need to specify:

  1. the Arweave network that will process the transactions,
  2. 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}`))
1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.2.1

1 year ago

1.0.3

1 year ago

1.0.2

2 years ago

0.0.1-pre.1

2 years ago

0.0.1-pre.0

2 years ago

0.0.1

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago