I'm trying to write a script in Go to interact with a smart contract on Binance Smart Chain using an RPC and the github.com/ethereum/go-ethereum
package. However, I keep getting "panic: hex string of odd length" when trying to call a method involving a bind.TransactOpts
struct. Here's the relevant code:
secret_key := "<my_secret_key>"
sk, _ := crypto.HexToECDSA(secret_key)
wallet_addr := crypto.PubkeyToAddress(sk.PublicKey)
auth, _ := bind.NewKeyedTransactorWithChainID(sk, big.NewInt(56))
...
tx := &bind.TransactOpts{
From: wallet_addr,
Nonce: nil,
Signer: auth.Signer,
Value: min_bet,
GasPrice: nil,
GasFeeCap: nil,
GasTipCap: nil,
}
attempt, err := instance.BetBull(tx, epoch)
if err != nil {
panic(err)
}
fmt.Println(attempt)
The problem seems to me to be with the Signer
field of tx
. When I run fmt.Println(auth.Signer)
the output is 0x4341680
, which has 9 characters. I'm new to coding and just doing this for fun, so it's likely that I'm missing something obvious, but I can't figure out how to fix this. Any help would be appreciated. Thanks.