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

TransactionReceipt function needs to wait for a certain number of block confirmations #35

Open
Tracked by #55
Ravenyjh opened this issue Sep 23, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request p1

Comments

@Ravenyjh
Copy link
Collaborator

something like that

 receipt, err := client.TransactionReceipt(ctx, txHash)
       if err == ethereum.NotFound {
           log.Println("Transaction not found yet. Retrying...")
           time.Sleep(pollingInterval)
           continue
       } else if err != nil {
           log.Fatalf("Failed to get transaction receipt: %v", err)
       }

       // 获取最新的区块号
       header, err := client.HeaderByNumber(ctx, nil)
       if err != nil {
           log.Fatalf("Failed to get latest block: %v", err)
       }

       // 计算确认数量
       confirmations := new(big.Int).Sub(header.Number, receipt.BlockNumber).Uint64()
       if confirmations >= confirmationsRequired {
           fmt.Printf("Transaction has been confirmed with %d confirmations.\n", confirmations)
           break
       } else {
           fmt.Printf("Transaction has %d confirmations; waiting for %d more confirmations...\n", confirmations, confirmationsRequired-confirmations)
           time.Sleep(pollingInterval)
       }
       ```
@Ravenyjh Ravenyjh added the enhancement New feature or request label Sep 23, 2024
@Ravenyjh Ravenyjh self-assigned this Sep 23, 2024
@Ravenyjh Ravenyjh added the p1 label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p1
Projects
None yet
Development

No branches or pull requests

1 participant