Cardinal
Search…
⌃K

Creating a CCS Token

Creating a CCS token in as simple as:
  1. 1.
    Initializing the token mint
  2. 2.
    Creating metadata for the mint
  3. 3.
    Creating a mint manager for the mint that takes the mint's mint and freeze authority
1
// Imports
2
import { findAta } from "@cardinal/common";
3
import {
4
CreateMetadataV2,
5
Creator,
6
DataV2,
7
Metadata,
8
} from "@metaplex-foundation/mpl-token-metadata";
9
import * as anchor from "@project-serum/anchor";
10
import { Keypair, PublicKey } from "@solana/web3.js";
11
import {
12
createAssociatedTokenAccountInstruction,
13
createInitializeMint2Instruction,
14
createMintToInstruction,
15
getAssociatedTokenAddressSync,
16
getMinimumBalanceForRentExemptMint,
17
MINT_SIZE,
18
TOKEN_PROGRAM_ID,
19
} from "@solana/spl-token";
20
import { findMintManagerId, findRulesetId, createInitMintManagerInstruction, Ruleset } from "@cardinal/creator-standard";
21
22
const wallet = Keypair.fromSecretKey(
23
anchor.utils.bytes.bs58.decode("wallet secret key")
24
); // your wallet's secret key // your wallet's secret key
25
26
// Setup
27
const rulesetName = "ruleset-name"
28
const mintKeypair = Keypair.generate();
29
const rulesetId = findRulesetId(rulesetName);
30
const rulesetData = await Ruleset.fromAccountAddress(connection, rulesetId);
31
const mintManagerId = findMintManagerId(mintKeypair.publicKey);
32
const holdetAta = await findAta(
33
mintKeypair.publicKey,
34
wallet.publicKey,
35
true
36
);
37
38
// Initialize mint
39
const ata = getAssociatedTokenAddressSync(mint, wallet.publicKey);
40
tx.add(
41
SystemProgram.createAccount({
42
fromPubkey: wallet.publicKey,
43
newAccountPubkey: mintKeypair.publicKey,
44
space: MINT_SIZE,
45
lamports: await getMinimumBalanceForRentExemptMint(connection),
46
programId: TOKEN_PROGRAM_ID,
47
}),
48
createInitializeMint2Instruction(mintKeypair.publicKey, 0, wallet.publicKey, wallet.publicKey),
49
createAssociatedTokenAccountInstruction(wallet.publicKey, ata, wallet.publicKey, mintKeypair.publicKey),
50
createMintToInstruction(mintKeypair.publicKey, ata, wallet.publicKey, 1)
51
);
52
53
// Create metadata
54
const metadataName = "name";
55
const metadataSymbol = "symbol";
56
const metadataUri = "uri";
57
const metadataId = await Metadata.getPDA(mintKeypair.publicKey);
58
tx.instructions.push(
59
...new CreateMetadataV2(
60
{ feePayer: wallet.publicKey },
61
{
62
metadata: metadataId,
63
metadataData: new DataV2({
64
name: metadataName,
65
symbol: metadataSymbol,
66
uri: metadataUri,
67
sellerFeeBasisPoints: 500,
68
creators: [
69
new Creator({
70
address: wallet.publicKey.toString(),
71
verified: false,
72
share: 100,
73
}),
74
],
75
collection: null,
76
uses: null,
77
}),
78
updateAuthority: wallet.publicKey,
79
mint: mintKeypair.publicKey,
80
mintAuthority: wallet.publicKey,
81
}
82
).instructions
83
);
84
85
// Create mint manager
86
tx.add(
87
createInitMintManagerInstruction({
88
mintManager: mintManagerId,
89
mint: mintKeypair.publicKey,
90
ruleset: rulesetId,
91
holderTokenAccount: holdetAta,
92
tokenAuthority: wallet.publicKey,
93
rulesetCollector: rulesetData.collector,
94
collector: rulesetData.collector,
95
authority: wallet.publicKey,
96
payer: wallet.publicKey,
97
})
98
);
99
100
// Execute transaction
101
txid = await executeTransaction(
102
connection,
103
transaction,
104
new anchor.Wallet(wallet)
105
);