Skip to main content

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,
})

Description

Signs and broadcasts a transaction to the network with full control over all transaction parameters.

Parameters

ParameterTypeRequiredDescription
chainIdStringYesThe chain ID in CAIP-2 format
toStringYesThe recipient/contract address
fromStringNoSender address (defaults to wallet address)
valueStringNoValue in wei (hex string)
dataStringNoTransaction data (hex string)
gasStringNoGas limit (hex string)
gasPriceStringNoGas price for legacy transactions (hex)
maxFeePerGasStringNoMax fee per gas for EIP-1559 (hex)
maxPriorityFeePerGasStringNoMax priority fee for EIP-1559 (hex)
nonceStringNoTransaction nonce (hex string)

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',
);

Errors

CodeDescription
NOT_INITIALIZEDPortal was not initialized
TRANSACTION_FAILEDThe transaction failed
INSUFFICIENT_FUNDSNot enough funds for gas or value