Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 8063

how can anchor program A read account data from anchor program B with #account macro way?

$
0
0

My anchor program "A", expect to use data from a anchor program name "B".

Let's say program_b has declare PDA account data struct:

#[account]#[derive(InitSpace)] pub struct FeeData {    pub fee: u64,}

and I got this account address that pass into program_a.

And in program_a, related code is:

        ...#[account]#[derive(InitSpace)] pub struct FeeData {     // mock after the struct on program_b    pub fee: u64,}#[derive(Accounts)]pub struct Initialize<'info> {        .../// CHECK: no check purposelypub fee_from_prog_b: Account<'info, FeeData>,        ...}

But, once invode instruction on program_a, I got error:Error Code: AccountDiscriminatorMismatch. Error Number: 3002. Error Message: 8 byte discriminator did not match what was expected.'

I know there is account discriminator and why this error raise.After search in the forumn, I got this one:How to Deserialize Anchor Accounts from Other Programs in Accounts Struct but I don't like this way to make it work.

So, I'm looking for a better solution to this requirement.Thanks in advance.


Viewing all articles
Browse latest Browse all 8063

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>