-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransfer-interface.ts
More file actions
51 lines (44 loc) · 1.32 KB
/
transfer-interface.ts
File metadata and controls
51 lines (44 loc) · 1.32 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
51
import "dotenv/config";
import { Keypair } from "@solana/web3.js";
import { createRpc } from "@lightprotocol/stateless.js";
import {
createMintInterface,
createAtaInterface,
mintToInterface,
transferInterface,
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 sender = Keypair.generate();
await createAtaInterface(rpc, payer, mint, sender.publicKey);
const senderAta = getAssociatedTokenAddressInterface(
mint,
sender.publicKey
);
await mintToInterface(rpc, payer, mint, senderAta, payer, 1_000_000_000);
const recipient = Keypair.generate();
const tx = await transferInterface(
rpc,
payer,
senderAta,
mint,
recipient.publicKey,
sender.publicKey,
sender,
500_000_000
);
console.log("Tx:", tx);
})();