logoAcademy

Register Your Precompile

Learn how to register your precompile.

The next step in developing our precompile is to register it with precompile-evm. Take a look at plugin/main.go. You should see the following file:

plugin/main.go
// (c) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
 
package main
 
import (
    "fmt"
 
    "github.com/ava-labs/avalanchego/version"
    "github.com/ava-labs/subnet-evm/plugin/evm"
    "github.com/ava-labs/subnet-evm/plugin/runner"
 
    // Each precompile generated by the precompilegen tool has a self-registering init function
    // that registers the precompile with the subnet-evm. Importing the precompile package here
    // will cause the precompile to be registered with the subnet-evm.
    // ADD YOUR PRECOMPILE HERE
    //_ "github.com/ava-labs/precompile-evm/{yourprecompilepkg}"
)
 
const Version = "v0.1.4"
 
func main() {
    versionString := fmt.Sprintf("Precompile-EVM/%s Avalanche L1-EVM/%s [AvalancheGo=%s, rpcchainvm=%d]", Version, evm.Version, version.Current, version.RPCChainVMProtocol)
    runner.Run(versionString)
}

As of now, we do not have any precompile registered. To reigster a precompile, simply import the precompile package in the plugin/main.go file.

plugin/main.go
// (c) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
 
package main
 
import (
    "fmt"
 
    "github.com/ava-labs/avalanchego/version"
    "github.com/ava-labs/subnet-evm/plugin/evm"
    "github.com/ava-labs/subnet-evm/plugin/runner"
 
    // Each precompile generated by the precompilegen tool has a self-registering init function
    // that registers the precompile with the subnet-evm. Importing the precompile package here
    // will cause the precompile to be registered with the subnet-evm.
    _ "github.com/ava-labs/precompile-evm/sha256"
    _ "github.com/ava-labs/precompile-evm/md5" 
)
 
const Version = "v0.1.4"
 
func main() {
    versionString := fmt.Sprintf("Precompile-EVM/%s Avalanche L1-EVM/%s [AvalancheGo=%s, rpcchainvm=%d]", Version, evm.Version, version.Current, version.RPCChainVMProtocol)
    runner.Run(versionString)
}

On this page

No Headings