You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+101
Original file line number
Diff line number
Diff line change
@@ -34,10 +34,111 @@ To get a comprehensive introduction to Precompile-EVM, take the Avalanche Academ
34
34
35
35
There is an example branch [hello-world-example](https://github.com/ava-labs/precompile-evm/tree/hello-world-example) in this repository. You can check the example branch to see how to register precompiles and test them.
cd precompile-evm/ # change directory to the precompile-evm/ directory
42
+
```
43
+
44
+
### Checkout the `hello-world-example` Branch
45
+
46
+
```zsh
47
+
git checkout hello-world-example
48
+
49
+
branch 'hello-world-example'set up to track 'origin/hello-world-example'.
50
+
Switched to a new branch 'hello-world-example'
51
+
```
52
+
53
+
### Install NodeJS Dependencies
54
+
55
+
First you have to `cd contracts/` and run `npm install` to get the dependencies.
56
+
57
+
```zsh
58
+
cd contracts/ # change directory to the contracts/ directory
59
+
npm install
60
+
```
61
+
62
+
### Create a New Contract
63
+
64
+
`hello-world-example` branch has already a precompile contract called `HelloWorld.sol`. All necessary files were already created for you. You can check existing files and see how a fully implemented precompile should look like. If you'd like to redo steps to create a new precompile contract, you can follow the steps below.
65
+
66
+
Copy the existing `IHelloWorld.sol` interface to a new file called `IHolaMundo.sol`.
67
+
68
+
```zsh
69
+
cd .. # change directory back to the root of the repo
- Use the given path as the root of the source tree instead of the root of the filesystem.
100
+
-`--include-path path`
101
+
- Make an additional source directory available to the default import callback. Use this option if you want to import contracts whose location is not fixed in relation to your main source tree, e.g. third-party libraries installed using a package manager. Can be used multiple times. Can only be used if base path has a non-empty value.
102
+
-`--output-dir path`
103
+
- If given, creates one file per output component and contract/file at the specified directory.
104
+
-`--overwrite`
105
+
- Overwrite existing files (used together with `--output-dir`).
106
+
107
+
```zsh
108
+
cd contracts/ # change directory to the contracts/ directory
Compiler run successful. Artifact(s) can be found in directory "abis".
112
+
```
113
+
37
114
### Generate Precompile Files
38
115
39
116
First, you need to create your precompile contract interface in the `contracts` directory and build the ABI. Then you can generate your precompile files with `./scripts/generate_precompile.sh --abi {abiPath} --out {outPath}`. This script installs the `precompilegen` tool from Subnet-EVM and runs it to generate your precompile.
40
117
118
+
```zsh
119
+
cd .. # change directory back to the root directory of the repo
Confirm that the new `holamundo/` directory has the appropriate files.
129
+
130
+
```zsh
131
+
ls -lh helloworld
132
+
133
+
-rw-r--r-- 1 user group 2.3K Jul 5 13:26 README.md
134
+
-rw-r--r-- 1 user group 2.3K Jul 5 13:26 config.go
135
+
-rw-r--r-- 1 user group 2.8K Jul 5 13:26 config_test.go
136
+
-rw-r--r-- 1 user group 963B Jul 5 13:26 contract.abi
137
+
-rw-r--r-- 1 user group 8.1K Jul 5 13:26 contract.go
138
+
-rw-r--r-- 1 user group 8.3K Jul 5 13:26 contract_test.go
139
+
-rw-r--r-- 1 user group 2.7K Jul 5 13:26 module.go
140
+
```
141
+
41
142
### Register Precompile
42
143
43
144
In `plugin/main.go` Subnet-EVM is already imported and ready to be Run from the main package. All you need to do is explicitly register your precompiles to Subnet-EVM in `plugin/main.go` and build it together with Subnet-EVM. Precompiles generated by `precompilegen` tool have a self-registering mechanism in their `module.go/init()` function. All you need to do is to force-import your precompile packprecompile package in `plugin/main.go`.
0 commit comments