Using anchor

pub fn instruction(ctx: Context<InstructionContext>, arg1: String, arg2: Vec<String>) -> Result<()> {

How should I "encode" the args to pass them from the client ? Should i pass a String directly, or use Buffer.encode(string) ? Same question for the Vec arg, how should I pass the array

const ix = await program.methods
                .instruction(Buffer.from(arg1), ["foo", "bar", "foobar"])

(this is not working)

1 Answer 1


Anchor will automatically serialise the arguments for you.

                .instruction("str argument", ["foo", "bar", "foobar"])

Check out the types reference https://www.anchor-lang.com/docs/javascript-anchor-types

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.