Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fumadocs #111

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6f7cff4
App router layout and fumadocs
pomber Nov 13, 2024
95e0a6b
Remove import
pomber Nov 13, 2024
0dad369
Add breadcrumbs
pomber Nov 13, 2024
8acd7d4
Container class
pomber Nov 13, 2024
b0826f9
Sidebar
pomber Nov 14, 2024
670c110
Layout
pomber Nov 15, 2024
96fa858
More placeholder content
pomber Nov 15, 2024
2f6191c
Fix typescript
pomber Nov 15, 2024
4c6f02e
Add cookbook and rpc
pomber Nov 26, 2024
fe324df
Add postcss-conditional-purge
pomber Nov 27, 2024
4fd73ea
Fumadocs styles
pomber Nov 29, 2024
79a69d5
Mobile sidebar
pomber Nov 30, 2024
400dad8
Better styles
pomber Dec 1, 2024
ce24540
Customized Fumadocs UI and layout
pomber Dec 2, 2024
7e68d81
Fix image caption
pomber Dec 2, 2024
cae8d0b
Fix previous/next links style
pomber Dec 2, 2024
553783a
Add locale middleware
pomber Dec 31, 2024
6749ebc
Move guides, courses and resources to app router with fumadocs
pomber Jan 2, 2025
aff9c33
Update fumadocs
pomber Jan 5, 2025
ef37e38
Fix warnings
pomber Jan 5, 2025
26fc771
Migrate filters to app router
pomber Jan 5, 2025
ffd9d56
Add Suspense for useSearchParams
pomber Jan 5, 2025
6b1c2e1
Add breadcrumbs
pomber Jan 5, 2025
99524fc
Small screen courses and guides
pomber Jan 6, 2025
494420f
Open graph tags
pomber Jan 7, 2025
923452a
Remove unused dependencies
pomber Jan 7, 2025
25d28f4
Move developers page to app router
pomber Jan 8, 2025
e00f7a3
Add previous, next, and scroll to top
pomber Jan 8, 2025
aab3791
Add app router not-found
pomber Jan 9, 2025
2fc1cb0
Fix pages catch-all
pomber Jan 10, 2025
e205a5f
Fix optional catch-alls
pomber Jan 11, 2025
3b087f1
Fix theme switcher
pomber Jan 13, 2025
9e5c97e
Unify i18n
pomber Jan 13, 2025
a2d58cd
Fix stackexchange card
pomber Jan 13, 2025
20e1f7f
More mdx components
pomber Jan 14, 2025
7deb2a2
Migrate docs content
pomber Jan 14, 2025
cc7ea8c
Fix Callout and Breadcrumb styles
pomber Jan 15, 2025
e052413
Fix breakpoint 404
pomber Jan 15, 2025
59e0084
Migrate cookbook content
pomber Jan 15, 2025
f259b03
Move RootLayout
pomber Jan 15, 2025
83f40ac
Increase sidebar and toc font-size
pomber Jan 15, 2025
c9a4ce4
Apply container-docs only to docs and cookbook
pomber Jan 16, 2025
e911e56
Fix developers localized metadata
pomber Jan 16, 2025
c4d282c
Migrate guides
pomber Jan 16, 2025
bcfbb37
Migrate courses content
pomber Jan 16, 2025
207b7f5
Split mdx sources
pomber Jan 16, 2025
7599eab
Fix alternate links meetadata
pomber Jan 17, 2025
e052f43
Split mdx collections source
pomber Jan 17, 2025
c857d21
Content i18n
pomber Jan 18, 2025
1b68218
Fix sitemap
pomber Jan 18, 2025
577dc62
Fix next/prev links
pomber Jan 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ public/sitemap*

coverage
.env.local
.source
10 changes: 10 additions & 0 deletions content/authors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"id": "unboxed",
"title": "Unboxed Software with updates from the Solana Foundation",
"github": "Unboxed-Software",
"twitter": "unboxedsoftware",
"website": "https://www.beunboxed.com/",
"image": "unboxed.png"
}
]
47 changes: 47 additions & 0 deletions content/cookbook/accounts/calculate-rent.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: How to Calculate Account Creation Cost
description:
"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
calculation, you need to consider the amount of data you intend to store in the
account. Rent can be reclaimed in full if the account is closed.

<Tabs groupId="language" items={['web3.js v2', 'web3.js v1']}>

<Tab value="web3.js v2">

```typescript title="calculate-rent.ts"
import { createSolanaRpc } from "@solana/web3.js";

const rpc = createSolanaRpc("https://api.devnet.solana.com");
// 1.5k bytes
const space = 1500n;

const lamports = await rpc.getMinimumBalanceForRentExemption(space).send();
console.log("Minimum balance for rent exception:", lamports);
```

</Tab>

<Tab value="web3.js v1">

```typescript
import { Connection, clusterApiUrl } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("devnet"), "confirmed");

// length of data in bytes in the account to calculate rent for
const dataLength = 1500;
const rentExemptionAmount =
await connection.getMinimumBalanceForRentExemption(dataLength);
console.log({
rentExemptionAmount,
});
```

</Tab>

</Tabs>
44 changes: 44 additions & 0 deletions content/cookbook/accounts/close-account.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: How to Close an Account
description:
"When an account is no longer needed, you can close the account to reclaim the
rent. Learn how to close accounts efficiently on Solana."
---

Closing accounts enables you to reclaim the SOL that was used to open the
account, but requires deleting of all information in the account. When an
account is closed, make sure that the data is zeroed out in the same instruction
to avoid people reopening the account in the same transaction and getting access
to the data. This is because the account is not actually closed until the
transaction is completed.

```rust title="close-account.rs" {18-25}
use solana_program::{
account_info::next_account_info, account_info::AccountInfo, entrypoint,
entrypoint::ProgramResult, pubkey::Pubkey,
};

entrypoint!(process_instruction);

fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();

let source_account_info = next_account_info(account_info_iter)?;
let dest_account_info = next_account_info(account_info_iter)?;

let dest_starting_lamports = dest_account_info.lamports();
**dest_account_info.lamports.borrow_mut() = dest_starting_lamports
.checked_add(source_account_info.lamports())
.unwrap();
**source_account_info.lamports.borrow_mut() = 0;

source_account_info.assign(&system_program::ID);
source_account_info.realloc(0, false).map_err(Into::into)

Ok(())
}
```
149 changes: 149 additions & 0 deletions content/cookbook/accounts/create-account.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
title: How to Create an Account
description:
"Accounts are the basic building blocks of anything on Solana. Learn how to
create accounts on the Solana blockchain."
---

Creating an account requires using the System Program `createAccount`
instruction. The Solana runtime will grant the owner program of an account,
access to write to its data or transfer lamports. When creating an account, we
have to preallocate a fixed storage space in bytes (space) and enough lamports
to cover the rent.

<Tabs groupId="language" items={['web3.js v2', 'web3.js v1']}>

<Tab value="web3.js v2">

```typescript title="create-account.ts"
import {
pipe,
createSolanaRpc,
appendTransactionMessageInstructions,
createSolanaRpcSubscriptions,
createTransactionMessage,
generateKeyPairSigner,
getSignatureFromTransaction,
sendAndConfirmTransactionFactory,
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
signTransactionMessageWithSigners,
} from "@solana/web3.js";
import { getSetComputeUnitPriceInstruction } from "@solana-program/compute-budget";
import {
getCreateAccountInstruction,
SYSTEM_PROGRAM_ADDRESS,
} from "@solana-program/system";

const rpc = createSolanaRpc("https://api.devnet.solana.com");
const rpcSubscriptions = createSolanaRpcSubscriptions(
"wss://api.devnet.solana.com",
);

const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({
rpc,
rpcSubscriptions,
});

const space = 0n; // any extra space in the account
const rentLamports = await rpc.getMinimumBalanceForRentExemption(space).send();
console.log("Minimum balance for rent exception:", rentLamports);

// todo: load your own signer with SOL
const signer = await generateKeyPairSigner();

// generate a new keypair and address to create
const newAccountKeypair = await generateKeyPairSigner();
console.log("New account address:", newAccountKeypair.address);

const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();

const transactionMessage = pipe(
createTransactionMessage({ version: "legacy" }),
tx => setTransactionMessageFeePayerSigner(signer, tx),
tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
tx =>
appendTransactionMessageInstructions(
[
// add a priority fee
getSetComputeUnitPriceInstruction({
microLamports: 200_000,
}),
// create the new account
getCreateAccountInstruction({
lamports: rentLamports,
newAccount: newAccountKeypair,
payer: signer,
space: space,
// "wallet" accounts are owned by the system program
programAddress: SYSTEM_PROGRAM_ADDRESS,
}),
],
tx,
),
);

const signedTransaction =
await signTransactionMessageWithSigners(transactionMessage);
const signature = getSignatureFromTransaction(signedTransaction);

await sendAndConfirmTransaction(signedTransaction, {
commitment: "confirmed",
});
console.log("Signature:", signature);
```

</Tab>

<Tab value="web3.js v1">

```typescript title="create-account.ts"
import {
SystemProgram,
Keypair,
Transaction,
sendAndConfirmTransaction,
Connection,
clusterApiUrl,
LAMPORTS_PER_SOL,
} from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
const fromPubkey = Keypair.generate();

// Airdrop SOL for transferring lamports to the created account
const airdropSignature = await connection.requestAirdrop(
fromPubkey.publicKey,
LAMPORTS_PER_SOL,
);
await connection.confirmTransaction(airdropSignature);

// amount of space to reserve for the account
const space = 0;

// Seed the created account with lamports for rent exemption
const rentExemptionAmount =
await connection.getMinimumBalanceForRentExemption(space);

const newAccountPubkey = Keypair.generate();
const createAccountParams = {
fromPubkey: fromPubkey.publicKey,
newAccountPubkey: newAccountPubkey.publicKey,
lamports: rentExemptionAmount,
space,
programId: SystemProgram.programId,
};

const createAccountTransaction = new Transaction().add(
SystemProgram.createAccount(createAccountParams),
);

await sendAndConfirmTransaction(connection, createAccountTransaction, [
fromPubkey,
newAccountPubkey,
]);
```

</Tab>

</Tabs>
Loading