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?
If you look at the implementation that you linked, you'll see that wrapping simply involves doing
system_program::create_accountandspl_token::initialize_accountusing the native mint address.In TS, there's a helper called
createWrappedNativeAccountat https://github.com/solana-labs/solana-program-library/blob/master/token/js/src/actions/createWrappedNativeAccount.ts, which you use as: