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
+101Lines changed: 101 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,10 +35,111 @@ To get a comprehensive introduction to Precompile-EVM, take the Avalanche Academ
35
35
36
36
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
43
+
```
44
+
45
+
### Checkout the `hello-world-example` Branch
46
+
47
+
```zsh
48
+
git checkout hello-world-example
49
+
50
+
branch 'hello-world-example'set up to track 'origin/hello-world-example'.
51
+
Switched to a new branch 'hello-world-example'
52
+
```
53
+
54
+
### Install NodeJS Dependencies
55
+
56
+
First you have to `cd contracts/` and run `npm install` to get the dependencies.
57
+
58
+
```zsh
59
+
cd contracts/ # change directory to the contracts/ directory
60
+
npm install
61
+
```
62
+
63
+
### Create a New Contract
64
+
65
+
`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.
66
+
67
+
Copy the existing `IHelloWorld.sol` interface to a new file called `IHolaMundo.sol`.
68
+
69
+
```zsh
70
+
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.
101
+
-`--include-path path`
102
+
- 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.
103
+
-`--output-dir path`
104
+
- If given, creates one file per output component and contract/file at the specified directory.
105
+
-`--overwrite`
106
+
- Overwrite existing files (used together with `--output-dir`).
107
+
108
+
```zsh
109
+
cd contracts/ # change directory to the contracts/ directory
Compiler run successful. Artifact(s) can be found in directory "abis".
113
+
```
114
+
38
115
### Generate Precompile Files
39
116
40
117
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.
41
118
119
+
```zsh
120
+
cd .. # change directory back to the root directory of the repo
Confirm that the new `holamundo/` directory has the appropriate files.
130
+
131
+
```zsh
132
+
ls -lh helloworld
133
+
134
+
-rw-r--r-- 1 user group 2.3K Jul 5 13:26 README.md
135
+
-rw-r--r-- 1 user group 2.3K Jul 5 13:26 config.go
136
+
-rw-r--r-- 1 user group 2.8K Jul 5 13:26 config_test.go
137
+
-rw-r--r-- 1 user group 963B Jul 5 13:26 contract.abi
138
+
-rw-r--r-- 1 user group 8.1K Jul 5 13:26 contract.go
139
+
-rw-r--r-- 1 user group 8.3K Jul 5 13:26 contract_test.go
140
+
-rw-r--r-- 1 user group 2.7K Jul 5 13:26 module.go
141
+
```
142
+
42
143
### Register Precompile
43
144
44
145
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