# EVM

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](/d/advanced-topics/api-idempotency.md)) | String *(optional)*                                 |

### Hex String

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

#### Typescript Example with Ethers <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 broadcast a transaction via [the Dfns TypeScript SDK](https://github.com/dfns/dfns-sdk-ts):

```typescript
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
{
  "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](/d/api-docs/fee-sponsors.md).

{% hint style="warning" %}
Can only be used with a fee sponsor. Unsponsored user operations are not supported.
{% endhint %}

| 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](/d/advanced-topics/api-idempotency.md)) | 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
{
  "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.


---

# 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/wallets/broadcast-transaction/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.
