3

I'm trying to do a token swap through the SPL token swap program. I have been looking at transactions in solscan to get an idea about which instructions are needed. An example here:

https://solscan.io/tx/5hLxbXPEPSmoMJfH4CtmYWRh6d8eHyfJpinLiq7uJ3GEZsmhkCgnTjZaGXAGbUVnXsTVe6Pe2FBNDnJYWP64rsgu

I have also used the following solana docs resource to better understand how to do a swap through the Token Swap Program: https://spl.solana.com/token-swap

I think I have a good understanding of the "swap" instruction. However, I stuggle to understand the purpose of the "Approve" instruction, and how to construct one.

I also wonder what the "User Transfer Authority" field means in the Swap instruction. I think this is just a generated "Throw away" keypair, that is used in the instruction. However, I don't really understand the purpose of it.

As a note, I try to do this in a Rust Client, and I'm not using Anchor.

Can someone explain to me, what the purpose of the "Approve" Instruction in the solscan example above is, and how to construct one using Rust (again not Anchor)?. Also, it would be nice if someone could confirm my understanding of the "User Transfer Authority" field in the solscan example.

Thanks in advance,

CTKI

1 Answer 1

1

The purpose of the approve instruction is to delegate the right to transfer up to delegated_amount to the delegate Pubkey.

If this Pubkey signs a token transfer it is allowed to transfer up to the delegated_amount from your token account it doesn't "own".

When you interact with a program, it allows you to be certain the program cannot transfer more that what has been approved by the first instruction.

Usually you would approve an ephemeral keypair, generated by you on the frontend, and revoke right after the swap.

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.