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

updated token-program.md course #492

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions content/courses/tokens-and-nfts/token-program.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function buildCreateMintTransaction(
lamports,
programId,
}),
token.createInitializeMintInstruction(
token.createInitializeMint2Instruction(
accountKeypair.publicKey,
decimals,
payer,
Expand Down Expand Up @@ -288,6 +288,7 @@ const associatedTokenAccount = await createAssociatedTokenAccount(
payer,
mint,
owner,
allowOwnerOffCurve,
);
```

Expand All @@ -298,6 +299,8 @@ requires the following arguments:
- `payer` - the account of the payer for the transaction
- `mint` - the token mint that the new token account is associated with
- `owner` - the account of the owner of the new token account
- `allowOwnerOffCurve` - defaults to false, used to create associated token
accounts for PDAs, necessary for vaults and multi-sig wallets.

You can also use `getOrCreateAssociatedTokenAccount` to get the Token Account
associated with a given address or create it if it doesn't exist. For example,
Expand All @@ -307,7 +310,7 @@ gets created if it doesn't already exist.

Under the hood, `createAssociatedTokenAccount` is doing two things:

1. Using `getAssociatedTokenAddress` to derive the associated token account
1. Using `getAssociatedTokenAddressSync` to derive the associated token account
address from the `mint` and `owner`
2. Building a transaction using instructions from
`createAssociatedTokenAccountInstruction`
Expand All @@ -319,11 +322,12 @@ import * as token from "@solana/spl-token";
async function buildCreateAssociatedTokenAccountTransaction(
payer: web3.PublicKey,
mint: web3.PublicKey,
allowOwnerOffCurve: boolean,
): Promise<web3.Transaction> {
const associatedTokenAddress = await token.getAssociatedTokenAddress(
const associatedTokenAddress = await token.getAssociatedTokenAddressSync(
mint,
payer,
false,
allowOwnerOffCurve,
);

const transaction = new web3.Transaction().add(
Expand Down
Loading