Skip to main content
10 votes
Accepted

How can I get all transactions associated with an account using web3.js?

One solution would be to call getSignaturesForAddress (https://solana-labs.github.io/solana-web3.js/classes/Connection.html#getSignaturesForAddress). This returns an array of 1000 signatures backwards ...
BeZe's user avatar
  • 116
7 votes
Accepted

Error: Hydration failed because the initial UI does not match what was rendered on the server | Using solana wallet adapter

Try to use dynamic import dynamic from 'next/dynamic'; // add this const WalletMultiButtonDynamic = dynamic( async () => (await import('@solana/wallet-adapter-react-ui')).WalletMultiButton, ...
pochi udon's user avatar
6 votes
Accepted

Do I have to use Borsh for serialization?

Do you perchance mean Borsh? Solana is not opinionated about which serialisation/deserialisation library you use in your program. The protocol just expects a byte array for account and instruction ...
sohrab's user avatar
  • 1,781
5 votes
Accepted

How to get the Solana unix_timestamp on the front-end (in JavaScript)?

You can use the getBlockTime endpoint from JSON RPC. First you'll need the highest slot using the getSlot. That would become: const connection = new Connection('https://api.testnet.solana.com', '...
AKSHAY DHAYAL's user avatar
5 votes
Accepted

How can I get parse a public key from Buffer?

You can get the correct key by calling new PublicKey(buffer). The constructor for PublicKey takes a number of different types: number | string | Buffer | Uint8Array | number[] https://solana-labs....
C.OG's user avatar
  • 2,837
5 votes

How do I use spl-token through cdn.jsdelivr.net?

@solana/spl-token does not export a global like @solana/web3.js does. It's an ES/CommonJS module intended to be bundled with your app. Nominally, you could use an ES Module import like this: <...
steveluscher's user avatar
  • 2,455
4 votes
Accepted

Sign transaction from keypair.json instead of wallet confirmation

You can create a Keypair object from a private key: import { Keypair } from '@solana/web3.js' import base58 from 'bs58' const yourPrivateKey = 'abcdef...' // base58 encoded const keypair = Keypair....
Callum M's user avatar
  • 3,190
4 votes
Accepted

How do we call solana methods if program.rpc deprecated?

Try adding .rpc to the end of await program.methods to send the transaction Example format below, (signers([]) can be excluded if there are not additional signers required): // sends transaction await ...
john's user avatar
  • 7,487
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,487
4 votes

Is there a way to fetch all the Stake Accounts of a given sol address?

You can do this using getProgramAccounts on the stake program and the correct filter. It would probably look something like: await connection.getProgramAccounts(StakeProgram.programId, { ...
Jon C's user avatar
  • 16.1k
3 votes

how to get all accounts owned by a program deserialized?

Here is some more context on getProgramAccounts. There are some shortcomings to it. https://solanacookbook.com/guides/get-program-accounts.html#deep-dive Despite its usefulness, getProgramAccounts is ...
Concise Labs's user avatar
  • 1,376
3 votes

How to get multiple accounts info with jsonParsed encoding using @solana/web3.js?

It doesn't look like the web3.js implementation of getMultipleAccounts supports parsed encoding replies. You can either open a feature request issue against the library in the monorepo on github (...
trent.sol's user avatar
  • 4,425
3 votes

sendAndConfirmTransaction returns Cannot read properties of undefined (reading 'toString')

Presuming that useWallet() is from @solana/wallet-adapter, its return value is not a Signer. The return value of useWallet is a WalletContextState. WalletContextState does not expose the private key ...
steveluscher's user avatar
  • 2,455
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 to send a short message / memo to a specific address

You can add messages to transactions using the memo program. Here's an example of sending "Data to send in transaction" in Javascript: import { Connection, Keypair, SystemProgram, ...
Jacob Creech's user avatar
  • 3,874
3 votes

How can I take an extra percentage fee out of every transaction?

Your best bet will be to use the Token-2022 Program. This explains how to set it up so that you can take out transaction fees: https://spl.solana.com/token-2022/extensions#transfer-fees
OCDev's user avatar
  • 762
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,140
3 votes
Accepted

How to convert _bn back to PublicKey in JS?

This is a bit of a strange case, but you could recreate the BN using this dict, and then recreate the PublicKey, ie: const pubkeyJson = {}; // put your JSON in here const num = new BN(0); // just ...
Jon C's user avatar
  • 16.1k
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,787
3 votes

How do I pass in `Option<MyEnum>` as an argument when testing

I cannot replicate the issue. I was able to pass null when I did not have an argument to pass. Happy to take a look at your full code if you have a GH. Here's what I tested (and anchor test ran fine): ...
AMilz's user avatar
  • 1,566
3 votes
Accepted

Why can slippage only be set to whole numbers using Raydium Swap SDK?

The Percent class works as a fraction and thus if I just increase the denominator the percent values can become more accurate. const slippage = new Percent(25, 10000); This would yield a percentage ...
sashavsthewrld's user avatar
3 votes

solana/web3.js Request Airdrop 429 error

You have hit the rate limit. As the message suggests, you will have to wait till the 24 hours are up to request again. More Info https://solana.com/docs/core/clusters#devnet You might also want to ...
Jimii's user avatar
  • 3,770
2 votes

Is there JS libraries for multisig/threshold sign on solana?

The coral-xyz/multisig program is meant to provide a generic multisig, including JS / TS support. You can find the program code at https://github.com/coral-xyz/multisig, note that it is unaudited, ...
Jon C's user avatar
  • 16.1k
2 votes

Is there JS libraries for multisig/threshold sign on solana?

There is no generic MS/TS support on solana. SPL Token specifies its own M:N MS, which the @solana/spl-token package supports. Outside that, you'd need to focus the question on a specific MS/TS ...
trent.sol's user avatar
  • 4,425
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

How to certify a group of uploaded images and metadata as a single collection on Solana?

Uploading the Image and Json to a Storage its not enough to create a Collection. That data is stored off-chain and its not on Solana network, so you have to create the NFTs somehow providing the JSON ...
WrathionTBP's user avatar
2 votes
Accepted

How to verify a signature from the Phantom wallet?

In JavaScript, you can use the tweetnacl library to verify signatures. const hasSucceededVerification = nacl.sign.detached.verify( encodedMessage, // the message signedMessage, // the ...
C.OG's user avatar
  • 2,837
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,140
2 votes
Accepted

sendAndConfirmTransaction returns Cannot read properties of undefined (reading 'toString')

I found the solution and turns out it was just a rookie mistake on my side. The mintPublicKey I was passing to the "getAssociatedAddress" function was the mint address in the string form ...
Ashwini Kumar's user avatar
2 votes

Solflare web wallet

Problem is solved with the new Mobile Wallet Adapter : https://github.com/solana-labs/wallet-adapter/issues/604 It connects directly to the wallet app without asking to connect either to web wallet or ...
Flo's user avatar
  • 53

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