Function Signature
Future<String> sendTransaction({
required String chainId,
required String to,
String? from,
String? value,
String? data,
String? gas,
String? gasPrice,
String? maxFeePerGas,
String? maxPriorityFeePerGas,
String? nonce,
String? idempotencyKey,
})
Description
Signs and broadcasts a transaction to the network with full control over all transaction parameters.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
chainId | String | Yes | The chain ID in CAIP-2 format |
to | String | Yes | The recipient/contract address |
from | String | No | Sender address (defaults to wallet address) |
value | String | No | Value in wei (hex string) |
data | String | No | Transaction data (hex string) |
gas | String | No | Gas limit (hex string) |
gasPrice | String | No | Gas price for legacy transactions (hex) |
maxFeePerGas | String | No | Max fee per gas for EIP-1559 (hex) |
maxPriorityFeePerGas | String | No | Max priority fee for EIP-1559 (hex) |
nonce | String | No | Transaction nonce (hex string) |
idempotencyKey | String? | No | Key that stops Portal from broadcasting the same transaction twice. Generate one with generateIdempotencyKey. See Idempotency keys. |
Returns
String - The transaction hash.
Example
import 'package:portal_flutter/portal_flutter.dart';
final portal = Portal();
// Simple ETH transfer
final txHash = await portal.sendTransaction(
chainId: 'eip155:1',
to: '0xRecipientAddress',
value: '0xDE0B6B3A7640000', // 1 ETH in wei (hex)
);
print('Transaction hash: $txHash');
EIP-1559 Transaction
final txHash = await portal.sendTransaction(
chainId: 'eip155:1',
to: '0xRecipientAddress',
value: '0x10',
maxFeePerGas: '0x3B9ACA00',
maxPriorityFeePerGas: '0x3B9ACA00',
);
Contract Interaction
final txHash = await portal.sendTransaction(
chainId: 'eip155:1',
to: '0xContractAddress',
data: '0xa9059cbb...', // Encoded function call
gas: '0x5208',
);
With an Idempotency Key
// Store this key with the pending transfer, and reuse it only to retry this transfer
final idempotencyKey = generateIdempotencyKey();
final txHash = await portal.sendTransaction(
chainId: 'eip155:1',
to: '0xRecipientAddress',
value: '0x10',
idempotencyKey: idempotencyKey,
);
Errors
| Code | Description |
|---|---|
NOT_INITIALIZED | Portal was not initialized |
TRANSACTION_FAILED | The transaction failed |
INSUFFICIENT_FUNDS | Not enough funds for gas or value |
INVALID_IDEMPOTENCY_KEY | idempotencyKey is empty, longer than 255 characters, or contains a character outside A-Z a-z 0-9 . _ ~ - |
IDEMPOTENT_*, IDEMPOTENCY_KEY_REUSED | Portal rejected the transaction because of its idempotencyKey. See Handle a rejection |