0

I am playing around with metaplex and umi. Trying to create a collection with candy machine to mint from that candy machine. I have created candy machine and inserted my assets in that candy machine. Now, I want to mint from that candy machine. What I am trying to do is that, mimic the real world scenario where a person pays for the mint. For that, I have tried below approach:

const mintFromCandyMachine = async (candyMachine: KeypairSigner, collectinMint: KeypairSigner) => {
    const nftMint = generateSigner(umi); // address of newly minted nft
    const minter = await walletSecretToArray();
    minter && await transactionBuilder()
        .add(setComputeUnitLimit(umi, { units: 800_000 }))
        .add(
            mintV2(umi, {
                candyMachine: candyMachine.publicKey,
                nftMint: nftMint,
                collectionMint: collectinMint.publicKey,
                collectionUpdateAuthority: myKeypair.publicKey,
                minter: minter,
                payer: minter

            })
        )
    }

const walletSecretToArray = async () => {
    const secretUint8Array = process.env.DEV_WALLET_SECRET && bs58.decode('2W6VSdXgXVquZKyvTRYhW7TEKLc2qbd4gXwV8u8kiAdphWfhMkqNWKcbggxgc2xwXCiXHTF3dSvexW1VwH12ZNW5');
    return secretUint8Array && Keypair.fromSecretKey(secretUint8Array)
    // const secretKeyArray = secretUintArray && Array.from(secretUintArray);
    // const userWallet = secretKeyArray && Keypair.fromSecretKey(new Uint8Array(secretKeyArray));
    // const myKeypair = userWallet && umi.eddsa.createKeypairFromSecretKey(userWallet?.secretKey);
    // return myKeypair;
}

However, I get below error for minter and payer fields in mintV2 function

Type 'Keypair' is missing the following properties from type 'Signer': signMessage, signTransaction, signAllTransactionsts(2739)
mintV2.d.ts(28, 5): The expected type comes from property 'minter' which is declared here on type 'MintV2InstructionAccounts & MintV2InstructionDataArgs<DefaultGuardSetMintArgs>'

How do I create Signer for minter and payer fields?

Here is how I created the umi instance

const solanaConnection = new Connection(endpoint);
const umi = createUmi(solanaConnection).use(mplTokenMetadata()).use(mplCandyMachine());
const userWallet = Keypair.fromSecretKey(new Uint8Array(secret));
const myKeypair = umi.eddsa.createKeypairFromSecretKey(userWallet.secretKey);
const myKeypairSigner: KeypairSigner = createSignerFromKeypair(umi, myKeypair);
const irys = getIrysUploaderInstance(umi, myKeypairSigner);
umi.use(signerIdentity(myKeypairSigner));

1 Answer 1

0

Found the solution. I need to create the keyPairSigner for the wallet that wants to mint. So, needed to use createSignerFromKeypair function. So, the function walletSecretToArray is now changed to

const createMinterWalletSigner = async () => {
    const secretUint8Array = process.env.DEV_WALLET_SECRET && bs58.decode(process.env.DEV_WALLET_SECRET);
    const secretKeyArray = secretUint8Array && Array.from(secretUint8Array);
    const userWallet = secretKeyArray && Keypair.fromSecretKey(new Uint8Array(secretKeyArray));
    const myKeypair = userWallet && umi.eddsa.createKeypairFromSecretKey(userWallet?.secretKey);
    const minterKeyPairSigner = myKeypair && createSignerFromKeypair(umi, myKeypair);
    return minterKeyPairSigner;
}

Not the best written function but, it is just for experimentation purpose for now

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.