5

I have an instruction that either sends SOL or SPL tokens to the signer depending upon the option chosen. I only want to include a mint of the SPL token in the context of SPL token option being chosen. Is it possible to use an optional account in the context or is it only possible through remaining_accounts?

1 Answer 1

6

Looks like Anchor 0.26 added support for optional accounts, might be useful for your use case

https://github.com/coral-xyz/anchor/blob/master/CHANGELOG.md#0260---2022-12-15

lang: Add support for optionally passing in accounts using the syntax Optional<Account<'info, T>>. Shouldn't affect existing programs but may be a breaking change to tools that use the anchor generated IDL.

https://github.com/coral-xyz/anchor/pull/2101

1
  • Very helpful, upvoted :). Small correction though: The correct syntax is Option not Optional
    – Ahri
    Mar 26 at 6:03

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.