Skip to content
Advertisement

How to pass public key in javascript struct to anchor rpc method

I am trying to pass a public key to a anchor rpc method but think I am not generating it correctly in Javascript, I tried padding it with and without quotes but to no avail. anchor test gives me a TypeError: key.toBuffer is not a function IF I pad it. IF I do not pad it then I get the error Error: AnchorError caused by account: my_account. Error Code: AccountDidNotSerialize. Error Number: 3004. Error Message: Failed to serialize the account.

I suspect the issue is with my javascript code:

JavaScript

Full code below.

Lib.rs

JavaScript

basic-1.js

JavaScript

basic_1.json

JavaScript

Advertisement

Answer

You misunderstood the problem. The issue here is not with Pubkey passing.

You are running out of space while adding signatory.

What you need to do is pre calculate the space required to store max number of signatories allowed to store in vec. It must have the bound.

Please refer https://borsh.io/#pills-specification to calculate how much space is required for you.

To validate this you can change the space from 100 to 1000

JavaScript

this worked fine for me

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement