ethereum/go-ethereum · error
trie.NewStateTrie called without a database
Error message
trie.NewStateTrie called without a database
What it means
Error "trie.NewStateTrie called without a database" thrown in ethereum/go-ethereum.
Source
Thrown at trie/secure_trie.go:80
// New and must have an attached database. The database also stores
// the preimage of each key if preimage recording is enabled.
//
// StateTrie is not safe for concurrent use.
type StateTrie struct {
trie Trie
db database.NodeDatabase
preimages preimageStore
secKeyCache map[common.Hash][]byte
}
// NewStateTrie creates a trie with an existing root node from a backing database.
//
// If root is the zero hash or the sha3 hash of an empty string, the
// trie is initially empty. Otherwise, New will panic if db is nil
// and returns MissingNodeError if the root node cannot be found.
func NewStateTrie(id *ID, db database.NodeDatabase) (*StateTrie, error) {
if db == nil {
panic("trie.NewStateTrie called without a database")
}
trie, err := New(id, db)
if err != nil {
return nil, err
}
tr := &StateTrie{
trie: *trie,
db: db,
secKeyCache: make(map[common.Hash][]byte),
}
// link the preimage store if it's supported
if preimages, ok := db.(preimageStore); ok && preimages.PreimageEnabled() {
tr.preimages = preimages
}
return tr, nil
}
View on GitHub (pinned to 6bb0588ad8)
Solutions
- Always pass a non-nil database to trie.NewStateTrie. Obtain it from the chain/state database (e.g., state.NewDatabase or triedb) instead of nil.
- Guard construction: check db != nil before calling NewStateTrie and return an error to the caller.
Example fix
if db == nil {
return nil, errors.New("state trie requires a database")
}
tr, err := trie.NewStateTrie(id, db) When it happens
Trigger: Calling trie.NewStateTrie(id, nil) — constructing a state trie without a backing node database.
Common situations: Test setups or new code paths that forget to wire the triedb/database dependency into the trie constructor.
AI-assisted analysis of ethereum/go-ethereum@6bb0588ad8 (2026-08-15).
Data as JSON: /api/errors/63d914ab298c8a69.
Report an issue: GitHub.