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

Instructions from a Rust client #883

Closed
MartinKavik opened this issue Oct 14, 2021 · 5 comments
Closed

Instructions from a Rust client #883

MartinKavik opened this issue Oct 14, 2021 · 5 comments

Comments

@MartinKavik
Copy link

MartinKavik commented Oct 14, 2021

Hi,

Context
I've written the Rust-only example with Solana and MoonZoon (MartinKavik/voting-solana-moonzoon). And I'm just rewriting it to Anchor (MartinKavik/voting-anchor-moonzoon).

The problem
I don't use Javascript so I can't use a generated client from IDL - I create transactions and instructions in Rust code.
I was able to create "native" Solana instructions this way:

pub fn init_voting(voting_owner_pubkey: &Pubkey) -> Instruction {
    let account_metas = vec![
        AccountMeta::new(*voting_owner_pubkey, true),
        AccountMeta::new(voting_state_pubkey(voting_owner_pubkey), false),
    ];
    Instruction::new_with_borsh(crate::id(), &VotingInstruction::InitVoting, account_metas)
}

but I don't know how to rewrite the code to make it compatible with Anchor instructions.

Anchor instructions and accounts and errors are defined in https://github.com/MartinKavik/voting-anchor-moonzoon/blob/master/program/programs/voting_program/src/lib.rs

Thank you!


Other problems (probably suitable for new issues):

  • Discord links don't work.
  • How to call system_instruction::create_account_with_seed to make the account compatible with Anchor?
  • How to pass a custom keypair to the command anchor deploy - an alternative to:
    solana program deploy -C ./config.yml --program-id ./keypairs/program-keypair.json ./target/deploy/voting_program.so
@gitmalong
Copy link

Have you found a solution? I'm looking for the equivalent of the following JS code in Rust.

    const program = new Program(
      idl as Idl,
      id,
      new Provider(bn.conn, null, {
        preflightCommitment: 'recent',
        commitment: 'recent',
      }),
    );

@armaniferrante
Copy link
Member

Example rust client with anchor programs here https://github.com/project-serum/anchor/blob/master/client/example/src/main.rs

@armaniferrante
Copy link
Member

Closing as I dont see anything actionable here.Closing as there doesn't

@MartinKavik
Copy link
Author

@gitmalong I was hired to write a tool to generate nice APIs for sending Anchor instructions (https://ackeeblockchain.com/blog/announcing-trdelnik-rust-testing-client-for-anchor/). Currently, it uses Rust compiler to expand Anchor program macros, then it parses the code with syn to Rust IDL and then it generates+format typed functions for sending instructions. I'm also playing with integration of Jupyter Notebook and REPL. It should be the most typed generated API because I don't need to care about JS-friendly/universal IDL and generators.
Under the hood it uses Anchor's APIs + code genereated by Anchor macros that you can always use directly as I've found out during the development (and you can see it in the link above posted by @armaniferrante )

@aslanahmtv
Copy link

Having the same issue as I need Rust to interact with an Anchor Program I don't have sources of. Are there any ways of interacting with them only having IDL and public key?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants