Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Jetton Transfers in Transaction Query #262

Open
keyliaran opened this issue Sep 25, 2024 · 2 comments
Open

Missing Jetton Transfers in Transaction Query #262

keyliaran opened this issue Sep 25, 2024 · 2 comments

Comments

@keyliaran
Copy link

I'm attempting to retrieve transactions, but I am only receiving a single transaction involving TON transfer. Is it possible to also retrieve transactions with Jetton (USDT) transfers?

Explorer Link:
TONSCAN Explorer

There should be two USDT transfers and one TON transfer visible for the address.

Code Sample:

package main

import (
	"context"
	"encoding/base64"
	"log"

	"github.com/xssnick/tonutils-go/address"
	"github.com/xssnick/tonutils-go/liteclient"
	"github.com/xssnick/tonutils-go/ton"
)

const (
	num = 10
)

func main() {
	client := liteclient.NewConnectionPool()
	err := client.AddConnectionsFromConfigUrl(context.Background(), "https://ton.org/global.config.json")
	if err != nil {
		panic(err)
	}

	api := ton.NewAPIClient(client, ton.ProofCheckPolicyFast).WithRetry()

	accountAddr := address.MustParseAddr("UQC7CECsMMrNJVcxJH8TlR-tK8yTS3gOC2JVvQdYyeC1RVZA")

	// we need fresh block info to run get methods
	b, err := api.CurrentMasterchainInfo(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	// we use WaitForBlock to make sure block is ready,
	// it is optional but escapes us from liteserver block not ready errors
	res, err := api.WaitForBlock(b.SeqNo).GetAccount(context.Background(), b, accountAddr)
	if err != nil {
		log.Fatal(err)
	}

	lastTransactionId := res.LastTxHash
	lastTransactionLT := res.LastTxLT

	headSeen := false

	for {
		trxs, err := api.ListTransactions(context.Background(), accountAddr, num, lastTransactionLT, lastTransactionId)

		if err != nil {
			log.Fatal(err)
		}

		log.Printf("transaction count %d", len(trxs))

		for i, tx := range trxs {
			// should include only first time lastTransactionLT
			if !headSeen {
				headSeen = true
			} else if i == 0 {
				continue
			}

			if tx.IO.In == nil || tx.IO.In.Msg.SenderAddr().IsAddrNone() {
				// external message should be omitted
				continue
			}

			if tx.IO.Out != nil {
				// no outgoing messages - this is incoming Toncoins
				continue
			}

			// process trx
			log.Printf("found in transaction hash %s", base64.StdEncoding.EncodeToString(tx.Hash))
		}

		if len(trxs) == 0 || (headSeen && len(trxs) == 1) {
			break
		}

		lastTransactionId = trxs[0].Hash
		lastTransactionLT = trxs[0].LT
	}
}

Can you help me understand how to modify the code to retrieve Jetton transfer transactions alongside the TON transfer? Thanks!

@xssnick
Copy link
Owner

xssnick commented Sep 27, 2024

Hi, as i see in explorer you have only one out transaction and you see it, if you want to see incoming then remove tx.IO.Out != nil

@keyliaran
Copy link
Author

keyliaran commented Sep 27, 2024

Currently, I have 8 transactions in total: 6 involving TON (5 incoming, 1 outgoing).
image
When I call the following method:

trxs, err := api.ListTransactions(context.Background(), accountAddr, num, lastTransactionLT, lastTransactionId)

And log the number of transactions (output will be 6)
log.Printf("transaction count %d", len(trxs))

I also print the transaction hashes (5 in msgs where i have recieved ton, and 1 out msg):

for i, tx := range trxs {
    log.Printf("found transaction hash %s", base64.StdEncoding.EncodeToString(tx.Hash))
}

However, I'm not receiving two transactions where I received USDT. The hashes for these missing transactions are:
(5c508c90aa472e06fa063b9d0396fec1975e1f5760d982363b3035f5bf0f7122, eDdYeBMSmHRDDeYyRzlhmUAFg/MqlbAOOiGT4W+PRdA=)

These transactions don't appear in the response, and I'm unsure why they're missing. Any ideas on what might be causing this?

Repository owner deleted a comment Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants