https://github.com/0xpolygon/eth-state-transition
Ethereum state transition
https://github.com/0xpolygon/eth-state-transition
Last synced: about 1 year ago
JSON representation
Ethereum state transition
- Host: GitHub
- URL: https://github.com/0xpolygon/eth-state-transition
- Owner: 0xPolygon
- Created: 2021-11-12T10:09:59.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-18T07:58:37.000Z (about 3 years ago)
- Last Synced: 2025-03-29T05:34:24.709Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 588 KB
- Stars: 6
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Eth-state-transition
Ethereum state transition function.
## Usage
```golang
import (
itrie "github.com/0xPolygon/eth-state-transition/immutable-trie"
"github.com/0xPolygon/eth-state-transition/runtime"
state "github.com/0xPolygon/eth-state-transition"
)
func main() {
// get a reference for the state
state := itrie.NewArchiveState(itrie.NewMemoryStorage())
snap := s.NewSnapshot()
// create a transition object
forks := runtime.ForksInTime{}
config := runtime.TxContext{}
transition := state.NewTransition(forks, config, snap)
// process a transaction
result, err := transition.Write(&state.Transaction{})
if err != nil {
panic(err)
}
fmt.Printf("Logs: %v\n", result.Logs)
fmt.Printf("Gas used: %d\n", result.GasUsed)
// retrieve the state data changed
objs := transition.Commit()
// commit the data to the state
if _, err := snap.Commit(objs); err != nil {
panic(err)
}
}
```