Skip to main content
6 votes
Accepted

Is there any way to get nonce accounts of an authorized account?

Using knowledge of the following facts: All nonce accounts are owned by the system program Nonce accounts are exactly 80 bytes long The nonce authority's public key is written into bytes 8–40 You ...
steveluscher's user avatar
  • 2,415
5 votes
Accepted

How to test a function that is expected to return error?

There are a few ways to assert errors. Here is one from Anchor's tic-tac-toe example: try { await program.methods.signUp("sajjad", "09146979106555555555", "")....
sohrab's user avatar
  • 1,781
4 votes
Accepted

How to identify a swap transaction and get details

You would first check for those transfer instructions that you posted in your question. Then you would also dig through your ParsedTransactionMeta, and look at the preTokenBalances and ...
cloudberry's user avatar
4 votes
Accepted

"Signature verification failed" error while creating an account

I think you need to also pass the keypair for newAccountPubkey as a signer. The sendAndConfirm method should have an array for signers you can use for this. This will also mean creating a variable for ...
T.J. Littlejohn's user avatar
4 votes
Accepted

How do I mint an SPL token with custom Metadata without using the Metaplex JS SDK?

You'll still end up needing to use metaplex since metaplex controls the Token Metadata Program. Specifically, you'll need to use createCreateMetadataAccountV3Instruction from @metaplex-foundation/mpl-...
john's user avatar
  • 7,445
4 votes
Accepted

How to export an Anchor defined enum to Typescript?

i think you can use : type myEnum = IdlTypes<ProgramIdl>["enumName"]
datben's user avatar
  • 133
4 votes

You cannot/should not initialize the payer account as a program account

It looks like you didn't provide the staking_pool account: #[account(init, payer = owner, space = StakingPool::LEN + 8)] pub staking_pool: Account<'info, StakingPool>, The account is ...
john's user avatar
  • 7,445
4 votes
Accepted

Issues with Solana CLI install & web3.js package

Once you clone the repo used in the video, you should be able to navigate to the directory, and run yarn install or npm i to install all of the needed packages. From there the variables and helpers ...
Joey Meere's user avatar
  • 1,294
3 votes
Accepted

How to import METADATA_PROGRAM_ID. (Buildspace Solana Staking Anchor course)

You can install @metaplex-foundation/mpl-token-metadata from here and import it like import { PROGRAM_ID as METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata" Else you can ...
Swaroop Maddu's user avatar
3 votes
Accepted

Solana Wallet adapter with different react UI

The wallet adapter styles can be added like so require("@solana/wallet-adapter-react-ui/styles.css"); You can also find the class naming convention and override the css.
Tyler Davis's user avatar
3 votes

Support of Anchor IDL for enums

For example if you have an account defined in Rust code #[account()] /// Stores meta information about the `Account` on chain pub struct User { // user data pub user_data : UserData, // ...
Galactus Godmode's user avatar
3 votes
Accepted

How do I solve this: `Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0`

On the first call your accounts will be initialized. On subsequent calls, the initialization will naturally fail because the account is already initialized... :-) Did you expect a different behavior? ...
AllBlooming's user avatar
  • 2,269
3 votes

How do I mint an SPL token with custom Metadata without using the Metaplex JS SDK?

Answering my own question to help others based on Adding Metadata for Fungible SPL tokens (Metaplex) and Need assistance creating a custom type of NFT, updating deprecated function signatures, and ...
mikemaccana's user avatar
  • 2,031
3 votes

Fetch Anchor Discriminator (Typescript)

You can use this function to fetch the Anchor Discriminator in Typescript. function sighash(nameSpace: string, ixName: string): Buffer { let name = snakeCase(ixName); let preimage = `${nameSpace}:$...
vicyyn's user avatar
  • 4,095
3 votes

How to sign a message using Baclpack?

Hey looking at the code it should be signMessage(tx: Buffer, address: string): Promise<string>; so const signature = await window.xnft.solana.signMessage(tx);
Jonas H.'s user avatar
  • 5,727
3 votes
Accepted

When importing a mnemonic phrase into a phantom app, the wallet addresses do not match

In case someone encounters the same problem, I will leave an answer to my question. The problem is that phantom find first key derivation along the path m/44'/501'/0'/0'. To get a wallet with the same ...
Leo Loki's user avatar
  • 392
3 votes
Accepted

Fetching authorization rules PDA for a pNFT

You can access the authentication rules for a given pNFT by inspecting the token's metadata account. This can be done with umi, and mpl-token-metadata. Fetching the PDA and it's data will look ...
Joey Meere's user avatar
  • 1,294
3 votes

Why does TypeScript throw a warning for ResolvedAccounts for my PDA in my Anchor tests?

This is because all PDAs resolve automatically in Anchor 0.30. The client does not need to know anything about the resolvable accounts, thus you can safely remove the web3.PublicKey....
acheron's user avatar
  • 2,571
2 votes
Accepted

Checking to see if a token account exists using anchor-ts

The easiest thing to do would be to use getOrCreateAssociatedTokenAccount on the client. This will get the account if it exists, and create it if required. See https://solana-labs.github.io/solana-...
Callum M's user avatar
  • 3,060
2 votes

Checking to see if a token account exists using anchor-ts

From the solana cookbook example, using the ts package "@solana/spl-token": "^0.2.0" import { getAccount } from "@solana/spl-token"; ... let tokenAccount = await ...
Henry E's user avatar
  • 3,050
2 votes
Accepted

Support of Anchor IDL for enums

I found a way to compare enums in typescript. We have to define custom type: type UserType = {client: {}} | {employee:{}} then you can create a variable const userType : UserType = account.userType ...
Galactus Godmode's user avatar
2 votes
Accepted

Failed to serialize or deserialize account data: Unknown

In anchor, failure to deserialize an account happens sometimes when a program tries to write more data to an account than the account has space. It looks like your code example you don't actually ...
Henry E's user avatar
  • 3,050
2 votes

How to test a function that is expected to return error?

try { await program.methods .signUp("sajjad", "09146979106555555555", "") .accounts({ user: secondUser.publicKey, authority: provider.wallet....
Ademola's user avatar
  • 3,833
2 votes
Accepted

How to generate new wallets in anchor typescript tests

Another user in your case is any Keypair You can generate another Keypair using: const user1 = anchor.web3.Keypair.generate(); const user2 = anchor.web3.Keypair.generate(); Then you can call ...
C.OG's user avatar
  • 2,827
2 votes
Accepted

Error: Signature verification failed

It looks like you're using a PDA for the state account let [auctionStatePubKey, auctionStateBump] = await anchor.web3.PublicKey.findProgramAddress( [ Buffer.from("auction"), ...
john's user avatar
  • 7,445
2 votes
Accepted

Importing '@metaplex-foundation/js' results in 'process is not defined' error

I eventually solved this adding a polyfill for process into my vite.config.ts define: { "process.env": process.env ?? {}, }, Here's my full vite.config.ts for reference: // https://vitejs....
mikemaccana's user avatar
  • 2,031
2 votes

0x0 error when trying to send NFT into PDA vault

Quoting an answer to this exact issue as shown here, with minor changes: "0x0 means you're attempting to initialize an already initialized account. What's happening here is that because your ...
Ademola's user avatar
  • 3,833
2 votes

How do I mint an SPL token with custom Metadata without using the Metaplex JS SDK?

Maybe a bit dated, but some example code from Strata if nobody else posts a full answer: https://github.com/StrataFoundation/strata/blob/master/packages/marketplace-ui/src/components/form/ManualForm....
Noah's user avatar
  • 286
2 votes

GetMultiple for Mints?

Posting the answer with parsed accounts here for reference: let mintInfos = await connection.getMultipleAccountsInfo(mintKeys); for (let i = 0; i < mintInfos.length; i++) { let mint: ...
Whiteseal's user avatar
  • 3,155
2 votes

I need help with changing the contents of a page once a wallet has been connected

If you are using Solana Wallet Adapter. You can use useWallet() which returns null when you are not connected. const HomePage = () => { const wallet = useWallet(); ... if (!wallet) ...
vicyyn's user avatar
  • 4,095

Only top scored, non community-wiki answers of a minimum length are eligible