0

I'm trying to fetch a PDA account and use one of it's properties as a seed for another PDA account. Here's what the implementation looks like:

const [ registryPDA, registryBump ] = PublicKey.findProgramAddressSync([Buffer.from('REGISTRY')], PROGRAM_KEY);
const registry = await program.account["registry"].fetch(registryPDA);
const company_id = registry.totalCompanies.toArrayLike(Buffer, "be", 8);

const [ companyPDA, companyBump ] = PublicKey.findProgramAddressSync([Buffer.from('COMPANY'), company_id], PROGRAM_KEY);

but it gives an error for registry.totalCompanies: 'registry.totalCompanies' is of type 'unknown'
It seems like since registry variable is type of unknown, it can't figure out how to turn it into Buffer. How can I specify it's account type?

1 Answer 1

0

I was declaring the program as:

const program = new Program(IDL as Idl, PROGRAM_KEY, provider)

But I was able to use the IdlType anchor created in types/.ts and solve the error by declaring program as:

const program = new Program(IDL as Main, PROGRAM_KEY, provider)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.