Skip to content

Commit 9efdc35

Browse files
wip
1 parent 2828bb4 commit 9efdc35

16 files changed

+175
-238
lines changed

package-lock.json

Lines changed: 59 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
},
3636
"homepage": "https://github.com/Lightprotocol/example-nodejs-client#readme",
3737
"dependencies": {
38-
"@lightprotocol/compressed-token": "0.20.9",
39-
"@lightprotocol/stateless.js": "0.20.9",
38+
"@lightprotocol/compressed-token": "file:../light-protocol/js/compressed-token",
39+
"@lightprotocol/stateless.js": "file:../light-protocol/js/stateless.js",
4040
"@solana/spl-token": "0.3.9",
4141
"@solana/spl-token-metadata": "^0.1.6",
4242
"@solana/web3.js": "^1.98.0",
4343
"@types/node": "^20.12.7",
44-
"bn.js": "^5.2.1",
44+
"bn.js": "^5.1.2",
4545
"bs58": "^6.0.0",
4646
"dotenv": "^16.4.5",
4747
"ts-node": "^10.9.2",

src/constants.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@ export const RPC_ENDPOINT = process.env.RPC_ENDPOINT;
77
export const PAYER_KEYPAIR = Keypair.fromSecretKey(
88
bs58.decode(process.env.PAYER_KEYPAIR!)
99
);
10-
1110
export const MINT_ADDRESS = new PublicKey(process.env.MINT_ADDRESS!);
12-
13-
export const AUTHORITY_KEYPAIR = process.env.LUT_AUTHORITY_KEYPAIR
14-
? Keypair.fromSecretKey(
15-
Uint8Array.from(JSON.parse(process.env.LUT_AUTHORITY_KEYPAIR))
16-
)
17-
: undefined;
18-
19-
export const BOB_KEYPAIR = process.env.BOB_KEYPAIR
20-
? Keypair.fromSecretKey(Uint8Array.from(JSON.parse(process.env.BOB_KEYPAIR)))
21-
: undefined;
11+
export const AUTHORITY_KEYPAIR = Keypair.fromSecretKey(
12+
Uint8Array.from(JSON.parse(process.env.LUT_AUTHORITY_KEYPAIR!))
13+
);
14+
export const BOB_KEYPAIR = Keypair.fromSecretKey(
15+
Uint8Array.from(JSON.parse(process.env.BOB_KEYPAIR!))
16+
);
2217

2318
export const LUT_MAINNET_AUTHORITY_KEYPAIR = process.env.LUT_AUTHORITY_KEYPAIR
2419
? Keypair.fromSecretKey(
@@ -34,5 +29,8 @@ if (!RPC_ENDPOINT) throw new Error("Please set RPC_ENDPOINT in .env");
3429
if (!PAYER_KEYPAIR)
3530
throw new Error("Please set PAYER_KEYPAIR as bs58 string in .env");
3631
if (!MINT_ADDRESS) throw new Error("Please set MINT_ADDRESS in .env");
32+
if (!AUTHORITY_KEYPAIR)
33+
throw new Error("Please set LUT_AUTHORITY_KEYPAIR in .env");
34+
if (!BOB_KEYPAIR) throw new Error("Please set BOB_KEYPAIR in .env");
3735

3836
console.log("PAYER PUBLIC KEY:", PAYER_KEYPAIR.publicKey.toString());

src/internal/create-account-pulse.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
createRpc,
44
LightSystemProgram,
55
Rpc,
6+
selectStateTreeInfo,
67
} from "@lightprotocol/stateless.js";
78
import { PAYER_KEYPAIR, RPC_ENDPOINT } from "../constants";
89
import { randomBytes } from "crypto";
9-
import { PublicKey } from "@solana/web3.js";
1010

1111
const fromKeypair = PAYER_KEYPAIR;
1212

@@ -26,7 +26,9 @@ const trees = [
2626
(async () => {
2727
try {
2828
while (true) {
29-
const pseudoRandomTree = trees[Math.floor(Math.random() * trees.length)];
29+
const infos = await connection.getCachedActiveStateTreeInfos();
30+
const info = selectStateTreeInfo(infos);
31+
3032
// Create account with random address
3133
const randomSeed = new Uint8Array(randomBytes(32));
3234
const txId = await createAccount(
@@ -35,8 +37,7 @@ const trees = [
3537
[randomSeed],
3638
LightSystemProgram.programId,
3739
undefined,
38-
undefined,
39-
new PublicKey(pseudoRandomTree)
40+
info
4041
);
4142
console.log(
4243
`Compressed Account Creation Success. Transaction Signature:`,

src/internal/create-account-with-lamports-pulse.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
createAccountWithLamports,
55
createRpc,
66
LightSystemProgram,
7-
pickRandomTreeAndQueue,
87
Rpc,
8+
selectStateTreeInfo,
99
} from "@lightprotocol/stateless.js";
1010
import { PAYER_KEYPAIR, RPC_ENDPOINT } from "../constants";
1111
import { randomBytes } from "crypto";
@@ -16,16 +16,15 @@ const connection: Rpc = createRpc(RPC_ENDPOINT);
1616
(async () => {
1717
try {
1818
while (true) {
19-
const activeStateTrees = await connection.getCachedActiveStateTreeInfo();
20-
21-
const { tree, queue } = pickRandomTreeAndQueue(activeStateTrees);
22-
console.log("Picked output state tree:", tree.toBase58());
19+
const infos = await connection.getCachedActiveStateTreeInfos();
20+
const info = selectStateTreeInfo(infos);
21+
console.log("Picked output state tree:", info.tree.toBase58());
2322
const compressedTxId = await compress(
2423
connection,
2524
fromKeypair,
2625
bn(10),
2726
fromKeypair.publicKey,
28-
tree
27+
info
2928
);
3029
console.log("Compressed TxId", compressedTxId);
3130
// Creat account with random address
@@ -36,8 +35,7 @@ const connection: Rpc = createRpc(RPC_ENDPOINT);
3635
10,
3736
LightSystemProgram.programId,
3837
undefined,
39-
undefined,
40-
tree
38+
info
4139
);
4240
console.log(
4341
`Compressed Account Creation Success. Transaction Signature:`,

0 commit comments

Comments
 (0)