# associate-evm-key (/docs/tx/associate-evm-key)

Links an Ethereum-style (H160) address to the signing hotkey on one subnet,
letting EVM-side activity be attributed to that neuron. Signed by the
hotkey, and additionally proven by the EVM key itself: `signature` must
be an EIP-191 personal-sign signature by the EVM key over the message
`hotkey_pubkey (32 bytes) ++ keccak_256(scale(block_number))`, where the
block number is SCALE-encoded (u64 little-endian). Use
`bittensor.evm.transactions.association_proof` to produce it (it needs
the EVM private key); a wrong message, block number, or key makes the
chain reject the call. Prerequisites: the hotkey must be registered on
`netuid` (else HotKeyNotRegisteredInSubNet) and have an owning coldkey,
and re-association is rate-limited to once per 7,200 blocks (\~1 day) per
neuron.

| Signer   | Origin                                 | Pallet          | Wraps                                                                                               |
| -------- | -------------------------------------- | --------------- | --------------------------------------------------------------------------------------------------- |
| `hotkey` | signed account (pallet role may apply) | SubtensorModule | [`SubtensorModule.associate_evm_key`](/code/pallets/subtensor/src/macros/dispatches.rs#L1573-L1587) |

## Parameters [#parameters]

| Parameter      | Type    | Required | Description                                                                                                                                                                       |
| -------------- | ------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `netuid`       | integer | yes      | Subnet on which the EVM key association is recorded.                                                                                                                              |
| `evm_key`      | string  | yes      | EVM address to link to the hotkey, as 0x-prefixed H160 hex.                                                                                                                       |
| `block_number` | integer | yes      | Block number the signature was produced for; part of the signed message.                                                                                                          |
| `signature`    | string  | yes      | The EVM key's ownership proof, as 0x-prefixed hex: an EIP-191 personal-sign signature over the hotkey public key concatenated with keccak\_256 of the SCALE-encoded block number. |

Address parameters (`--hotkey`, `--coldkey`, `--dest`, ...) accept a raw ss58
address, an address-book or proxy-book name, or a local wallet/hotkey name.

## CLI [#cli]

Preview with `--dry-run` (shows fee, effects, and policy result without
submitting), then submit:

```bash
btcli tx associate-evm-key \
  --netuid <int> \
  --evm-key <value> \
  --block-number <int> \
  --signature <value> --dry-run
btcli tx associate-evm-key \
  --netuid <int> \
  --evm-key <value> \
  --block-number <int> \
  --signature <value> -w my_coldkey
```

## Python [#python]

```python
import bittensor as bt
from bittensor.wallet import Wallet

wallet = Wallet(name="my_coldkey", hotkey="my_hotkey")
intent = bt.AssociateEvmKey(netuid=1, evm_key="...", block_number=0, signature="...")

sub = bt.Subtensor()
plan = sub.plan(intent, wallet)   # fee, effects, policy — no submission
result = sub.execute(intent, wallet)
if not result.success:
    print(result.error.code, result.error.remediation)
```

(`bt.Subtensor` is also the async client — `async with bt.Subtensor() as client:`
— see [The client](/docs/concepts/client).) Or build the intent by op name, as
an agent would:

```python
result = sub.execute_tool("associate_evm_key", {...}, wallet)
```

## On-chain implementation [#on-chain-implementation]

`SubtensorModule.associate_evm_key` — [`pallets/subtensor/src/macros/dispatches.rs#L1579`](/code/pallets/subtensor/src/macros/dispatches.rs#L1573-L1587):

```rust
#[pallet::call_index(93)]
#[pallet::weight((
    <T as crate::pallet::Config>::WeightInfo::associate_evm_key(),
    DispatchClass::Normal,
    Pays::No
))]
pub fn associate_evm_key(
    origin: OriginFor<T>,
    netuid: NetUid,
    evm_key: H160,
    block_number: u64,
    signature: Signature,
) -> DispatchResult {
    Self::do_associate_evm_key(origin, netuid, evm_key, block_number, signature)
}
```

Delegates to [`do_associate_evm_key`](/code/pallets/subtensor/src/utils/evm.rs#L46).

Every file is browsable under [/code](/code) exactly as built into the runtime, or as plain text under `/code/raw/<path>` (index: [`/code/index.json`](/code/index.json)).
