0

I am following the Upload to Arweave example from Solana Cookbook:

This used to work perfectly, but has stopped recently and now returns an HTTP 400 error and:

{
  "error": "Nodes rejected the TX headers"
}

as the response body.

import { promises as fs } from "fs";
import { SECONDS } from "./constants";
import Arweave from "arweave";
import { fileNameToContentType } from "./solana-functions";
import { log, stringify } from "./functions";

const OK = 200;

// See https://solanacookbook.com/references/nfts.html#upload-to-arweave
export const uploadImageToArweave = async (fileName: string) => {
  const data = await fs.readFile(fileName);

  const arweave = Arweave.init({
    host: "arweave.net",
    port: 443,
    protocol: "https",
    timeout: 20 * SECONDS,
    logging: true,
  });

  const contentType = fileNameToContentType(fileName);

  const arWeaveWallet = JSON.parse(
    // File supplied by https://faucet.arweave.net/
    await fs.readFile("arweave-wallet.json", "utf-8")
  );

  const transaction = await arweave.createTransaction({
    data,
  });

  transaction.addTag("Content-Type", contentType);

  await arweave.transactions.sign(transaction, arWeaveWallet);

  const response = await arweave.transactions.post(transaction);

  if (response.status !== OK) {
    log(stringify(response.data));
    throw new Error(`Got ${response.status} error from arWeave`);
  }

  const uploadedImageUrl = `https://arweave.net/${transaction.id}`;
  return uploadedImageUrl;
};

I can't find anything about this error - literally 0 results - using the most popular search engine.

How can I upload something to ARweave successfully?

2
  • Did you able to solve this error using arweave js?
    – Syed
    Commented Aug 14, 2023 at 11:04
  • Sorry @Syed I think I ended up moving to Pinata instead.
    – mikemaccana
    Commented Aug 17, 2023 at 11:54

2 Answers 2

1

I have not used Arweave directly, but Metaplex abstracts it with their JS SDK and bundlr which is extremely easy to use and can be paid with SOL. It's called off of your metaplex instance like so:

import { Metaplex, imageMetaplexFile, bundlrStorage, keypairIdentity } from "@metaplex-foundation/js";

const METAPLEX = Metaplex.make(SOLANA_CONNECTION)
    .use(keypairIdentity(WALLET))
    .use(bundlrStorage({
        address: 'https://devnet.bundlr.network',
        providerUrl: RPC_URL,
        timeout: 60000,
    }));

const imageMetaplexFile = toMetaplexFile(imageBuffer,fileName);

const imageUri = await METAPLEX.storage().upload(imageMetaplexFile );

Here's a guide on how to use Metaplex to upload images (in the context of minting an NFT).

1
1

There are other solutions available to upload data to arweave like you can use irys to upload data to arweave and you can use Arweave/Eth/Polygon etc for the fee. Plz check the currently available options at irys website.

400 could be return due to these listed reasons:

// When chunk is bigger than 256 KiB.
{"error": "chunk_too_big"}

or

// When the proof is bigger than 256 KiB.
{"error": "data_path_too_big"}

or

// When the offset is bigger than 2 ^ 256.
{"error": "offset_too_big"}

or

// When the data size is bigger than 2 ^ 256.
{"error": "data_size_too_big"}

or

/*
  When data_path is bigger than the chunk.
  NOTE: If the original data is too small, it should not be uploaded in chunks. 
  Also, this does not apply to chunks which are the only chunks of their transaction
  and to the last chunk of every transaction.
*/

{"error": "chunk_proof_ratio_not_attractive"}

or

// When the node hasn’t seen the header of the corresponding transaction yet.
{"error": "data_root_not_found"}

or

/*
  The corresponding transaction is pending and it is either of:
   - 50 MiB worth of chunks have been already accepted by this node for this (data root, data size);
   - 2 GiB worth of all pending chunks have been accepted by this node. 
   
  Note: The values above are default values, any node may configure bigger limits.  

*/
{"error": "exceeds_disk_pool_size_limit"}

or

{"error": "invalid_proof"}

Note: most common reason is your wallet doesn't have enough funds to upload data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.