2

i am trying to create and initialize candy machine config account from web application but transaction failed with following error:

Are there some special need why every tutorial is based on node,js and just minting is on web? Here is code snippet with following steps:

  1. Create authority account and airdrop some lamports
  2. Create candy machine config account
  3. Initialize candy machine config account (fail)

Log:

Transaction simulation failed: Error processing Instruction 1: custom program error: 0x8f 
    Program 11111111111111111111111111111111 invoke [1]
    Program 11111111111111111111111111111111 success
    Program cndyAnrLdpjq1Ssp1z8xxDsB8dxe7u4HL5Nxi2K5WXZ invoke [1]
    Program log: Custom program error: 0x8f
    Program cndyAnrLdpjq1Ssp1z8xxDsB8dxe7u4HL5Nxi2K5WXZ consumed 6437 of 200000 compute units
    Program cndyAnrLdpjq1Ssp1z8xxDsB8dxe7u4HL5Nxi2K5WXZ failed: custom program error: 0x8f

enter image description here

import { Keypair, PublicKey } from "@solana/web3.js"
import { useWorkspace } from "@/composables/useWorkspace"
import { SYSVAR_RENT_PUBKEY, CONFIG_ARRAY_START, CONFIG_LINE_SIZE, CANDY_MACHINE_PROGRAM_ID, SYSTEM_PROGRAM_ID } from "./constants"
import BN from "bn.js"
import * as anchor from '@project-serum/anchor';

let anchorWallet = null;
let solanaConnection = null;
let candyMachineProgram = null;

export const init = () => {
    const { wallet, connection, candyMachine } = useWorkspace();
    anchorWallet = wallet;
    solanaConnection = connection;
    candyMachineProgram = candyMachine;
}

const candyMachineAccountSpace = (numLines) => {
    return CONFIG_ARRAY_START + 4 + numLines * CONFIG_LINE_SIZE + 4 + Math.ceil(numLines / 8.0)
};

export const mintNft = async (metadata) => {
    let candyMachineConfig = Keypair.generate();
    let authority = Keypair.generate();

    await airdrop(authority.publicKey, 1);

    await initializeCandyMachineAccount(metadata, candyMachineConfig, authority);
}

const createAccount = async (account) => {
    let minimumAmountForRent = await solanaConnection.getMinimumBalanceForRentExemption(
        candyMachineAccountSpace(1),
    );
    console.log("Account space need: " + candyMachineAccountSpace(1))
    console.log("Minimum rent for config account: " + minimumAmountForRent);
    console.log("From account: " + anchorWallet.value.publicKey);
    console.log("To account: " + account.publicKey);
 

    return anchor.web3.SystemProgram.createAccount({
        fromPubkey: anchorWallet.value.publicKey,
        newAccountPubkey: account.publicKey,
        space: candyMachineAccountSpace(1),
        lamports: minimumAmountForRent,
        programId: new PublicKey(CANDY_MACHINE_PROGRAM_ID),
    });
}

const airdrop = async (address, amount) => {
    return await solanaConnection.requestAirdrop(address, amount);
}

const initializeCandyMachineAccount = async (metadata, candyMachineConfig, authority) => {
    let cmuuid = candyMachineConfig.publicKey.toBase58().slice(0, 6) //;
    console.log("cmuuid: " + cmuuid);
    console.log("Symbol: " + metadata.symbol);
    console.log("Seller fee: " + metadata.sellerFeeBasisPoints);
    console.log("Rent: " + new PublicKey(SYSVAR_RENT_PUBKEY));
    console.log("Wallet: ");

    candyMachineProgram.value.rpc.initializeConfig(
        {
            uuid: cmuuid,
            maxNumberOfLines: new BN(1),
            symbol: metadata.symbol, 
            sellerFeeBasis: metadata.sellerFeeBasisPoints,
            isMutable: true, 
            maxSupply: new BN(1),
            retainAuthority: true,
            creators: [ 
                {
                    address: anchorWallet.value.publicKey,
                    share: 100
                }
            ]
        },
        {
            accounts: {
                config: candyMachineConfig.publicKey,
                authority: authority.publicKey,
                payer: authority.publicKey,
                systemProgram: SYSTEM_PROGRAM_ID,
                rent: new PublicKey(SYSVAR_RENT_PUBKEY),
            },
            preInstructions: [
                //await createAccount(authority), // created by airdrop
                await createAccount(candyMachineConfig)
            ],
            signers: [candyMachineConfig, authority],
        }
    )
}
Daniel
  • 91
  • 4

0 Answers0