Reputation: 21
I'm trying to deploy non-transferable token on solana. As explained in the document, I used token-program-2022 example with non-transferable extension.
import {
clusterApiUrl,
sendAndConfirmTransaction,
Connection,
Keypair,
SystemProgram,
Transaction,
LAMPORTS_PER_SOL,
} from '@solana/web3.js';
import {
createInitializeNonTransferableMintInstruction,
createInitializeMintInstruction,
getMintLen,
ExtensionType,
TOKEN_2022_PROGRAM_ID,
} from '@solana/spl-token';
(async () => {
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
const payer = Keypair.generate();
const airdropSignature = await connection.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL);
await connection.confirmTransaction({ signature: airdropSignature, ...(await connection.getLatestBlockhash()) });
const mintAuthority = Keypair.generate();
const decimals = 9;
const mintKeypair = Keypair.generate();
const mint = mintKeypair.publicKey;
const mintLen = getMintLen([ExtensionType.NonTransferable]);
const lamports = await connection.getMinimumBalanceForRentExemption(mintLen);
const transaction = new Transaction().add(
SystemProgram.createAccount({
fromPubkey: payer.publicKey,
newAccountPubkey: mint,
space: mintLen,
lamports,
programId: TOKEN_2022_PROGRAM_ID,
}),
createInitializeNonTransferableMintInstruction(mint, TOKEN_2022_PROGRAM_ID),
createInitializeMintInstruction(mint, decimals, mintAuthority.publicKey, null, TOKEN_2022_PROGRAM_ID)
);
await sendAndConfirmTransaction(connection, transaction, [payer, mintKeypair], undefined);
})();
But my transaction failed with this logs.
SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 1: custom program error: 0xc
at Connection.sendEncodedTransaction (/Users/user/Desktop/workspace/solana-nft-js-test/node_modules/@solana/web3.js/src/connection.ts:4825:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Connection.sendRawTransaction (/Users/user/Desktop/workspace/solana-nft-js-test/node_modules/@solana/web3.js/src/connection.ts:4784:20)
at async Connection.sendTransaction (/Users/user/Desktop/workspace/solana-nft-js-test/node_modules/@solana/web3.js/src/connection.ts:4772:12)
at async sendAndConfirmTransaction (/Users/user/Desktop/workspace/solana-nft-js-test/node_modules/@solana/web3.js/src/utils/send-and-confirm-transaction.ts:31:21)
at async /Users/user/Desktop/workspace/solana-nft-js-test/src/example.ts:87:3 {
logs: [
'Program 11111111111111111111111111111111 invoke [1]',
'Program 11111111111111111111111111111111 success',
'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]',
'Program log: Error: Invalid instruction',
'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 725 of 600000 compute units',
'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0xc'
]
}
I can't find the reason why the transaction failed. Is token-program-2022 deployed on the 'devnet' different from the program in spl git repository?
Upvotes: 2
Views: 380