以太坊错误 "code":-32000,"message":"unknown account"
Posted
技术标签:
【中文标题】以太坊错误 "code":-32000,"message":"unknown account"【英文标题】:Ethereum error "code":-32000,"message":"unknown account"以太坊错误 "code":-32000,"message":"unknown account" 【发布时间】:2021-12-16 14:51:32 【问题描述】:我正在尝试使用eth.sendTransaction
发送原始交易,但我收到一条错误消息,显示为"code":-32000,"message":"unknown account"
。我不确定是什么原因造成的,我似乎无法在互联网上找到答案。谁能帮我弄清楚?这是我的代码:
func ExecuteSignedTransaction(rawTransaction string)
var hash web3.Hash
data := make(map[string]interface)
data["data"] = rawTransaction
err := Web3HTTPClient.Call("eth_sendTransaction", &hash, data)
if err != nil
fmt.Println(err)
Os.Exit(1)
fmt.Println("Sent tx hash:", hash)
【问题讨论】:
您需要使用类似*bind.TransactOpts
的实例来签署交易。我的一般建议是使用类似于 go-ethereum 包中已有的 *ethclient.Client
的东西,它提供了非常有用的接口来做这样的事情——还有更多关于它的文档,你可能已经能够否则找到。但是,如果您不想使用 *ethclient.Client
,请考虑使用您控制的帐户的私钥签署您的 rawTransaction。
【参考方案1】:
那么,我可能在这里做什么:
import (
"strings"
"crypto/ecdsa"
"math/big"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
)
var chainId = big.NewInt(1) // chain id for the ethereum mainnet, change according to needs
func ecdsaPrivateKeyFromHex(privKeyHex string) *ecdsa.PrivateKey
ecdsaKey, err := crypto.HexToECDSA(privKeyHex)
if err != nil panic(err)
return ecdsaKey
func newTransactOpts(privKey *ecdsa.PrivateKey) *bind.TransactOpts
transactOpts, err := bind.NewKeyedTransactorWithChainID(privKey, chainId)
if err != nil panic(err)
return transactOpts
func newRpcClient() *ethclient.Client
c, err := ethclient.Dial("insert rpc url here")
if err != nil panic(err)
return c
// note: constructing the *types.Transaction object left as
// an exercise to the reader
func ExecuteTransaction(rawTransaction *types.Transaction)
privKeyHex := "0xblahblahblahblahblah" // use your own account's private key
transactOpts := newTransactOpts(ecdsaPrivateKeyFromHex(privKeyHex))
signedTxn, err := transactOpts.Signer(transactOpts.From, rawTransaction)
if err != nil panic(err)
rpcClient := newRpcClient()
if err := rpcClient.SendTransaction(context.Background(), signedTxn); err != nil panic(err)
// do whatever
【讨论】:
以上是关于以太坊错误 "code":-32000,"message":"unknown account"的主要内容,如果未能解决你的问题,请参考以下文章
为啥在尝试从节点脚本部署以太坊智能合约时出现“无效发件人”(-32000)?