eth_sendTransaction
Instructs the Wallet to broadcast a transaction to the network.
Request
type Request = {
method: 'eth_sendTransaction',
params: [{
/** Target chain ID. Defaults to the connected chain. */
chainId?: `0x${string}`,
/** Calldata to send with the transaction. */
data?: `0x${string}`,
/** Address of the sender. */
from: `0x${string}`,
/** Address of the recipient. */
to: `0x${string}`,
/** Value to transfer. Defaults to 0. */
value?: `0x${string}`,
}]
}
Response
Transaction hash.
type Response = `0x${string}`
Example
import { Porto } from 'porto'
const { provider } = Porto.create()
const hash = await provider.request({
method: 'eth_sendTransaction',
params: [{
from: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
to: '0xcafebabecafebabecafebabecafebabecafebabe',
value: '0x1',
}],
})
Mint ERC20 Tokens
The example below demonstrates minting 100 EXP on the Odyssey testnet.
import { encodeFunctionData, parseAbi, parseEther } from 'viem'
const [account] = await provider.request({
method: 'eth_accounts',
})
const hash = await provider.request({
method: 'eth_sendTransaction',
params: [{
from: account,
to: '0x706aa5c8e5cc2c67da21ee220718f6f6b154e75c',
data: encodeFunctionData({
abi: parseAbi([
'function mint(address, uint256)',
]),
functionName: 'mint',
args: [account, parseEther('100')],
}),
}],
})