0

The title says it all: If my anchor instruction expects an Option<T> to be passed what do I need to send in typescript for None and Some<T> respectively? I checked the docs but couldn't find any info on this.

1
  • For None I've tried undefined, null,[undefined], [null], {} but all of these result in InstructionDidNotDeserialize
    – McBain
    Commented Apr 17 at 8:03

1 Answer 1

2

If you mean the transaction data (arguments) then null works fine for me.

In particular for recent Anchor project we pass configuration options either with value (to be configured) or None (to not be configured). The program arguments are defined as: https://github.com/marinade-finance/validator-bonds/blob/main/programs/validator-bonds/src/instructions/config/configure_config.rs#L7

The Anchor TS IDL is generated as: https://github.com/marinade-finance/validator-bonds/blob/contract-v1.4.0/packages/validator-bonds-sdk/generated/validator_bonds.ts#L2936

And the Anchor TS types are loaded and used in the following way to pass null at on-chain call.

1
  • 1
    null works now for me, so the error I was facing stemmed from something else. Thanks for the elaborate answer!
    – McBain
    Commented Apr 19 at 4:33

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.