Skip to content

Commit

Permalink
Merge branch 'main' into cookbook-v2-snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfrosty committed Nov 19, 2024
2 parents bc66d1c + 44e44fa commit 916b10f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
6 changes: 3 additions & 3 deletions content/cookbook/accounts/calculate-rent.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
title: How to Calculate Account Creation Cost
sidebarSortOrder: 2
description:
"Every time you create an account, that creation costs a small amount of SOL.
Learn how to calculate how much an account costs at creation."
"Every time you create an account, that creation costs an amount of SOL. Learn
how to calculate how much an account costs at creation."
---

Keeping accounts alive on Solana incurs a storage cost called rent. For the
Expand All @@ -29,7 +29,7 @@ console.log("Minimum balance for rent exception:", lamports);

<Tab value="web3.js v1">

```typescript filename="calculate-rent.ts"
```typescript
import { Connection, clusterApiUrl } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
Expand Down
36 changes: 35 additions & 1 deletion content/cookbook/wallets/check-publickey.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,36 @@ have a private key associated with them. You can check this by looking to see if
the public key lies on the ed25519 curve. Only public keys that lie on the curve
can be controlled by users with wallets.

```javascript file=/code/cookbook/wallets/check-public-key.ts#L1-L2,#L3-L19
<Tabs groupId="language" items={['web3.js v2', 'web3.js v1']}>

<Tab value="web3.js v2">

```typescript
import { isAddress } from "@solana/web3.js";

// Note that generateKeyPair() will always give a public key that is valid for users

// Valid public key
const key = "5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY";

// Lies on the ed25519 curve and is suitable for users
console.log("Valid Address: ", isAddress(key));

// // Valid public key
const offCurveAddress = "4BJXYkfvg37zEmBbsacZjeQDpTNx91KppxFJxRqrz48e";

// // Not on the ed25519 curve, therefore not suitable for users
console.log("Valid Off Curve Address: ", isAddress(offCurveAddress));

// // Not a valid public key
const errorPubkey = "testPubkey";
console.log("Invalid Address: ", isAddress(errorPubkey));
```

</Tab>
<Tab value="web3.js v1">

```typescript
import { PublicKey } from "@solana/web3.js";

// Note that Keypair.generate() will always give a public key that is valid for users
Expand All @@ -31,4 +60,9 @@ console.log(PublicKey.isOnCurve(offCurveAddress.toBytes()));

// Not a valid public key
const errorPubkey = new PublicKey("testPubkey");
console.log(PublicKey.isOnCurve(errorPubkey.toBytes()));
```

</Tab>
</Tabs>
```

0 comments on commit 916b10f

Please sign in to comment.