TransactionRequest.toRpc
Converts a TransactionRequest.TransactionRequest
to a TransactionRequest.Rpc
.
Imports
import { TransactionRequest } from 'ox'
Examples
import { TransactionRequest, Value } from 'ox'
const request = TransactionRequest.toRpc({
to: '0x0000000000000000000000000000000000000000',
value: Value.fromEther('0.01'),
})
Using with a Provider
You can use Provider.from
to instantiate an EIP-1193 Provider and send a transaction to the Wallet using the eth_sendTransaction
method.
import 'ox/window'
import { Provider, TransactionRequest, Value } from 'ox'
const provider = Provider.from(window.ethereum!)
const request = TransactionRequest.toRpc({
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: Value.fromEther('0.01'),
})
const hash = await provider.request({
method: 'eth_sendTransaction',
params: [request],
})
Definition
function toRpc(
request: TransactionRequest,
): Rpc
Source: src/core/TransactionRequest.ts
Parameters
request
- Type:
TransactionRequest
The request to convert.
request.accessList
- Type:
readonly { address: abitype_Address; storageKeys: readonly 0x${string}[]; }[]
- Optional
EIP-2930 Access List.
request.authorizationList
- Type:
readonly { address: abitype_Address; chainId: numberType; nonce: bigintType; r: bigintType; s: bigintType; yParity: numberType; }[]
- Optional
EIP-7702 Authorization List.
request.blobVersionedHashes
- Type:
readonly 0x${string}[]
- Optional
Versioned hashes of blobs to be included in the transaction.
request.blobs
- Type:
readonly 0x${string}[]
- Optional
Raw blob data.
request.chainId
- Type:
numberType
- Optional
EIP-155 Chain ID.
request.data
- Type:
0x${string}
- Optional
Contract code or a hashed method call with encoded args
request.from
- Type:
Address.Address | undefined
- Optional
Sender of the transaction.
request.gas
- Type:
bigintType
- Optional
Gas provided for transaction execution
request.gasPrice
- Type:
bigintType
- Optional
Base fee per gas.
request.input
- Type:
0x${string}
- Optional
request.maxFeePerBlobGas
- Type:
bigintType
- Optional
Maximum total fee per gas sender is willing to pay for blob gas (in wei).
request.maxFeePerGas
- Type:
bigintType
- Optional
Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas).
request.maxPriorityFeePerGas
- Type:
bigintType
- Optional
Max priority fee per gas (in wei).
request.nonce
- Type:
bigintType
- Optional
Unique number identifying this transaction
request.to
- Type:
Address.Address | null | undefined
- Optional
Transaction recipient
request.type
- Type:
type
- Optional
Transaction type
request.value
- Type:
bigintType
- Optional
Value in wei sent with this transaction
Return Type
An RPC request.
Rpc