arweave-nft-uploader
v1.1.2
Published
Easily upload images and metadata for your Ethereum (and other) NFTs to Arweave for permanent storage. Compatible with OpenSea!
Downloads
42
Readme
arweave-nft-uploader
If you're creating Eth NFTs and want to save the images and metadata permanently to Arweave, you've come to the right place. All you need to do is give this library your images and metadata and it will give you a list of Arweave URIs that you can use as the TokenURIs when you mint your NFTs.
How to install:
npm i arweave-nft-uploader
or
yarn add arweave-nft-uploader
The correct shape of your images and metadata
- Your images should be in one directory and your corresponding metadata should be in a single
JSON
file as an array of objects. See theexampleData
directory for the correct structure - Your metadata objects should be in the same order that your images are listed in within your image directory. The easiest way to achieve this is to name your images by incrementing number (
1.jpg
,2.jpg
, etc) - The
image
property of the metadata should exist, but can be left empty because it will be overwritten - If you'd like your metadata to show up correctly on OpenSea, please make sure it complies with the OpenSea metadata standards
Calculating the cost of your upload
To fetch the latest price of AR:
getCostOfARInDollars();
To see how much it will cost to save a file or directory in AR and Dollars:
await getCostToSavePathToArweaveInAR('assets/images');
await getCostToSavePathToArweaveInDollars('assets/images');
To get the full cost of your upload, add together the cost of your image directory and metadata file:
const costToUploadImagesInDollars = await getCostToSavePathToArweaveInDollars('assets/images');
const costToUploadMetadataInDollars = await getCostToSavePathToArweaveInDollars('assets/metadata.json');
const totalCostInDollars = costToUploadImagesInDollars + costToUploadMetadataInDollars;
console.log('Total cost: $' + totalCostInDollars)
Or, you may get the cost of uploading a given number of bytes:
await getCostToSaveBytesToArweaveInAR(1024);
await getCostToSaveBytesToArweaveInDollars(1024);
Uploading
Using ArLocal for testing
You may use ArLocal to make sure your upload is correct before spending real money:
const localArweaveInstance = await
// first param is boolean for starting up a new ArLocal instance, second param is a boolean to turn on verbose logging. Both default to true.
connectToLocalArweave();
const testKey = await generateTestKey(localArweaveInstance);
const isMainnet = false;
const arweaveNftUploader = new ArweaveNftUploader(localArweaveInstance, testKey, isMainnet);
const arLocalMetadataUris = await arweaveNftUploader.uploadImageDirAndFullMetadataFile('path/to/image/dir', 'path/to/metadata.json');
The above will return a list of ArLocal metadata URIs for your images and metadata. While the ArLocal instance is still running on port 1984
, you may view them in your browser. Here's an example of what the URIs look like:
['http://localhost:1984/FunHUe__kslRIKi1kSjfLyMsuHxLLg_RShdmxyymQLs', 'http://localhost:1984/w3qa3ayfSDr0eFu__vy-hiPpKOYU67wC8SL7SMyrJqU', ...]
When you check these, be sure to open the image
URI in the browser and ensure the image is correct.
Note
Each testKey is given 1,000 AR when created. If you somehow need more, you may mint more to your key:
await mintTestWinstonsToKey(localArweave, 1000 * WINSTONS_PER_AR, testKey);
Uploading to Arweave Mainnet
Once you've tested uploading your data locally, it's time to do it for real. For this, you'll need some AR.
How to get AR
The easiest way to get AR as an American is to make a Gate.io account, send it BTC and swap for AR. Then transfer that AR to a newly created AR wallet. When you create this wallet, you can paste the contents into a new string as an environment variable.
Next, you can upload in a similar way that you did locally:
const arweaveInstance = connectToArweave();
const key = JSON.parse(process.env["ARWEAVE_KEY"]);
const isMainnet = true;
const arweaveNftUploader = new ArweaveNftUploader(arweaveInstance, key, isMainnet);
const arLocalMetadataUris = await arweaveNftUploader.uploadImageDirAndFullMetadataFile('path/to/image/dir', 'path/to/metadata.json');
Now you'll end up with real Arweave URIs:
[
'https://arweave.net/gRTv8xFiwKQAdr7WzbPNGhoLXYEHepZ98XmsTh-SufI',
'https://arweave.net/0TlnEiPNtHepIlhhZ7JG3R2SPJKTGSOJGOwr7NaZYGU',
'https://arweave.net/zoX_Ez-T3_xZAyXXhlaaWhGYu-S0aiJutfNpsz9TJOE',
]
You're done! All you need to do is use those Arweave URIs as the token URIs in your ETH NFT and OpenSea will read them correctly if they comply to the standard.
Contributing
The workflow
When you're ready to release a new version, use:
npm pushNextVersion