Here is a step-by-step guide and sample code that should help you resolve the “unsupported transaction type” error when fetching blocks from BaseChain with Go-Ethereum (Geth):
Issue Description
The issue occurs because the BlockByNumber method returns an empty or incorrect response, which can be misleading. The transactionType field is not present in the returned block data.
Solution
To resolve this issue, you need to inspect the actual block data and identify the transaction type that was processed by BaseChain. You can do this using Geth’s internal logs or the Ethereum-Go-RPC API.
Step 1: Inspect the Block Data
You will need to fetch a specific block from BaseChain using BlockByNumber with the correct transaction hash and number. Next, inspect the returned block data to identify the type of transaction that was processed by the BaseChain.
Here’s an example code snippet that shows how to do this:
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethers/v5"
)
func main() {
// Replace with the correct transaction hash and number for your block
blockNumber := 12345 // Replace with the actual block number
txHash := "0x...Transaction Hash..."
contractAddress := "0x...Contract Address..."
contractInterface := contractAddress
ethers := &go.Ethers{}
// Fetch the block using BlockByNumber
block, err := ethers.BlockByNumber(context.Background(), contractInterface, txHash, 12345)
if err != nil {
fmt.Println(err)
return
}
// Inspect the returned block data to identify the transaction type
for _, t := range block.Data {
if t.Type == go.ETH_TYPE Transaction {
fmt.Printf("Transaction Type: %s\n", t.Value)
}
}
}
Step 2: Identify the correct transaction type

From the inspection in step 1, you should be able to identify the type of transaction that the BaseChain is processing. You can use Go-Ethereum’s (Geth) TransactionType enum values to verify that the correct type is being returned.
For example:
type goETHTransactionType uint8
const (
ETH_TYPE TransactionType = iota // 0x...Transaction Type...
)
func (t go.ETHTransactionType) String() string {
switch t {
case ETH_TYPE:
return "Transaction"
default:
return "Unknown"
}
}
Step 3: Update the code
Replace the BlockByNumber method calls with the correct transaction hash and number, and update the inspection logic to identify the correct transaction type.
Here’s an updated sample code snippet that shows how to do this:
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethers/v5"
)
func main() {
// Replace with the correct transaction hash and number for your block
blockNumber := 12345 // Replace with the actual block number
txHash := "0x...Transaction Hash..."
contractAddress := "0x...Contract Address..."
ethers := &go.Ethers{}
// Fetch the block using BlockByNumber with the correct transaction hash and number
block, err := ethers.BlockByNumber(context.Background(), contractAddress, txHash, blockNumber)
if err != nil {
fmt.Println(err)
return
}
// Inspect the returned block data to identify the transaction type
for _, t := range block.Data {
if t.Type == go.ETH_TYPE Transaction {
fmt.Printf("Transaction Type: %s\n", t.Value.String())
}
}
}
By following these steps, you should be able to resolve the “unsupported transaction type” error when fetching blocks from the BaseChain with Go-Ethereum (Geth).

Recent Comments