forked from solana-labs/solana-program-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreallocate.ts
62 lines (57 loc) · 1.7 KB
/
reallocate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {
clusterApiUrl,
sendAndConfirmTransaction,
Connection,
Keypair,
Transaction,
LAMPORTS_PER_SOL,
} from '@solana/web3.js';
import {
createAccount,
createMint,
createEnableRequiredMemoTransfersInstruction,
createReallocateInstruction,
ExtensionType,
TOKEN_2022_PROGRAM_ID,
} from '../src';
(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 mint = await createMint(
connection,
payer,
mintAuthority.publicKey,
mintAuthority.publicKey,
decimals,
undefined,
undefined,
TOKEN_2022_PROGRAM_ID,
);
const owner = Keypair.generate();
const account = await createAccount(
connection,
payer,
mint,
owner.publicKey,
undefined,
undefined,
TOKEN_2022_PROGRAM_ID,
);
const extensions = [ExtensionType.MemoTransfer];
const transaction = new Transaction().add(
createReallocateInstruction(
account,
payer.publicKey,
extensions,
owner.publicKey,
undefined,
TOKEN_2022_PROGRAM_ID,
),
createEnableRequiredMemoTransfersInstruction(account, owner.publicKey, [], TOKEN_2022_PROGRAM_ID),
);
await sendAndConfirmTransaction(connection, transaction, [payer, owner], undefined);
})();