Creating Counter Precompile
Learn how to create a Stateful Counter Precompiles in Subnet EVM.
What We Are Building
It's time to build our first stateful precompile. In particular, we'll build a counter that keeps track of an integer. Our Counter precompile will have the following logic:
- Users are able to get the current value of the counter
- Users are able to set a new value to the counter
- Users are able to increment the value of the counter
To help you understand, we've provided a reference stateful precompile: StringStore. As the name suggests, StringStore stores a string that users can change. This string is stored in the EVM state.
Overview of Steps
Compared to the process before, we must also add tests for our precompile. Here's a quick overview of the steps we'll follow:
- Create a Solidity interface for the precompile and generate the AB
- Generate the precompile Go boilerplate files
- Write the precompile code in Go with access to the EVM state
- Set the initial state in the configurator and register the precompile
- Add and run tests
- Build and run your customized EVM
- Connect Remix to your customized EVM and interact with the counter
This tutorial will help you create more complex precompiles. Let's begin!