Questions tagged [anchor-lang]
The anchor-lang tag has no usage guidance.
130
questions
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 ...
3
votes
1
answer
62
views
Where does 'anchor keys list' store its keys?
I know anchor keys list shows existing keys, or creates new ones. And anchor keys sync will modify my program to use the stored keys. But where are the anchor keys list keys stored on disk?
I've ...
0
votes
1
answer
35
views
Can't get past this error with anchor/@coral/xyz
import { Connection, Keypair, PublicKey, clusterApiUrl } from "@solana/web3.js";
import { Program, setProvider, web3, AnchorProvider } from "@coral-xyz/anchor";
import { ...
0
votes
1
answer
27
views
Can we derive PDAs inside a solana program?
Is there any function to generate PDAs using seeds manually?
I dont want to create PDAs using client modules but I want to create PDAs inside the rust functions in the contract/program.
Is there a way ...
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 ...
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: ...
2
votes
1
answer
112
views
How do I create a basic program to use as a Token-22 transfer hook in Anchor? Is it even possible now?
I want to create a counter PDA that counts the number of times a token has been transferred. I understand how to create the counter PDA using the Solana Playground tutorial as the basis and I know how ...
1
vote
1
answer
30
views
Reference for supported IDL types
Is there a reference for supported anchor IDL types, just like we have for the space reference. Trying to use a slice [usize; 32] but getting the error
IdlError: Type not found: {"type":{&...
0
votes
0
answers
28
views
Getting AccountNotInitialized error when creating metadata account
The Metadata and MasterEdition accounts are created using the create_metadata_accounts_v3 and create_master_edition_v3 instructions.
For some reason anchor expects them to already be initialized. Is ...
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(),
...
2
votes
2
answers
366
views
is there a limit to the number of functions that can consume anchor Context?
I currently Have four functions, that consume the context for my Dummy Accounts struct, Two of the functions work as expected but the other two fail.
#[derive(Accounts)]
#[instruction(bump: u8)]
pub ...
2
votes
2
answers
160
views
How to authenticate or validate wallets or NFTs when executing solana instructions
I am building a Solana program using Anchor and I would like to know which is the recommended way to authenticate/validate users allowed to execute certain Solana instructions. For what I have seen so ...
0
votes
2
answers
30
views
Transferring solana to a hardcoded publickey
let fee_pubkey_str = "auth8dV96CVJrsFxAdDM13eo1fFq9vE27C2EJ2yezJw";
let fee_pubkey = Pubkey::from_str(fee_pubkey_str).unwrap();
let transfer_to_fee = solana_program::...
1
vote
1
answer
71
views
Super slow deployments when using Solana CLI 16.x
My deployments are extremely slow since I have updated my Solana CLI to v16.8 but when I run:
anchor deploy
I get:
Blockhash expired. 4 retries remaining
Blockhash expired. 3 retries remaining
⠁ 0....
2
votes
1
answer
29
views
What happens when you pass the same account as writable twice in a single ix but fail to sync the data manually?
I'm required to use conditional logic in my ix where two mutable references to accounts could be be pointing to the same account. What happens when I don't sync them at the end?
0
votes
1
answer
30
views
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: incorrect program id for instruction
this is my code and error is occur when i calling new method :
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Starter } ...
1
vote
1
answer
43
views
How to implement a Buying NFT feature on solana program?
I am trying to implement a buying NFT feature in my solana program, but here i am struct on signature verification error.
Can anyone find out what i am missing here ?
pub fn buy_nft(
ctx: ...
1
vote
1
answer
30
views
How we can create auction contract using anchor?
I have minted NFT using an anchor and metaplex library. But now I want to create an auction on the same NFT, is it possible to create a contract using anchor and metaplex or do I have to use the core ...
1
vote
2
answers
164
views
Get account public key in an Anchor program
I got an Anchor program and there is some functions that I want to restrict their access in order to create some particular privileges in the program, so I want to grab the caller's account/address ...
1
vote
2
answers
110
views
Is there a way to overwrite data in an account?
I have a PDA account, and I am trying to change the data format in the account.
from this
#[account]
pub dummy_data {
x_point: f32
}
to
#[account]
pub dummy_data {
x_point: u64,
y_point: f64,
...
0
votes
1
answer
72
views
Getting error when I'm going to mint NFT on testnet using Metaplex
Here is my mint contract
use anchor_lang::prelude::*;
use anchor_lang::solana_program::program::invoke;
use anchor_spl::token::mint_to;
use anchor_spl::token::{MintTo, Token};
use mpl_token_metadata::...
0
votes
1
answer
130
views
"Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x4b"
I have also checked the error repository of metaplex and there i have found this msg:
"#[error("This instruction was deprecated in a previous release and is now removed")]
Removed, //...
2
votes
1
answer
64
views
How to deserialized Anchor accounts in Rust
In JS/TS I can decode an account from bytes using the coder:
const program = new Program(IDL, new PublicKey(""), anchorProvider)
const decoded = program.coder.accounts.decode("...
4
votes
1
answer
86
views
How to fix Borsh serialize error on Anchor 0.28 when publishing crates
Related to the Borsh serialize error the changes suggested by @acheron only work for running the program, but doesn't work or are ignored when publishing the crate to crates.io.
For instance when ...
4
votes
2
answers
64
views
How to fetch empty optional accounts in Anchor
How can I fetch empty optional accounts in Anchor? For instance I have a simple account in rust with the following optional account:
#[account]
pub struct MyApp {
pub my_optional_account: Option&...
2
votes
1
answer
1k
views
How to fix error Macro not expanded: proc macro crate is missing dylib
Somebody knows how to get rid of the error "Macro .... not expanded: proc macro crate is missing dylib"?
I am getting that error on pretty much every anchor macro since I have installed the ...
6
votes
2
answers
907
views
How to fix Error: The trait BorshSerialize is not implemented for Pubkey
I am using OSX with the following packages:
Anchor CLI 0.28.0
Rust 1.70.0
Solana CLI 1.16.1
To flush cache and ensure my environment is clean I have run:
anchor clean && cargo update
...
1
vote
1
answer
52
views
How can any program in Solana read an account of another program? Give an example
The Solana docs states that Any program can read or credit another account.
Ref: https://docs.solana.com/developing/intro/programs.
Please explain this line. Does that mean I can extract all past ...
1
vote
1
answer
58
views
Why do I get Invalid account data when trying to reopen a token account?
I am trying to unwrap SOL from a WSOL account and then initialize the token account again.
I am creating the account like so
pub authority_pda: UncheckedAccount<'info>, ...
1
vote
1
answer
81
views
How to know if the an account already exists when using Anchor's init_if_needed feature
Is there is an easy way to know if the account has just been created or already existed when using the init_if_needed feature?:
#[account(
init_if_needed,
seeds = [seeds],
...
0
votes
1
answer
52
views
How to create the seeds for invoking spl cpi instruction?
I need a program owned token account to hold WSOL. I am creating it like thus
#[derive(Accounts)]
pub struct InitializeProgramTokenAccount<'...
5
votes
3
answers
797
views
Program failed to complete: Instruction passed to inner instruction is too large (12884933924 > 1280)
I'm getting an error while executing an initialise code in my smart contract. I'm using Anchor Framework for my code. Below is the struct and the account:
#[derive(Accounts)]
pub struct ...
5
votes
1
answer
289
views
spl-token-2022 compilation error in anchor build
I am running anchor build and faced into an issue mentioned on Anchor discord.
After fixing this issue by adding to dependencies, now I am facing this error even if I do not use spl-token-2022. Here ...
6
votes
2
answers
222
views
Compile error on Anchor 0.27 when using anchor-spl
I am using the following Anchor dependencies:
anchor-lang = "0.27.0"
anchor-spl = { version = "0.27.0", features = ["metadata"] }
But it breaks when compiling because ...
0
votes
2
answers
244
views
Can we use pda as signer and payer to create an account in any solana program
I have asked same kind of question earlier but not got proper answer.
As I got an answer in my previous question in which I have to use system owned pda account, I have also tried this but getting ...
1
vote
1
answer
70
views
How multiple accounts can sign transaction in PDA CPI
How can multiple accounts can sign transaction along with PDA ?
In PDA based CPI in which PDA signs transactions, how can we use multiple accounts as a signers ?
I have to create an account in callee ...
0
votes
1
answer
418
views
update rustc that anchor uses
After running cargo build-bpf I get the following error:
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
error: package ...
2
votes
1
answer
23
views
Does anyone have a coding standard documentation for Rust programming on Solana?
I have written smart contract in Rust using Anchor framework on Solana blockchain. I need to make sure that I'm following all the right coding standards. So if anyone happens to have a coding standard ...
2
votes
1
answer
96
views
constructs a new Loader from account. using AccountLoader from anchor_lang crate
i referred this https://docs.rs/anchor-lang/latest/anchor_lang/accounts/account_loader/struct.AccountLoader.html for Constructs a new Loader from account.
use anchor_lang::prelude::*;
use whirlpools::...
0
votes
0
answers
56
views
Access violation in unknown section at address 0x0
in this log, my logic is completed in instruction but somehow Program failed to complete. Can anyone help me here? why program is failing.
logs: [
'Program <my_program> invoke [1]',
'...
0
votes
0
answers
29
views
I'm trying to initialize an account for my program but I get "account doesn't exist". It worked on devnet but didn't work on mainnet pls help
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
let accts = ctx.accounts;
accts.global_state.admin = accts.admin.key();
accts.global_state.dev_wallet ...
0
votes
1
answer
125
views
Not able to call a anchor function, please help
I have a withdrawAll function written in Anchor lang but I'm not able to call it, I keep getting
"Uncaught (in promise) Error: Invalid arguments: admin not provided."
If you know how I can ...
1
vote
0
answers
36
views
Topic support when subscribing to Solana programs events
Anchor events are fairly easy to use in JS and Rust, nonetheless the current integration many times forces us to receive hundreds or thousands of irrelevant emitted program events. Is there a way to ...
0
votes
1
answer
84
views
How to define constants in Anchor
Is there some special approach for defining constants in Anchor? I tried it normally just before the program ID:
pub const MY_CONST: &'static str = "some example str";
declare_id!("...
2
votes
1
answer
62
views
How to define fixed variables in Anchor programs
Is it possible to define a variable within the Anchor.toml file and then use it during run time inside the anchor program? I couldn't find how in the docs.
I guess an alternative could be defining the ...
1
vote
0
answers
33
views
How to call another instruction from the same Anchor program (No CPI) [duplicate]
Is there a way to invoke an instruction within the same program? just for the sake of code reusability, I know we can achieve this easily with CPI when invoking different programs instructions, but I ...
0
votes
1
answer
96
views
anchor program not getting build
here is my code, I'm using anchor 0.26.0.
I'm getting some error while building
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod ...
1
vote
2
answers
279
views
Why use the 'AccountInfo' account type?
I'm looking for clarification on when and why I should use the 'AccountInfo' type instead of passing an account as a function parameter in anchor_lang.
For example:
Both following programs do the same ...
7
votes
4
answers
849
views
Stack offset error for anchor build
How can I fix this error? This is a basic anchor smart contract that initializes an account. There's only one value, an integer, stored. I tried boxing the account (to put the storage on the heap, ...
1
vote
1
answer
99
views
How to Mint a NFT which belongs to certain collection in Anchor tests
Is there an easy way to mint some fake NFT that belongs to certain fake collection within Anchor JS tests? This would be really handy for testing Anchor instructions, NFTs validation/authentication ...