EVM: Broadcast Transaction

EVM chains like Ethereum, Polygon, BSC, Arbitrum, etc support the use of templates to broadcast transactions. Select the following based on the template kind:

  • Evm: Use this template if you don't want to worry about gas parameters.

  • Eip1559: Use this template to interact with chains that support the new EIP-1559 gas standard (most chains do now).

  • Transaction: Use this template to just pass in the fully serialized EVM transaction (formatted and encoded using eg Ethersjs library)

EMV Template

Request fieldsRequired - TypeDescription

kind

Required - String

Evm

to

Required - String

Blockchain address of target contract or payee.

value

Optional (Required only if making a payment) - String (representing a integer eg "1000000")

Amount of the native currency to transfer denominated in WEI.

data

Optional - String

Encoded hex string indicating which function in the smart contract to call with which parameters. Can also be an entire encoded contract in the case of contract deployment.

nonce

Optional - Integer

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 maxFeePerGas to "overwrite" existing transactions in the mempool.

Sample request body

{
    "kind": "Evm",
    "to": "0x00fb58432ef9d418bf6688bcf0a226d2fcaa18e2",
    "data": "0x40d097c3000000000000000000000000d2f77f85a50cdd650ca562f3a180284e1d5b4934",
}

200 response example

{
  "id": "tx-hpq5n-4p9s9-xxxxxxxxxxxxxxxx",
  "walletId": "wa-1f04s-lqc9q-xxxxxxxxxxxxxxxx",
  "network": "EthereumSepolia",
  "requester": {
    "userId": "us-3v1ag-v6b36-xxxxxxxxxxxxxxxx",
    "tokenId": "to-7mkkj-c831n-xxxxxxxxxxxxxxxx",
    "appId": "ap-24vva-92s32-xxxxxxxxxxxxxxxx"
  },
  "requestBody": {
    "kind": "Eip1559",
    "to": "0x00fb58432ef9d418bf6688bcf0a226d2fcaa18e2",
    "data": "0x40d097c3000000000000000000000000d2f77f85a50cdd650ca562f3a180284e1d5b4934",
    "maxFeePerGas": "1626000000000",
    "maxPriorityFeePerGas": "1332000000000"
  },
  "dateRequested": "2023-05-08T19:27:04.680Z",
  "dateBroadcasted": "2024-01-10T21:19:58.225Z",
  "status": "Broadcasted"
}

EIP-1559 Template

Use this template to adjust the maxFeePerGas and maxPriorityFeePerGas of an EIP-1559 type-2 transaction. Keep in mind that not all EVM compatible chains support this standard.

Request fieldsRequired - TypeDescription

kind

Required - String

Eip1559

to

Required - String

Blockchain address of target contract or payee.

value

Optional (Required if making a payment) - String (representing an integer eg "1000000")

Amount of the native currency to transfer denominated in WEI.

data

Optional - String

Encoded hex string indicating which function in the smart contract to call with which parameters. Can also be an entire encoded contract in the case of contract deployment.

nonce

Optional - Integer

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 maxFeePerGas to "overwrite" existing transactions in the mempool.

gasLimit

Optional - String (representing an Integer)

The maximum amount of gas that can be spent for executing the transaction. If omitted, it will be calculated automatically.

maxPriorityFeePerGas

Optional - String (representing an Integer)

The maximum amount of gas to be included as a tip to the validator. If omitted, it will be calculated automatically.

maxFeePerGas

Optional - String (representing an Integer)

The maximum amount for gas willing to be paid for the transaction. If omitted, it will be calculated automatically.

Sample request body

{
    "kind": "Eip1559",
    "to": "0x00fb58432ef9d418bf6688bcf0a226d2fcaa18e2",
    "data": "0x40d097c3000000000000000000000000d2f77f85a50cdd650ca562f3a180284e1d5b4934",
    "maxFeePerGas": "1626000000000",
    "maxPriorityFeePerGas": "1332000000000"
}

200 response example

{
  "id": "tx-hpq5n-4p9s9-xxxxxxxxxxxxxxxx",
  "walletId": "wa-1f04s-lqc9q-xxxxxxxxxxxxxxxx",
  "network": "EthereumSepolia",
  "requester": {
    "userId": "us-3v1ag-v6b36-xxxxxxxxxxxxxxxx",
    "tokenId": "to-7mkkj-c831n-xxxxxxxxxxxxxxxx",
    "appId": "ap-24vva-92s32-xxxxxxxxxxxxxxxx"
  },
  "requestBody": {
    "kind": "Eip1559",
    "to": "0x00fb58432ef9d418bf6688bcf0a226d2fcaa18e2",
    "data": "0x40d097c3000000000000000000000000d2f77f85a50cdd650ca562f3a180284e1d5b4934",
    "maxFeePerGas": "1626000000000",
    "maxPriorityFeePerGas": "1332000000000"
  },
  "dateRequested": "2023-05-08T19:27:04.680Z",
  "dateBroadcasted": "2024-01-10T21:19:58.225Z",
  "status": "Broadcasted"
}

Raw Transaction with EthersJS

You can also format the transaction using Ethers JS and the Dfns SDK:

Request fieldsRequired - TypeDescription

kind

Required - String

For EVM, always "Transaction"

transaction

Required - String

The transaction encoded by EthersJS as shown below

Sample request body

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

200 Response Example

{
    "id": "tx-3p6n9-tdrn2-xxxxxxxxxxxxxxxx",
    "walletId": "wa-19lns-o74qn-xxxxxxxxxxxxxxxx",
    "network": "EthereumSepolia",
    "requester": {
        "userId": "us-3v1ag-v6b36-xxxxxxxxxxxxxxxx",
        "tokenId": "to-7mkkj-c831n-xxxxxxxxxxxxxxxx",
        "appId": "ap-C3H2-H7-xxxxxxxxxxxxxxxx"
    },
    "requestBody": {
        "kind": "Transaction",
        "transaction": "0x02e783aa36a71503850d40e49def82520894e5a2ebc128e262ab1e3bd02bffbe16911adfbffb0180c0"
    },
    "status": "Broadcasted",
    "txHash": "0x86b092a7fde26cca7fa49350d6d9244fb1f772d30c15aed48decea11fa68531f",
    "dateRequested": "2024-01-10T19:02:11.615Z",
    "dateBroadcasted": "2024-01-10T19:02:12.873Z"
}

EthersJS SDK Sample:

See the full EthersJS docs here: https://docs.ethers.org/v6/

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

Last updated