1

我正在尝试从 Web 应用程序创建和初始化糖果机配置帐户,但交易失败并出现以下错误:

为什么每个教程都基于 node、js 而只是铸币是在网络上,有什么特殊需要吗?这是包含以下步骤的代码片段:

  1. 创建权限账户并空投一些灯
  2. 创建糖果机配置帐户
  3. 初始化糖果机配置账户(失败)

日志:

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

在此处输入图像描述

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],
        }
    )
}
4

0 回答 0