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 |
externalId | A unique ID from your system. It can be leveraged to be used as an idempotency key. (read more here) | String (optional) |
Hex String
{
"kind": "Transaction",
"transaction": "0x02e783aa36a71503850d40e49def82520894e5a2ebc128e262ab1e3bd02bffbe16911adfbffb0180c0"
}
Typescript Example with Ethers
First install the Ethers JS. You can find the full documentation here
Here a code sample to broadcast a transaction via the Dfns TypeScript SDK:
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
Field | Description | Type - Optional |
---|
type | Ethereum transaction type. 0 for legacy transaction; 2 for EIP-1559 transaction; 4 for EIP-7702 transaction. Default is 2 if undefined. | Integer (optional) |
to | The destination address or target contract. Leave undefined when the transaction is a contract deployment. | String (optional) |
value | The amount of native tokens to transfer in minimum denomination. | String (optional) |
data | ABI encoded function call data in hex format. Can also be the encoded smart contract data when the transaction is a contract deployment. | String (optional) |
nonce | 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. | Integer or String (optional) |
gasLimit | The maximum amount of gas that can be spent for executing the transaction. If omitted, it will be calculated automatically. | String (optional) |
gasPrice | The amount of per unit gas. Only valid for a type 0 legacy transaction. If omitted, it will be calculated automatically. | String (optional) |
maxFeePerGas | 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. | String (optional) |
maxPriorityFeePerGas | 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. | String (optional) |
authorizationList | 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. | Authorization (optional) |
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 |
{
"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.
Can only be used with a fee sponsor. Unsponsored user operations are not supported.
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) | String |
externalId | A unique ID from your system. It can be leveraged to be used as an idempotency key. (read more here) | 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) |
{
"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.