Created
April 24, 2022 14:38
-
-
Save jstorm31/c98804dce3193f89fcc845e1ec144dc9 to your computer and use it in GitHub Desktop.
Mint NFT ticket with Cardinal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes'; | |
import { Wallet } from '@project-serum/anchor'; | |
import { clusterApiUrl, Connection, Keypair, PublicKey, sendAndConfirmRawTransaction } from '@solana/web3.js'; | |
import { IssueParameters, issueToken } from '@cardinal/token-manager'; | |
import { InvalidationType, TokenManagerKind } from '@cardinal/token-manager/dist/cjs/programs/tokenManager'; | |
const connection = new Connection(clusterApiUrl('devnet')); | |
// Test account created by solana CLI | |
const issuerPublicKey = new PublicKey('3RtKcbE5LpSScrEHHNiGBBD25xVNPLezbY7S2TAwdXis'); | |
const issuerSecretKey = Uint8Array.from([...]); // Private key value hidden | |
// Phantom wallet account | |
const payerPublicKey = new PublicKey('9SfTMJ5wnVCug5v5M8fZEf3QeeqiWVMdo9FT5HvnkksB'); | |
const payerSecretKey = new Uint8Array(bs58.decode('...')); // Private key value hidden | |
const issuerWallet = new Wallet(Keypair.fromSecretKey(issuerSecretKey)); | |
const payerWallet = new Wallet(Keypair.fromSecretKey(payerSecretKey)); | |
const issuer = { publicKey: issuerPublicKey, secretKey: issuerSecretKey }; | |
const payer = { publicKey: payerPublicKey, secretKey: payerSecretKey }; | |
const issueTokenParameters: IssueParameters = { | |
mint: issuerPublicKey, | |
issuerTokenAccountId: issuerPublicKey, | |
invalidationType: InvalidationType.Invalidate, | |
useInvalidation: { | |
totalUsages: 1, | |
}, | |
visibility: 'public', | |
kind: TokenManagerKind.Unmanaged, | |
claimPayment: { | |
paymentMint: issuerPublicKey, | |
paymentAmount: 0.01, | |
}, | |
}; | |
const issueTicket = async () => { | |
const [transaction] = await issueToken(connection, issuerWallet, issueTokenParameters); | |
const blockhash = await connection.getLatestBlockhash(); | |
transaction.feePayer = payerWallet.publicKey; | |
transaction.recentBlockhash = blockhash.blockhash; | |
transaction.sign(payer, issuer); | |
await sendAndConfirmRawTransaction(connection, transaction.serialize(), { | |
commitment: 'confirmed', | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment