# EVM Chain

The EVM (Ethereum Virtual Machine) chain implementation in Signet.js provides support for all EVM-compatible networks, including Ethereum, Binance Smart Chain, Polygon, Arbitrum, and more.

## Overview

The EVM implementation allows you to:

* Derive addresses and public keys
* Check balances
* Prepare, sign, and broadcast transactions
* Sign messages (EIP-191)
* Sign typed data (EIP-712)

## Complete Transaction Example

Below is a complete example of sending a transaction on an EVM chain using Signet.js:

```ts twoslash
import { chainAdapters } from 'signet.js'
// [!include ~/snippets/code/evm/contract.ts]

const evm = new chainAdapters.evm.EVM({
  publicClient,
  contract: evmChainSigContract,
})

const path = 'eth'
const predecessorId = walletClient.account.address
const keyVersion = 1

const { address: from, publicKey } = await evm.deriveAddressAndPublicKey(
  predecessorId,
  path,
  keyVersion
)

const { balance, decimals } = await evm.getBalance(from)

const { transaction, hashesToSign } = await evm.prepareTransactionForSigning({
  from: from as `0x${string}`,
  to: '0x4174678c78fEaFd778c1ff319D5D326701449b25',
  value: 1n, // Amount in wei (1 wei in this example)
})

const rsvSignature = await evmChainSigContract.sign({
  payload: hashesToSign[0],
  path,
  key_version: keyVersion,
})

const tx = evm.finalizeTransactionSigning({
  transaction,
  rsvSignatures: [rsvSignature],
})

const txHash = await evm.broadcastTx(tx)
```

### Supported Networks

You can use any EVM-compatible network by providing the appropriate client:

```ts twoslash
// [!include ~/snippets/code/contract.ts]
// ---cut---
import { chainAdapters } from 'signet.js'
import { polygon, bsc, mainnet } from 'viem/chains'

// Ethereum Mainnet
const clientEthereum = createPublicClient({
  chain: mainnet,
  transport: http(),
})

const ethereumChain = new chainAdapters.evm.EVM({
  publicClient: clientEthereum,
  contract: evmChainSigContract,
})

// Polygon (Matic)
const clientPolygon = createPublicClient({
  chain: polygon,
  transport: http(),
})

const polygonChain = new chainAdapters.evm.EVM({
  publicClient: clientPolygon,
  contract: evmChainSigContract,
})

// Binance Smart Chain
const clientBSC = createPublicClient({
  chain: bsc,
  transport: http(),
})

const bscChain = new chainAdapters.evm.EVM({
  publicClient: clientBSC,
  contract: evmChainSigContract,
})
```

## Working Examples

See the test suite for complete, runnable examples:

* [Unit tests](https://github.com/sig-net/signet.js/blob/main/tests/unit/evm/EVM.test.ts) — message signing, typed data signing, and transaction signing
* [E2E tests](https://github.com/sig-net/signet.js/blob/main/tests/e2e/evm/EVM.e2e.test.ts) — MPC signing on Sepolia, broadcast on local hardhat
