Skip to main content

Function Signature

Future<PortalProviderResponse> request({
  required String chainId,
  required String method,
  required List<Object?> params,
  String? signatureApprovalMemo,
})

Description

Make a generic JSON-RPC request to the blockchain. This allows you to call any RPC method supported by the chain.

Parameters

ParameterTypeRequiredDescription
chainIdStringYesThe chain ID in CAIP-2 format
methodStringYesThe JSON-RPC method name
paramsList<Object?>YesThe method parameters
signatureApprovalMemoStringNoOptional memo for signing operations

Returns

PortalProviderResponse - An object containing:
PropertyTypeDescription
resultdynamicThe result of the RPC call
errordynamicError information if the call failed

Example

import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Get account balance
final response = await portal.request(
  chainId: 'eip155:1',
  method: 'eth_getBalance',
  params: ['0xYourAddress', 'latest'],
);

print('Balance: ${response.result}');

Common RPC Methods

// Get block number
final blockResponse = await portal.request(
  chainId: 'eip155:1',
  method: 'eth_blockNumber',
  params: [],
);

// Estimate gas
final gasResponse = await portal.request(
  chainId: 'eip155:1',
  method: 'eth_estimateGas',
  params: [{
    'from': '0xFromAddress',
    'to': '0xToAddress',
    'value': '0x10',
  }],
);

// Call contract (read-only)
final callResponse = await portal.request(
  chainId: 'eip155:1',
  method: 'eth_call',
  params: [{
    'to': '0xContractAddress',
    'data': '0x70a08231...', // balanceOf encoded
  }, 'latest'],
);

Signing Methods

// personal_sign
final signResponse = await portal.request(
  chainId: 'eip155:1',
  method: 'personal_sign',
  params: ['0x48656c6c6f', '0xYourAddress'],
  signatureApprovalMemo: 'Sign hello message',
);

// eth_sendTransaction
final txResponse = await portal.request(
  chainId: 'eip155:1',
  method: 'eth_sendTransaction',
  params: [{
    'from': '0xYourAddress',
    'to': '0xRecipientAddress',
    'value': '0x10',
  }],
);

Errors

CodeDescription
NOT_INITIALIZEDPortal was not initialized
RPC_ERRORThe RPC call returned an error
NETWORK_ERRORNetwork connectivity issue