4

when I transfer nft to my another account. It makes error.

export const createWalletKey = async () => {
  const bs58 = require("bs58");
  const bs = bs58.decode(secretKey);
  const wallet = Keypair.fromSecretKey(bs); // get wallet keypair
  const connection = new Connection(clusterApiUrl("devnet"), "confirmed");

  connectWithMetaplex(wallet);
};
export const connectWithMetaplex = async wallet => {
  const bs58 = require("bs58");
  const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
  const bs = bs58.decode(anotherSecretKey);
  const toWallet = Keypair.fromSecretKey(bs); // get wallet keypair
  const metaplex = Metaplex.make(connection).use(keypairIdentity(wallet));
  const { nft } = await metaplex
    .nfts()
    .create({
      uri: "",
      name: "JERRY NFT",
      sellerFeeBasisPoints: 100,
    })
    .run();

  const fromTokenAccount = await getOrCreateAssociatedTokenAccount(
    connection,
    wallet,
    nft.mintAddress,
    wallet.publicKey,
  );

  console.log("fromTokenAccount", fromTokenAccount.address.toString());

  const toTokenAccount = await getOrCreateAssociatedTokenAccount(
    connection,
    wallet,
    nft.mintAddress,
    toWallet.publicKey,
  );

  console.log(LAMPORTS_PER_SOL);
  const transaction = new Transaction().add(
    createTransferInstruction(
      fromTokenAccount.address,
      toTokenAccount.address,
      wallet.publicKey,
      LAMPORTS_PER_SOL * 10,
      [],
      TOKEN_PROGRAM_ID,
    ),
  );

  const blockHash = await connection.getLatestBlockhash();
  transaction.feePayer = await wallet.publicKey;
  transaction.recentBlockhash = await blockHash.blockhash;
  console.log(transaction);
};

I have 10 SOL in devnet :(

2
  • Please post the full error in the body of your question
    – C.OG
    Aug 1, 2022 at 7:50
  • What secret key are you making your wallet from? Is it your provider's secret key?
    – Ademola
    Aug 1, 2022 at 10:14

3 Answers 3

5

Custom program error: 0x1 implies that you have insufficient funds to execute the transaction.

  1. You are trying to transfer LAMPORTS_PER_SOL * 10 lamports between two accounts.
  2. You mentioned that you have exactly 10 SOL in devnet.

While, at first glance, the source account might appear to have sufficient funds to cover the transfer, you also need to consider that the source account must pay the network fee.

Try reducing the transfer amount. Note that you can query the network fee by using the getFeeForMessage API.

2

As the others have said the problem is insufficient SOL,

here is how to get SOL or lamports in devnet / testnet / mainnet:

    const airdropSignature = await connection.requestAirdrop(
        keypair.publicKey, 2 * LAMPORTS_PER_SOL);

      const latestBlockHash = await connection.getLatestBlockhash();

      await connection.confirmTransaction({
        blockhash: latestBlockHash.blockhash,
        lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
        signature: airdropSignature,
      });

for Anchor tests, add provider. in front of the connection in the above code.

0

comment resoudre une transfer Custom program error: 0x1 implies that you have insufficient funds to execute the transaction.

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.