Create Solidity Interface
Learn how to create a solidity interface for your counter precompile.
Now, we'll create a Solidity interface for our Stateful Precompile.
StringStore Solidity Interface
To start, let's look at the interface of the StringStore precompile:
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IStringStore {
function getString() external view returns (string memory value);
function setString(string memory value) external;
}
As seen above, we have the following two functions defined:
getString
: retreives the string from the stateful precompilesetString
: sets a string in the stateful precompile
Create Solidity Interface for Counter
Create an interface for the counter in the same directory called ICounter.sol
. Your interface should have the following three functions declared:
getCounter
: returns the counter value from the stateful precompileincrementCounter
: when called, this function increments the current countersetCounter
: takes in a value, and sets it as the counter of the stateful precompile
For any argument/return value, make sure it is named as value
.
Generate the ABI
Now that we have an interface of our precompile, let's create an ABI of our Solidity interface. Open the terminal (control + `), change to the /contracts
directory, and run the command to compile the solidity interface to ABI:
# Move to contracts directory
cd contracts
# Compile ICounter.sol to ABI
npx solc@latest --abi ./contracts/interfaces/ICounter.sol -o ./abis --base-path . --include-path ./node_modules
# Rename
mv ./abis/contracts_interfaces_ICounter_sol_ICounter.abi ./abis/ICounter.abi
Edit on GitHub
Last updated on 1/23/2025