Querying Transactions
Loop through the transactions in the block, you can get transaction details.
Import the types
packages:
import (
"github.com/PhoenixGlobal/Phoenix-Chain-SDK/ethereum/core/types"
)
Query transaction details:
for _, trans := range block.Transactions() {
fmt.Println(trans.Hash().Hex()) // get transaction hash
fmt.Println(trans.Value().String()) // get transaction value
chianID, err := client.ChainID(context.Background())
if err != nil{
fmt.Println(err)
}
msg, err := trans.AsMessage(types.NewEIP155Signer(chianID))
if err != nil{
fmt.Println(err)
} else{
fmt.Println(msg.From().Hex()) // get from address
}
fmt.Println(trans.To().Hex()) // get to address
}
Or get transaction details directly by transaction hash:
txHash := common.HexToHash("0xdc52533193e5b31707d7a8cacb06eb78acbcd13dfc4917c61a2215806ad7ece6")
tx, isPending, err := client.TransactionByHash(context.Background(), txHash)
if err != nil {
log.Fatal(err)
}
fmt.Println(tx.Hash().Hex())
fmt.Println(isPending)
You can also get the transaction receipt by a transaction hash:
txHash := common.HexToHash("0xdc52533193e5b31707d7a8cacb06eb78acbcd13dfc4917c61a2215806ad7ece6")
receipt, err := client.TransactionReceipt(context.Background(), txHash)
fmt.Println(receipt.Status)
fmt.Println(receipt.Logs)
Last updated