1

Hi I was working on making a contract that should support both SOL and SPL tokens.

Is there a recommended way to manage SOL and SPL token altogether? It looks like we need to wrap SOL to make it work. A way I an thinking to do is ask the user to wrap it first, but it doesn't feel really user friendly.

Is there a recommended way to do that? I was thinking a function that could look like that:

pub fn function_one(ctx: Context<Game>, amount: u64) -> Result<()> {

    is_spl = detect_if_spl()
    
    if not spl { 
      wrap_sol() 
    }
   ...
   ...
}

Thank you!

1 Answer 1

1

You need to wrap sol in the client and then you can use it like a normal SPL token. Afterwards you can unwrap it again.

https://solana.com/de/developers/cookbook/tokens/manage-wrapped-sol

2
  • But this will ask the users using to have to make 2 transactions instead of one? Or is there a way to do both operations client side in one go? Commented Nov 9 at 2:11
  • 1
    You can have multiple instructions in the same transaction
    – Jonas H.
    Commented Nov 10 at 18:27

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.