I am trying do a tutorial following these docs to try to create and mint tokens on metaplex but receiving this warning here which will eventually trigger an error if I run the code obviously -
Type 'PublicKey' is not assignable to type 'PublicKey | Pda | undefined'.
Type 'PublicKey' is not assignable to type 'Pda'.
Type 'PublicKey' is not assignable to type '[PublicKey<string>, number]'.ts(2322)
mintV1.d.ts(15, 5): The expected type comes from property 'tokenOwner' which is declared here on type 'MintV1InstructionAccounts & MintV1InstructionDataArgs & MintV1InstructionExtraArgs'
This is my code -
import { payer, testWallet, connection } from "@/lib/vars";
import * as fs from "fs";
import * as path from "path";
import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
import { MINT_SIZE, TOKEN_PROGRAM_ID, createInitializeMint2Instruction } from "@solana/spl-token";
import { generateSigner, percentAmount, some, signerIdentity, createSignerFromKeypair } from '@metaplex-foundation/umi';
import { createV1, mintV1, TokenStandard, createFungible, mplTokenMetadata } from '@metaplex-foundation/mpl-token-metadata';
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'; // If using the bundle
(async () => {
const umi = createUmi(connection)
const walletFile = fs.readFileSync(
path.join(__dirname, '../my_keypair.json') // Move one directory up
);
// Parse the JSON string into an array
const secretKeyArray = JSON.parse(walletFile.toString());
// Create the keypair from the parsed array
let keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(secretKeyArray));
const signer = createSignerFromKeypair(umi, keypair);
// Tell Umi to use the new signer.
umi.use(signerIdentity(signer)).use(mplTokenMetadata())
// Create a signer for the mint account
const mint = generateSigner(umi);
// Define authority and token owner
const authority = umi.identity; // Use identity as authority
const tokenOwner = new PublicKey(payer.publicKey); // Ensure it's a PublicKey instance
console.log('tokenOwner', tokenOwner);
const my_keypair = new PublicKey(keypair.publicKey); // Ensure it's a PublicKey instance
console.log('my_keypair', my_keypair);
// Derive the PDA for tokenOwner
const [tokenOwnerPda] = PublicKey.findProgramAddressSync(
[Buffer.from("token_owner_seed"), payer.publicKey.toBuffer()], // Use appropriate seed
TOKEN_PROGRAM_ID // Use the SPL Token Program ID here
);
// Create Fungible asset
await createFungible(umi, {
mint,
name: 'My Fungible Token',
uri: 'https://example.com/my-fungible-token.json', // Replace with your metadata URI
sellerFeeBasisPoints: percentAmount(5.5), // Set seller fee basis points
decimals: some(2), // Number of decimal places for the fungible token
}).sendAndConfirm(umi);
// Optionally, you can mint tokens after creation if needed
await mintV1(umi, {
mint: mint.publicKey,
authority,
amount: 1000, // Amount of tokens to mint
tokenOwner: tokenOwner,
tokenStandard: TokenStandard.Fungible,
}).sendAndConfirm(umi);
})();
I have tried using pda public address (tokenOwnerPda), normal public address (tokenOwner) and the address that created the token (my_keypair), but none of them works - they are all triggering the same error - These are the docs and it states that it expects "tokenOwner?: PublicKey | Pda" which is what I have already but it continues to trigger the error.
I am running on local (solana test validator) and I have successfully imported the programs from devnet. I have also made sure that
I have enough sol in each address I have tried to use.
I have tried using .toString()
and toBase58()
formats - they all do not work.
I hope someone has insights on how to fix this. Thanks