-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate-ata.ts
More file actions
50 lines (43 loc) · 1.36 KB
/
create-ata.ts
File metadata and controls
50 lines (43 loc) · 1.36 KB
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
import "dotenv/config";
import {
Keypair,
Transaction,
sendAndConfirmTransaction,
} from "@solana/web3.js";
import { createRpc, CTOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js";
import {
createMintInterface,
createAssociatedTokenAccountInterfaceInstruction,
getAssociatedTokenAddressInterface,
} from "@lightprotocol/compressed-token";
import { homedir } from "os";
import { readFileSync } from "fs";
// devnet:
// const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
// const rpc = createRpc(RPC_URL);
// localnet:
const rpc = createRpc();
const payer = Keypair.fromSecretKey(
new Uint8Array(
JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8"))
)
);
(async function () {
const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
const owner = Keypair.generate();
const associatedToken = getAssociatedTokenAddressInterface(
mint,
owner.publicKey
);
const ix = createAssociatedTokenAccountInterfaceInstruction(
payer.publicKey,
associatedToken,
owner.publicKey,
mint,
CTOKEN_PROGRAM_ID
);
const tx = new Transaction().add(ix);
const signature = await sendAndConfirmTransaction(rpc, tx, [payer]);
console.log("ATA:", associatedToken.toBase58());
console.log("Tx:", signature);
})();