Created
November 3, 2021 23:21
-
-
Save benhenryhunter/3f1fc34c89887aaf0f25091ff1cfe9bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"strconv" | |
"strings" | |
"github.com/ethereum/go-ethereum/common" | |
"github.com/ethereum/go-ethereum/ethclient" | |
) | |
func main() { | |
client, err := ethclient.Dial("eth.net") | |
if err != nil { | |
log.Fatal(err) | |
} | |
txHash := common.HexToHash("0x25368782ac11e0466b6b88ebf9c93d76bf4374f4036b777df0f772a1668f5ca9") | |
txReceipt, err := client.TransactionReceipt(context.Background(), txHash) | |
if err != nil { | |
log.Fatal(err) | |
} | |
logWithData := txReceipt.Logs[1] | |
tokenHexValue := logWithData.Topics[3].Hex() | |
numberStr := strings.Replace(tokenHexValue, "0x", "", -1) | |
numberStr = strings.Replace(numberStr, "0X", "", -1) | |
output, err := strconv.ParseInt(numberStr, 16, 64) | |
if err != nil { | |
log.Fatal(err) | |
} | |
tokenId := output | |
from := logWithData.Topics[1].String()[26:] | |
to := logWithData.Topics[2].String()[26:] | |
fmt.Printf("Token Number: %v\nFrom Address: 0x%v\nTo Address:0x%v", tokenId, from, to) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment