Closed AnishDe12020 closed 1 year ago
However many wallets (for e.g. Glow) add an instruction at the end of every Solana Pay transaction (they use it to tag accounts and send messages)
Can you provide an example of such a transaction for us to look at?
The relevant part of the spec says
the wallet must include a
TokenProgram.Transfer
orTokenProgram.TransferChecked
instruction as the last instruction of the transaction. [...] the wallet must include aSystemProgram.Transfer
instruction as the last instruction of the transaction instead.
If Glow, or any wallet, is not doing this, it's not following the spec, so we need to figure out why and if we can change that.
Can you provide an example of such a transaction for us to look at?
the last program is a note program
I had reached out to Glow on twitter and this was their response -
I had the same issue just running the example here with a native SOL transfer.
I was consistently getting Error: invalid instruction; programId is not SystemProgram
when running validateTransfer
.
For a quick fix, just changed instructions.pop()
to instructions[0]
and the instruction was validated. Agree with OP that some type of iteration or filter might be more appropriate that the pop. Also, I could imagine an optional program parameter for this function so you could validate custom instructions.
The issue here is that the spec says the transfer ix must be last, immediately preceded by the memo ix. Glow is adding its own note ix at the end. I'm told that this issue is fixed in Glow now, I believe by inserting the note ix first. Can you check?
told that this issue is fixed in
yeah that works. thx for quick reply. sry about that.
Currently the
validateTransfer
function in the SDK only returns (does not throw) when the token transfer was done on the last instruction. However many wallets (for e.g. Glow) add an instruction at the end of every Solana Pay transaction (they use it to tag accounts and send messages) and hence thevalidateTransfer
function throws.It would be better if we loop through all the instructions, check if it is a token transfer instruction (jn case it is an spl token) transfer or try to decode it (continue upon failure) so that we can check all the instructions
Here is how I have implemented it