logoAcademy

Setting Config Key and Contract Address

Learn how to set ConfigKey and ContractAddress

Config Key

The precompile config key is used to configure the precompile in the chainConfig. It's set in the module.go file of our precompile.

The generator chooses an initial value that should be sufficient for many cases. For the sha256 precompile this is:

sha256/module.go
// ConfigKey is the key used in json config files to specify this precompile precompileconfig.
// must be unique across all precompiles.
const ConfigKey = "sha256Config"

This key is used for each precompile in the chainConfig to set the activation timestamp of the precompile.

.devcontainer/genesis-example.json
{
  "config": {
    "chainId": 99999,
    // ...
    "feeConfig": {
      "gasLimit": 20000000,
      "minBaseFee": 1000000000,
      "targetGas": 100000000,
      "baseFeeChangeDenominator": 48,
      "minBlockGasCost": 0,
      "maxBlockGasCost": 10000000,
      "targetBlockRate": 2,
      "blockGasCostStep": 500000
    },
 
    "sha256Config": { 
      "blockTimestamp": 0
    }
 
    // Add the md5Config here
 
  },
  "alloc": {
    "8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC": {
      "balance": "0x52B7D2DCC80CD2E4000000"
    }
  },
  "nonce": "0x0",
  // ...
}

Contract Address

Each precompile has a unique contract address we can use to call it. This is the address we used earlier to instantiate the precompile in our solidity code or in remix when we interacted with the precompile.

sha256/module.go
// ContractAddress is the defined address of the precompile contract.
// This should be unique across all precompile contracts.
// See precompile/registry/registry.go for registered precompile contracts and more information.
 
var ContractAddress = common.HexToAddress("0x0300000000000000000000000000000000000001") 

The 0x01 range is reserved for precompiles added by Ethereum.

The 0x02 range is reserved for precompiles provided by Avalanche.

The 0x03 range is reserved for custom precompiles.

Setting ConfigKey and ContractAddress for MD5 Precompile

Set a custom precompile address in the md5/module.go file.

Updated:

On this page

Edit on Github