Closed BillInUK closed 6 months ago
Pumpfun was built with anchor so you have to generate the appropriate bindings to decode
thanks for help , i resloved with following code:
// 查询token有关的交易
func TestQueryTokenTx(t *testing.T) {
client := rpc.New(DevRpc)
txSig := solana.MustSignatureFromBase58("5aVh3XHbD7TP4gPzFcybPmHp59en64KYdJzehZfishgQUoJ7AZpzbFsumVN1JKKVSzHx1WZSZ6VANjG9zzQHnujF")
{
out, err := client.GetTransaction(
context.TODO(),
txSig,
&rpc.GetTransactionOpts{
Encoding: solana.EncodingBase64,
},
)
if err != nil {
panic(err)
}
tx, err := solana.TransactionFromDecoder(bin.NewBinDecoder(out.Transaction.GetBinary()))
if err != nil {
panic(err)
}
decodeSPLTokenTransfer(tx)
}
}
func decodeSPLTokenTransfer(tx *solana.Transaction) {
// 依次解析命令,解析出的TransferChecked指令为止
for _, inst := range tx.Message.Instructions {
progKey, err := tx.ResolveProgramIDIndex(inst.ProgramIDIndex)
if err != nil {
break
}
fmt.Printf("progKey is %v \n", progKey)
accounts, err := inst.ResolveInstructionAccounts(&tx.Message)
if err != nil {
break
}
decodedInst, err := token.DecodeInstruction(accounts, inst.Data)
if err != nil {
continue
}
if transferInfo, ok := decodedInst.Impl.(*token.TransferChecked); ok {
fmt.Printf("from %v\n", transferInfo.Accounts.Get(0).PublicKey.String())
fmt.Printf("to %v\n", transferInfo.Accounts.Get(2).PublicKey.String())
fmt.Printf("token %v\n", transferInfo.Accounts.Get(1).PublicKey.String())
fmt.Printf("amount %d\n", *transferInfo.Amount)
fmt.Printf("decimals %d\n", *transferInfo.Decimals)
}
}
}
@BillInUK hi,
if transferInfo, ok := decodedInst.Impl.(*token.TransferChecked); ok {
fmt.Printf("from %v\n", transferInfo.Accounts.Get(0).PublicKey.String())
fmt.Printf("to %v\n", transferInfo.Accounts.Get(2).PublicKey.String()) // 65h8ExrJjVXo65VyP1NWGTYfBgVVPS1e3nBnt6K1EkWA
fmt.Printf("token %v\n", transferInfo.Accounts.Get(1).PublicKey.String())
fmt.Printf("amount %d\n", *transferInfo.Amount)
fmt.Printf("decimals %d\n", *transferInfo.Decimals)
}
your tx: 2kX9yRqsFH6tqDuSkM8tEApXYygvfDK6t2gvaqrAK9whg8Z3fmLdMi3MjZqfFgiubDkGQDLKGH6Fr9a3yBCkgFXY
transferInfo.Accounts.Get(2).PublicKey.String() = 65h8ExrJjVXo65VyP1NWGTYfBgVVPS1e3nBnt6K1EkWA
But the actual receiving address is:5D4MWh35wxUcY1hBsm5GwuippPL2UBmfDnfkC8MeqxcN
How can we obtain the real token receiving address?
thanks.
i use the latest version of solana-go to decode spl transfer transaction on mainnet with the following codee:
when i run this test case it panic,and the output in console:
it panic at