arweave-archive is a node package that allows you to archive webpage and screenshot of the desired url on the Arweave blockchain. It provides a convenient way to store web content permanently and securely.
Using npm,
npm install arweave-archive
Using yarn,
yarn add arweave-archive
Using pnpm,
pnpm add arweave-archive
To use the Arweave Archive package, import it and create an instance of the ArweaveArchiver
class. You need to provide a JSON Web Key (JWK) or a path to a JWK file, which will be used to sign transactions. Optionally, you can also provide the gateway and bundler URLs and browserless options. If browserless options is not provided, locally installed Chrome browser is used to capture the webpage and screenshot of the provided url using puppeteer.
import { ArweaveArchiver } from 'arweave-archive'
const jwk = '<your-jwk-file-path-or-data>'
const options = {
gatewayUrl: 'https://arweave.net',
bundlerUrl: 'https://node2.bundlr.network',
}
const archiver = new ArweaveArchiver(jwk, options)
The ArweaveArchiver
class allows you to configure the following options:
gatewayUrl
(optional): The URL of the Arweave gateway to use for uploading and accessing archived webpages. (default: 'https://arweave.net')bundlerUrl
(optional): The URL of the Arweave bundler to use for bundling and uploading archives. (default: 'https://node2.bundlr.network')browserOptions
(optional): HtmlScreenshotSaverOptions
Here's an example of how you can set the browserOptions:
const options = {
gatewayUrl: 'https://ar-io.net',
browserOptions: {
browserHeadless: true,
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
browserHeight: 1080,
browserWidth: 1920,
browserlessOptions: {
apiKey: 'your-api-key',
blockAds: true,
stealth: true,
userDataDir: 'your-user-data-dir',
keepalive: 60000,
ignoreDefaultArgs: '--disable-extensions',
timeout: 60000
}
}
}
const archiver = new ArweaveArchiver(jwk, options)
Please note that the browserlessOptions is optional, and you can omit them if you don't need to use it for capturing webpage and screenshots of the provided url.
You can archive a webpage by providing its URL to the archiveUrl
method. The method returns a promise that resolves to an ArchiveResult
object, containing the status of the archive process, a message, the transaction ID, the title of the webpage, and the timestamp.
const output = await archiver.archiveUrl('https://github.com/pawanpaudel93')
console.log(output)
You can retrieve a list of all archived webpages or get the latest archived webpage for a specific wallet address or the provided wallet itself.
To get all archived webpages, use the getAllArchives
method. It returns a promise that resolves to an array of Archive
objects, representing each archived webpage. Each object contains the ID, URL, title, webpage URL, screenshot URL, and timestamp.
// Get all archives of the loaded Arweave wallet JWK
const allArchives = await archiver.getAllArchives();
console.log(allArchives)
// Get all archives of a wallet address
const allAddressArchives = await archiver.getAllArchives("some-wallet-address");
console.log(allAddressArchives)
To get the latest archived webpage for a specific wallet address or the provided wallet itself, use the getLatestArchive
method. It returns a promise that resolves to an Archive
object representing the latest archived webpage, or null if no archived webpages are found.
// Get latest archive of the loaded Arweave wallet JWK
const latestArchive = await archiver.getLatestArchive();
console.log(latestArchive)
// Get latest archive of a wallet address
const latestAddressArchive = await archiver.getLatestArchive("some-wallet-address");
console.log(latestAddressArchive)
👤 Pawan Paudel
- Github: @pawanpaudel93
Contributions, issues and feature requests are welcome! \ Feel free to check issues page.
Give a ⭐️ if this project helped you!
Copyright © 2023 Pawan Paudel