Open Moses-Alero opened 1 week ago
your example might not work. tx.Message.Instructions
is compiled instruction. you need the same account list to generate a correct compiled instruction. we can do something similar to transaction.add()
by this SDK but it's a bit tricky atm. could you provide more details about your scenario? does it help if you pass the instructions instead then compose them into a transaction in the finial step?
@yihau my current use case requires the transaction to be passed in as an argument to a function then an additional instruction which is the new instruction is then added to the transaction before it is then used. Here's a simple example
func CreatePostRes(tx types.Transaction, ref common.PublicKey){
//do simple check
if len(tx.Message.Instruction) < 1 {
return
}
instruction := fetchNewInstruction(ref)
//append instruction to tx
tx = AddIxToTransaction(tx, instruction) //we do the tricky stuff here
...
}
Something like the above.
If only there was a way to decompile instructions then compile them back with the data intact. I think that might be helpful too.
you said that doing something similar to transaction.add()
is possible but tricky. I'm pretty sure I can handle tricky :)
I would like to know if it is possible to add new instructions to pre-existing transactions similar to
transaction.add()
in the@solana/web3.js
package.I tried to do something to make it work using the example below
I tried to make it work using the example above. It returns tx hash but the second instruction isn't added to the transaction when viewed on the explorar Is there a way to do this?