Questions tagged [anchor]

Should be used for all things relating to the Anchor Framework.

Filter by
Sorted by
Tagged with
0 votes
1 answer
20 views

Is it possible to set up an account to point to another account?

I'm making an anchor program where I would like to make a user ID easily retrievable with their Pk, sequential ID or username. one way I thought is to make a PK link account (in case the seed for the ...
alex's user avatar
  • 1
0 votes
1 answer
25 views

How to parse the inner instructions of the transaction's instruction?

Its parsing only transaction instructions, but not inner. import { PublicKey, Connection, LAMPORTS_PER_SOL } from "@solana/web3.js"; import { SolanaParser } from "@debridge-finance/...
omm's user avatar
  • 25
0 votes
0 answers
21 views

Problem with testing a name service smart contract written in Solang

I'm trying to run a benchmark for a Solana node using this name service I wrote in Solang within an Anchor project. This is the Solang smart contract. import 'solana'; contract eclipse_ns { ...
Pratham Prasoon's user avatar
0 votes
0 answers
12 views

no method named `try_to_vec` found for reference `&UpdateArgs` in the current scope

Here is my idl: use solana_idlgen::idlgen; idlgen!({ "version": "0.1.0", "name": "wba_prereq", "instructions": [ { &...
WowBow's user avatar
  • 123
0 votes
3 answers
68 views

Proper way to integrate Solana's Wallet Adapter with Anchor and further questions

After spending some days battling to implement Phantom + Anchor I found out about Solana's Wallet adapter. I sighed in relief thinking the end was nigh but: The the wallet adapter for Solana Apps is ...
CrossedCarpet's user avatar
1 vote
1 answer
29 views

How to run ONLY ONE test in Anchor 0.29.0?

This error came back in 2023 after the previous post here from 2022 August. anchor run test1 now gave me Error: failed to get recent blockhash: TypeError: fetch failed !!?? That is because it does not ...
Russo's user avatar
  • 163
1 vote
2 answers
36 views

How to give authority of PDA to another program

I have two programs. // program one #[derive(Accounts)] pub struct MyContext<'info> { ... #[account(mut)] pub pda_in_prog_1: PDA_ONE<'info, T>, pub system_program: Program<'...
Jimii's user avatar
  • 990
2 votes
1 answer
74 views

Error when two `programs.devnet` found in anchor

Could someone explain what the differences are to [programs.localnet], [programs.devnet] and possibly [programs.mainnet-beta] defined in Anchor.toml The anchor-lang reference for the manifest only ...
Jimii's user avatar
  • 990
0 votes
1 answer
24 views

Challenges with Lifetime Specifiers and Attribute Macros in Solana Playground: Seeking Guidance

Hello Solana Community, I'm developing a smart contract using Solana Playground (beta.solpg.io), and I've encountered several compilation errors that I'm struggling to resolve. My contract involves ...
orhange.qgem's user avatar
3 votes
3 answers
57 views

is it possible to know the caller of an instruction

TL;DR, how can I get the address of the person calling an instruction inside my anchor program. In my anchor program, I want to know the person who is calling my program. Say I have an instruction ...
Jimii's user avatar
  • 990
1 vote
1 answer
28 views

When would the #[account(rent_exempt = skip)] and #[account(rent_exempt = enforce)] constraints be used?

Since newly created accounts are required to be rent-exempt, what are some examples where the #[account(rent_exempt = skip)] and #[account(rent_exempt = enforce)] anchor constraints would need to be ...
john's user avatar
  • 5,420
2 votes
1 answer
32 views

When would #[account(signer)] constraint be used instead of Signer account type?

The docs.rs page mentions: Consider using the Signer type if you would only have this constraint on the account. What would be some examples where you would want to use the #[account(signer)] ...
john's user avatar
  • 5,420
0 votes
1 answer
38 views

Error: Signature verification failed while initialising PDA

I've been working on Solana program that should hold two different tokens for me in a Vault in an ATA. The first token should be deposited during Vault initialisation, the second will be deposited by ...
Kamil Słuszniak's user avatar
0 votes
1 answer
19 views

AccountOwnedByWrongProgram

I've been working on Solana program that should hold two different tokens for me in a Vault in an ATA. The first token should be deposited during Vault initialisation, the second will be deposited by ...
Kamil Słuszniak's user avatar
3 votes
1 answer
26 views

What is the definitive way of wrapping sol in anchor?

I would like to handle all the wrapping and transferring of sol in the anchor instruction. not in the frontend, but I cant seem to find any examples of how I wrap sol in an instruction on-chain. If i ...
anchor noob's user avatar
1 vote
2 answers
45 views

why im getting this error when i run anchor init and anchor build :Error: Invalid Base58 string

i dunno why im getting this issue when i run anchor build or init , here is the error : Error: Invalid Base58 string
abdukkahi's user avatar
0 votes
1 answer
61 views

'called `Option::unwrap()` on a `None` value'

I have updated Anchor to ^0.29.0, Solana to 1.16.18 (did try 1.17.4), and Rust Compiler to 1.73.0. The anchor build runs successfully, however, the anchor test always throws this exception. I have ...
Tu Phan's user avatar
0 votes
0 answers
14 views

nft delegate confusion (metaplex token metadata)

I'm trying to delegate an pnft to a pda. but I keep getting incorrect account owner. I can't for the life of me know how the account owner is incorrect. and what the delegate field in the ...
Fares_Hassen's user avatar
0 votes
1 answer
29 views

How do I get the recent blockhashses during program execution?

I want to get the latest blockhash (or last 10 or so) during program execution. The goal is prove that the tx was created and executed in real time. Here are the steps that I am thinking: get latest ...
larry 8's user avatar
1 vote
2 answers
34 views

Is there a go package to create clients for anchor programs?

Like typescript package do we have go package that generates clients for solana anchor programs?
Aravind Makam's user avatar
2 votes
1 answer
27 views

HashMaps in Anchor

Does anyone have experience using HashMaps in an Anchor project? I have the following implementation for a struct: #[account] #[derive(Debug)] pub struct Company { pub id: u64, // 8 bytes pub ...
brknarsy's user avatar
2 votes
0 answers
20 views

How does anchor test work?

new to solana. I have a project called day2. I have run anchor build in day2 and all it does is print integers. The command anchor build creates a json file day2.json in file day2/target/idl. However, ...
mashedpotato's user avatar
3 votes
1 answer
26 views

What is the best way to do "safe math" in rust or anchor programs?

I know with rust you need to be sure you do not cause buffer overflows/underflows when performing math operations. What are the best practices for doing common math safely within programs? Adding, ...
nickfrosty's user avatar
0 votes
1 answer
17 views

Error: memory allocation failed, out of memory. When using dynamic seed in anchor

I am getting and memory allocation failed error when I am passing in a dynamic seed for my account initialization. This is how i use it: pub fn chop_tree(ctx: Context<ChopTree>, counter: u16, ...
Jonas H.'s user avatar
  • 1,857
2 votes
1 answer
41 views

Unable to upload Solang generated idl

$ anchor idl init -f target/idl/program.json `solana address -k target/deploy/program-keypair.json` Error: RPC response error -32002: Transaction simulation failed: Error processing Instruction 0: ...
CrossedCarpet's user avatar
0 votes
1 answer
55 views

Transaction failing while calling a Solana program with PDA

I'm calling a function of anchor_movie_review_program program on devnet CLA5Pk8tpcsA3RPmCYPaRNBdU6xBknRnqshsT1bKT7if. I cloned the following GitHub https://github.com/Unboxed-Software/anchor-movie-...
kc.sol's user avatar
  • 1
0 votes
0 answers
17 views

Call Instructions Anchor IDL error address not inicialized

I am trying to replicate some calls to an Anchor IDL of a contract. And all the instructions work for me, but the most important one doesn't. And I have a couple of doubts, comparing my calls with the ...
Victor Maldonado's user avatar
1 vote
1 answer
31 views

How to validate that a cNFT is part of a collection in a program

I want to validate in a program that a cNFT is in a particular collection. Is there a better way to do this than adding a PDA as a delegate to the cNFT collection so that it can sign and call the ...
Slae's user avatar
  • 111
1 vote
0 answers
30 views

Anchor idl upgrade triggers: require_gte expression was violated

i had to recompile anchor to print the error (is there away to stream idl write logs during anchor idl upgrade|install?) > ../anchor/target/debug/anchor idl upgrade ...
amilkov's user avatar
  • 21
2 votes
3 answers
68 views

Extending struct fields in a PDA and ensuring compatibility

I need to extend the fields I have within a PDA. Some accounts are already live, so I want those to still be compatible with the new layout. As a simple illustrative example, consider this account ...
mega_creamery's user avatar
0 votes
1 answer
18 views

Anchor build error with apecs crate

Within a new empty project, after adding the apecs crate: [dependencies] anchor-lang = "0.28.0" apecs = "0.7.0" I get the following errors: Error: Function ...
Gabriele Picco's user avatar
0 votes
1 answer
19 views

Error: ELF error from deploying an anchor project

I have been trying to deploy my anchor project on the local net. I started by running solana-test-validator and then anchor deploy but I keep receiving this error: Error: ELF error: ELF error: ...
Quang Phạm's user avatar
2 votes
1 answer
28 views

Are writes to BTreeMaps expensive? How much compute units does it take?

I am using a quite a few BTreeMaps and i am writing to 2 BTreeMaps and it is using all the compute units. So i wanted to know how much compute units it takes and what can be the alternatives for using ...
Dhruv D Jain's user avatar
0 votes
1 answer
30 views

Getting ConstraintRaw Error

I'm integrating smart contract in next js. and getting this error Uncaught (in promise) Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 2: custom program ...
Sabir Khan's user avatar
2 votes
1 answer
22 views

Solang anchor commands after "anchor init <name> --solidity" yields "Error: No such file or directory (os error 2)"

To reproduce: anchor init <name> --solidity anchor build # output: Error: No such file or directory (os error 2) I have tried many logging options but none showed any relevant information.
CrossedCarpet's user avatar
0 votes
0 answers
25 views

Anchor clockwork-sdk error

I have a basic anchor project with no modifications made other then adding the clockwork-sdk in Cargo.toml. When I run anchor build without the clockwork-sdk the program builds. When I run it with the ...
Jannik's user avatar
  • 1
0 votes
0 answers
27 views

Can't realloc and SPL transfer in the same instruction

I am trying to transfer an SPL token, and reallocating space in a PDA in one instruction. I am able to realloc (increase and decrease) if I remove the token transfer code in the instruction. I'm also ...
Joey B's user avatar
  • 1
1 vote
1 answer
25 views

having trouble to encode a u64 as data for CPI

I have a u64 which is an amount of lamports. I need to send it to another program with a CPI. So i'm trying to encode it in the data, but can't figure out how to do it. Here is what i tried: let mut ...
Effe2's user avatar
  • 683
2 votes
1 answer
44 views

anchor: how to init a PDA and close it in the same method?

I would like to create a PDA and close it in the same method, but can't find how. if i use init and close, it says i should add mut, but if i add mut, it says it can't be used with init. Why do i need ...
Effe2's user avatar
  • 683
1 vote
2 answers
41 views

Are enums with associated values permitted?

Not sure if this is really an anchor or solana related question, since I am able to compile, just not to run tests. I can run code and test against code that has an account that has following enum: #[...
mega_creamery's user avatar
1 vote
1 answer
33 views

BN inside object

I'm trying to send a BN to a Solana Program, but the account it's never set as intended. When the BN is sent as an another independent argument works fine. const created_at = new BN(Date.now()); ...
Bruno Barros's user avatar
1 vote
1 answer
21 views

Use candy machine in anchor program

Are there examples of calling candy machine and candy guard prgoram from an anchor program?
Jimii's user avatar
  • 990
3 votes
1 answer
54 views

Using u128 without sacrificing alignment 8

We have a struct like: #[account(zero_copy)] #[repr(C)] pub struct SomeStruct { pub authority: Pubkey, pub some_value: u128, pub another_value: u64, // etc... } This struct has alignment ...
Whiteseal's user avatar
  • 2,252
1 vote
3 answers
54 views

Is my transaction to big?

I am creating a transaction with these contexts. when I remove an account, (does not matter which one) I am able to make the transaction but whenever I have all of them it fails with the error: failed ...
anchor noob's user avatar
0 votes
0 answers
14 views

anchor's instruction create account but with CPI?

i have created an anchor method that needs an escrow account. When i use this method, the escrow account is created with instructions: [ await program.account.escrowAccount.createInstruction(escrow), ]...
Effe2's user avatar
  • 683
2 votes
1 answer
37 views

Why does the token metadata program have an account discriminator field?

The first field for the MetadataAccount struct is key which is commented as being the account discriminator. What is MPL token metadata using this field for?
Jimii's user avatar
  • 990
0 votes
3 answers
46 views

what is the name of the second parameter for `CpiContext`

For example, when calling the instruction to mint_to my wallet, I initialize the cpi_context let cpi_context = CpiContext::new( ctx.accounts.token_program.to_account_info(), ...
Jimii's user avatar
  • 990
1 vote
1 answer
67 views

How to organize program's anchor code properly

I have a program with around 10/15 methods, all in the same file which represents 2K lines of code +/-. I would like to have one file with the method pub fn my_method and the struct #[derive(Accounts)]...
Effe2's user avatar
  • 683
1 vote
0 answers
24 views

A peculiar problem with CPIs

So I'm working on a DAO program and I ran into this really weird error. My program is bespoke, so I'm going to demonstrate the problem with an easier-to-understand program: coral-xyz/multisig. The ...
Proph3t's user avatar
  • 382
0 votes
2 answers
38 views

Error on building sdk with solita on anchor-lang:0.28.0

No matching version is found by solita for anchor-cli: 0.28.0 on https://crates.io/crates/anchor-cli/versions , which gives error.
Athar Mohd's user avatar

1
2 3 4 5
17