> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dfns.co/llms.txt
> Use this file to discover all available pages before exploring further.

# EVM chains

> Reference for EVM transaction and message payloads used with the Dfns sign and sign-and-broadcast endpoints across Ethereum and EVM-compatible chains.

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

* `Transaction`: broadcasts an EVM transaction.
* `UserOperations`: fee sponsorship of smart contract invocation.

## Transaction

Signs an unsigned transaction and broadcasts it to chain.

| Property      | Description                                                                                                                                                           | Type - Optional                                     |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| `kind`        | `Transaction`                                                                                                                                                         | String                                              |
| `transaction` | The unsigned transaction formatted as JSON or a serialized hex-encoded buffer as shown below.                                                                         | String or [EvmTransactionJson](#evmtransactionjson) |
| `externalId`  | A unique ID from your system. It can be leveraged to be used as an idempotency key. (read more [here](https://docs-legacy.dfns.co/d/advanced-topics/api-idempotency)) | String *(optional)*                                 |

### Hex String

```json theme={null}
{
  "kind": "Transaction",
  "transaction": "0x02e783aa36a71503850d40e49def82520894e5a2ebc128e262ab1e3bd02bffbe16911adfbffb0180c0"
}
```

#### Typescript Example with Ethers

First install the Ethers JS. You can find the full documentation [here](https://docs.ethers.org/v6/)

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

```typescript theme={null}
import { parseUnits, Transaction } from 'ethers'

const walletId = 'wa-6lbfv-9esgj-xxxxxxxxxxxxxxxx'

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.broadcastTransaction({
  walletId,
  body: { kind: 'Transaction', transaction: transaction.unsignedSerialized },
})
```

### EvmTransactionJson

<table data-full-width="false"><thead><tr><th>Field</th><th>Description</th><th>Type - Optional</th></tr></thead><tbody><tr><td><code>type</code></td><td>Ethereum transaction type. <code>0</code> for legacy transaction; <code>2</code> for EIP-1559 transaction; <code>4</code> for EIP-7702 transaction. Default is <code>2</code> if undefined.</td><td>Integer (optional)</td></tr><tr><td><code>to</code></td><td>The destination address or target contract. Leave undefined when the transaction is a contract deployment.</td><td>String (optional)</td></tr><tr><td><code>value</code></td><td>The amount of native tokens to transfer in minimum denomination.</td><td>String <em>(optional)</em></td></tr><tr><td><code>data</code></td><td>ABI encoded function call data in hex format. Can also be the encoded smart contract data when the transaction is a contract deployment.</td><td>String <em>(optional)</em></td></tr><tr><td><code>nonce</code></td><td>The transaction number to guarantee idempotency. If omitted, it will be provided automatically. Note the same nonce can be submitted multiple times with a higher <code>maxFeePerGas</code> to "overwrite" existing transactions in the mempool.</td><td>Integer or String <em>(optional)</em></td></tr><tr><td><code>gasLimit</code></td><td>The maximum amount of gas that can be spent for executing the transaction. If omitted, it will be calculated automatically.</td><td>String <em>(optional)</em></td></tr><tr><td><code>gasPrice</code></td><td>The amount of per unit gas. Only valid for a type 0 legacy transaction. If omitted, it will be calculated automatically.</td><td>String <em>(optional)</em></td></tr><tr><td><code>maxFeePerGas</code></td><td>The maximum amount of per unit gas willing to be paid for the transaction. Valid for type 2 and type 4 transactions. If omitted, it will be calculated automatically.</td><td>String <em>(optional)</em></td></tr><tr><td><code>maxPriorityFeePerGas</code></td><td>The maximum amount of per unit gas to be included as a tip to the validator. Valid for type 2 and type 4 transactions. If omitted, it will be calculated automatically.</td><td>String <em>(optional)</em></td></tr><tr><td><code>authorizationList</code></td><td>A list that indicates what code the signer of each authorization desires to execute in the context of their EOA. Only valid for type 4 transaction.</td><td><a href="#authorization">Authorization</a> <em>(optional)</em></td></tr></tbody></table>

### Authorization

| Field       | Description                                                        | Type - Optional |
| ----------- | ------------------------------------------------------------------ | --------------- |
| `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         |
| `signature` | The signer signature.                                              | String          |

```json theme={null}
{
  "kind": "Transaction",
  "transaction": {
    "to": "0x00fb58432ef9d418bf6688bcf0a226d2fcaa18e2",
    "data": "0x40d097c3000000000000000000000000d2f77f85a50cdd650ca562f3a180284e1d5b4934",
    "maxFeePerGas": "1626000000000",
    "maxPriorityFeePerGas": "1332000000000"
  }
}
```

## User Operations

Signs one or more user operations and broadcasts to chain using a sponsored transaction. Used for invoking arbitrary smart contract calls, including batch operations, with a [fee sponsor](https://docs-legacy.dfns.co/d/api-docs/fee-sponsors).

<Warning>
  Can only be used with a fee sponsor. Unsponsored user operations are not supported.
</Warning>

| Property         | Description                                                                                                                                                           | Type - Optional       |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| `kind`           | `UserOperations`                                                                                                                                                      | String                |
| `userOperations` | One or more user operations. See format below.                                                                                                                        | Array\<UserOperation> |
| `feeSponsorId`   | A fee sponsor id to sponsor the transaction fee by another wallet. (read more [here](https://docs.dfns.co/d/api-docs/fee-sponsors))                                   | String                |
| `externalId`     | A unique ID from your system. It can be leveraged to be used as an idempotency key. (read more [here](https://docs-legacy.dfns.co/d/advanced-topics/api-idempotency)) | String *(optional)*   |

### UserOperation

| Property | Description                                                      | Type - Optional     |
| -------- | ---------------------------------------------------------------- | ------------------- |
| `to`     | The destination address or target contract.                      | String              |
| `value`  | The amount of native tokens to transfer in minimum denomination. | String *(optional)* |
| `data`   | ABI encoded function call data in hex format.                    | String *(optional)* |

```json theme={null}
{
  "kind": "UserOperations",
  "userOperations": [
    {
      "to": "0xd964d741998edc275f3800eed113378a391951d9",
      "data": "0xa9059cbb000000000000000000000000d964d741998edc275f3800eed113378a391951d90000000000000000000000000000000000000000000000000000000000000001"
    }
  ],
  "feeSponsorId": "fs-5ercu-e9r9u-xxxxxxxxxxxxxxxx"
}
```

## EVM Templates

`Evm` and `Eip1559` kinds are deprecated. They only support type 2 transactions. Use the new JSON format with `Transaction` kind instead which has support for legacy and type 4 transactions.

## Complete examples

For complete working examples, see the SDK examples on GitHub:

**Ethers.js:**

* [Ethers.js v5](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/ethersjs/v5) - Integration with Ethers.js version 5
* [Ethers.js v6](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/ethersjs/v6) - Integration with Ethers.js version 6

**Viem:**

* [Alchemy AA gasless](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/viem/alchemy-aa-gasless) - Gasless transactions with Alchemy account abstraction
* [Biconomy AA gasless](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/viem/biconomy-aa-gasless) - Gasless transactions with Biconomy account abstraction
* [Multicall](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/viem/multicall) - Batch multiple calls in a single transaction
* [Pimlico AA gasless](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/viem/pimlico-aa-gasless) - Gasless transactions with Pimlico account abstraction
* [ZeroDev AA gasless](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/viem/zerodev-aa-gasless) - Gasless transactions with ZeroDev account abstraction
