logoAcademy

Registering Your Precompile

Learn how to register your precompile.

The next step in developing our precompile is to register it with precompile-evm. For this, 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. As a first step, register the SHA-256 precompile. Your updated file should look like the following:

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"
)
 
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)
}

Now, register the MD5 precompile using the same format as for the SHA-256 precompile. Add the necessary line to main.go so that we can use the MD5 precompile.

On this page

No Headings