# EVM

EVM chains like Ethereum, Polygon, Base etc support the following signature `kinds`:

* `Transaction`: unsigned transaction.
* `Message`: an arbitrary message.
* `Eip712`: typed structured data defined in [EIP-712](https://eips.ethereum.org/EIPS/eip-712).
* `Eip7702`: authorization tuple for type 4 set code transaction defined in [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702).

## Transaction

Signs an unsigned transaction.

| Field            | Description                                          | Type - Optional |
| ---------------- | ---------------------------------------------------- | --------------- |
| `blockchainKind` | `Evm`                                                | String          |
| `kind`           | `Transaction`                                        | String          |
| `transaction`    | The unsigned hex encoded transaction as shown below. | String          |

```shell
{
  "blockchainKind": "Evm",
  "kind": "Transaction",
  "transaction": "0x02e783aa36a71503850d40e49def82520894e5a2ebc128e262ab1e3bd02bffbe16911adfbffb0180c0"
}
```

### Typescript Example with EthersJs <a href="#typescript-example" id="typescript-example"></a>

First install the Ethers JS. You can find the full documentation here: <https://docs.ethers.org/v6/>

Here a code sample to generate a signature via [the Dfns TypeScript SDK](https://github.com/dfns/dfns-sdk-ts):

```typescript
import { parseUnits, Transaction } from 'ethers'

const walletId = 'wa-6lbfv-9esgj-88s80c0qsih0a393'

const transaction = Transaction.from({
  to: '0xa238b6008Bc2FBd9E386A5d4784511980cE504Cd',
  value: '1',
  gasLimit: '21000',
  maxPriorityFeePerGas: parseUnits('5', 'gwei'),
  maxFeePerGas: parseUnits('20', 'gwei'),
  nonce: 3,
  type: 2,
  chainId: 11155111,
})

const res = await dfnsClient.wallets.generateSignature({
  walletId,
  body: { kind: 'Transaction', transaction: transaction.unsignedSerialized },
})
```

## Message

Signs an arbitrary hex encoded message.

| Field            | Description                       | Type - Optional |
| ---------------- | --------------------------------- | --------------- |
| `blockchainKind` | `Evm`                             | String          |
| `kind`           | `Message`                         | String          |
| `message`        | An arbitrary hex encoded message. | String          |

```shell
{
  "blockchainKind": "Evm",
  "kind": "Message",
  "message": "0x49206c6f76652044666e73"
}
```

## EIP-712 TypedData

Signs a typed structured data defined in [EIP-712](https://eips.ethereum.org/EIPS/eip-712).

| Field            | Description                 | Type - Optional                 |
| ---------------- | --------------------------- | ------------------------------- |
| `blockchainKind` | `Evm`                       | String                          |
| `kind`           | `Eip712`                    | String                          |
| `types`          | Type definitions.           | Map\<String, TypedDataField\[]> |
| `domain`         | Domain separator.           | Eip712Domain                    |
| `message`        | Structured message to sign. | Object                          |

#### TypedDataField

| Field  | Description | Type - Optional |
| ------ | ----------- | --------------- |
| `name` | Field name. | String          |
| `type` | Field type. | String          |

#### Eip712Domain

| Field               | Description                                                 | Type - Optional |
| ------------------- | ----------------------------------------------------------- | --------------- |
| `name`              | Name of the signing domain.                                 | String          |
| `version`           | Current major version of the signing domain.                | String          |
| `chainId`           | Chain ID.                                                   | Integer         |
| `verifyingContract` | The address of the contract that will verify the signature. | String          |
| `salt`              | 32-byte value as a last-resort domain separator.            | String          |

```shell
{
  "blockchainKind": "Evm",
  "kind": "Eip712",
  "types": {
    "Person": [
      { "name": "name", "type": "string" },
      { "name": "wallet", "type": "address" }
    ],
    "Mail": [
      { "name": "from", "type": "Person" },
      { "name": "to", "type": "Person" },
      { "name": "contents", "type": "string" }
    ]
  },
  "domain": {
    "name": "Ether Mail",
    "version": "1",
    "chainId": 1,
    "verifyingContract": "0x1b352de7a926ebd1bf52194dab487c2cb0793a9b",
    "salt": "0xf2d857f4a3edcb9b78b4d503bfe733db1e3f6cdc2b7971ee739626c97e86a558"
  },
  "message": {
    "from": {
      "name": "Chris",
      "wallet": "0x00e3495cf6af59008f22ffaf32d4c92ac33dac47"
    },
    "to": {
      "name": "Bob",
      "wallet": "0xcc0ee1a1c5e788b61916c8f1c96c960f9a9d3db7"
    },
    "contents": "Hello, Bob!"
  }
}
```

## EIP-7702 Authorization

Signs an authorization tuple for type 4 set code transaction defined in [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702).

| Field            | Description                                                        | Type - Optional |
| ---------------- | ------------------------------------------------------------------ | --------------- |
| `blockchainKind` | `Evm`                                                              | String          |
| `kind`           | `Eip7702`                                                          | String          |
| `chainId`        | Chain ID.                                                          | Integer         |
| `address`        | The address of the contract the signer's EOA will be delegated to. | String          |
| `nonce`          | The current nonce of the signer EOA.                               | Integer         |

```json
{
  "blockchainKind": "Evm",
  "kind": "Eip7702",
  "chainId": 1,
  "address": "0xcea43594f38316f0e01c161d8dabde0a07a1f512",
  "nonce": 0
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-legacy.dfns.co/d/api-docs/keys/generate-signature/evm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
