logoAcademy

ConfigKey, ContractAddress, and Genesis

Learn how to set ConfigKey, ContractAddress, and update the genesis configuration.

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. In our case:

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

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

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 sha256 precompile.

md5/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("{ASUITABLEHEXADDRESS}") // SET A SUITABLE HEX ADDRESS HERE

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.

Lets set our contract address to 0x0300000000000000000000000000000000000002

md5/module.go
var ContractAddress = common.HexToAddress("0x0300000000000000000000000000000000000002") // SET A SUITABLE HEX ADDRESS HERE

Update Genesis Configuration

Now that the ConfigKey and ContractAddress are set, we need to update the genesis configuration to register the precompile.

.devcontainer/genesis-example.json
{
  "config": {
    "chainId": 99999,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "muirGlacierBlock": 0,
    "subnetEVMTimestamp": 0,
    "feeConfig": {
      "gasLimit": 20000000,
      "minBaseFee": 1000000000,
      "targetGas": 100000000,
      "baseFeeChangeDenominator": 48,
      "minBlockGasCost": 0,
      "maxBlockGasCost": 10000000,
      "targetBlockRate": 2,
      "blockGasCostStep": 500000
    },
    "sha256Config": {
      "blockTimestamp": 0
    },
    "md5Config": { 
      "blockTimestamp": 0
    } 
  },
  "alloc": {
    "8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC": {
      "balance": "0x52B7D2DCC80CD2E4000000"
    }
  },
  "nonce": "0x0",
  "timestamp": "0x0",
  "extraData": "0x00",
  "gasLimit": "0x1312D00",
  "difficulty": "0x0",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

On this page