0

Using Solana Web3 TS library how can we wrap and unwrap SOL?

Here on this link it is possible to see what the SPL Token CLI program does for wrapping and unwrapping SOL, but the conversion of those methods to TypesScript is not straightforward.

How can we programmatically create 2 instructions, one for wrapping SOL and the other one for unwrapping it, so we could include them in a transaction and test them?

GarouDan
  • 3,743
  • 9
  • 49
  • 75

1 Answers1

0

If you look at the implementation that you linked, you'll see that wrapping simply involves doing system_program::create_account and spl_token::initialize_account using the native mint address.

In TS, there's a helper called createWrappedNativeAccount at https://github.com/solana-labs/solana-program-library/blob/master/token/js/src/actions/createWrappedNativeAccount.ts, which you use as:

        const account = await createWrappedNativeAccount(
            connection,
            payer,
            owner,
            lamports,
        );
Jon C
  • 7,019
  • 10
  • 17