Skip to content

Commit 297eb5c

Browse files
committed
add new examples
1 parent 1752995 commit 297eb5c

File tree

5 files changed

+106
-4
lines changed

5 files changed

+106
-4
lines changed

apps/web/content/cookbook/accounts/calculate-rent.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ if the account is closed.
1212

1313
<CodeTabs storage="cookbook" flags="r">
1414

15+
```ts !! title="Gill"
16+
import { createSolanaClient } from "gill";
17+
18+
const { rpc } = createSolanaClient({
19+
urlOrMoniker: "localnet",
20+
});
21+
22+
const space = 1500n; // bytes
23+
// !mark
24+
const lamports = await rpc.getMinimumBalanceForRentExemption(space).send();
25+
console.log("Minimum balance for rent exemption:", lamports);
26+
```
27+
1528
```ts !! title="Kit"
1629
import { createSolanaRpc } from "@solana/kit";
1730

apps/web/content/cookbook/accounts/create-account.mdx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,74 @@ can then initialize the account data through its own instructions.
2424

2525
<CodeTabs storage="cookbook" flags="r">
2626

27+
```ts !! title="Gill"
28+
import {
29+
airdropFactory,
30+
appendTransactionMessageInstructions,
31+
createSolanaRpc,
32+
createSolanaRpcSubscriptions,
33+
createTransaction,
34+
generateKeyPairSigner,
35+
getSignatureFromTransaction,
36+
lamports,
37+
pipe,
38+
sendAndConfirmTransactionFactory,
39+
setTransactionMessageFeePayerSigner,
40+
setTransactionMessageLifetimeUsingBlockhash,
41+
signTransactionMessageWithSigners
42+
} from "gill";
43+
import {
44+
getCreateAccountInstruction,
45+
SYSTEM_PROGRAM_ADDRESS
46+
} from "@solana-program/system";
47+
48+
const { rpc, sendAndConfirmTransaction } = createSolanaClient({
49+
urlOrMoniker: "localnet",
50+
});
51+
const rpcSubscriptions = createSolanaRpcSubscriptions("ws://localhost:8900");
52+
53+
const sender = await generateKeyPairSigner();
54+
const LAMPORTS_PER_SOL = 1_000_000_000n;
55+
await airdropFactory({ rpc, rpcSubscriptions })({
56+
recipientAddress: sender.address,
57+
lamports: lamports(LAMPORTS_PER_SOL), // 1 SOL
58+
commitment: "confirmed"
59+
});
60+
61+
const newAccount = await generateKeyPairSigner();
62+
63+
const space = 0n;
64+
const rentLamports = await rpc.getMinimumBalanceForRentExemption(space).send();
65+
66+
// !mark(1:7)
67+
const createAccountInstruction = getCreateAccountInstruction({
68+
payer: sender,
69+
newAccount: newAccount,
70+
lamports: rentLamports,
71+
programAddress: SYSTEM_PROGRAM_ADDRESS,
72+
space
73+
});
74+
75+
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
76+
const transactionMessage = createTransaction({
77+
feePayer: sender,
78+
version: "legacy",
79+
instructions: [
80+
createAccountInstruction,
81+
],
82+
latestBlockhash,
83+
});
84+
85+
const signedTransaction =
86+
await signTransactionMessageWithSigners(transactionMessage);
87+
await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(
88+
signedTransaction,
89+
{ commitment: "confirmed" }
90+
);
91+
const transactionSignature = getSignatureFromTransaction(signedTransaction);
92+
console.log("Transaction Signature for create account:", transactionSignature);
93+
```
94+
2795
```ts !! title="Kit"
2896
import {
2997
airdropFactory,

apps/web/content/cookbook/accounts/get-account-balance.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ Every Solana account is required to maintain a minimum balance of native SOL
1010

1111
<CodeTabs storage="cookbook" flags="r">
1212

13+
```ts !! title="Gill"
14+
import { createSolanaClient, Address } from "gill";
15+
16+
const { rpc } = createSolanaClient({
17+
urlOrMoniker: "mainnet",
18+
});
19+
20+
const addresss = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address;
21+
// !mark
22+
const { value } = await rpc.getBalance(addresss).send();
23+
24+
console.log(`Balance: ${Number(value) / 1_000_000_000} SOL`);
25+
```
26+
1327
```ts !! title="Kit"
1428
import { createSolanaRpc, Address } from "@solana/kit";
1529

apps/web/content/cookbook/tokens/get-token-account.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@ const mintAddress = address("2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo");
2727

2828
const authority = address("AC5RDfQFmDS1deWZos921JfqscXdByf8BKHs5ACWjtW2");
2929

30-
const associatedTokenAddress = await getAssociatedTokenAccountAddress(mintAddress, authority, TOKEN_2022_PROGRAM_ADDRESS);
30+
const associatedTokenAddress = await getAssociatedTokenAccountAddress(
31+
mintAddress,
32+
authority,
33+
TOKEN_2022_PROGRAM_ADDRESS
34+
);
3135

32-
// !mark
33-
const ataDetails = await fetchToken(rpc, associatedTokenAddress);
36+
// !mark(1:4)
37+
const ataDetails = await fetchToken(
38+
rpc,
39+
associatedTokenAddress
40+
);
3441

3542
console.log(ataDetails);
3643
```

apps/web/content/cookbook/transactions/add-priority-fees.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const transactionMessage = createTransaction({
6363
getSetComputeUnitPriceInstruction({ microLamports: 5000n }),
6464
getAddMemoInstruction({ memo: "Hello, world!" })
6565
],
66-
latestBlockhash
66+
latestBlockhash,
6767
});
6868

6969
const estimatedComputeUnits = await getComputeUnitEstimate(transactionMessage);

0 commit comments

Comments
 (0)