Skip to main content
This example shows how the Portal Provider interacts with the blockchain.

Signing Messages

Personal Sign

The signMessage method uses the personal_sign RPC method which prepends the standard Ethereum message prefix before signing.
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Sign a message on Ethereum mainnet
final chainId = 'eip155:1';
final message = 'Hello, Portal!';

final signature = await portal.signMessage(
  chainId: chainId,
  message: message,
);

print('Signature: $signature');
Ensure you have set the gateway URL correctly with Infura or Alchemy when you initialize the portal class.

Typed Data Signing (EIP-712)

For signing structured data according to the EIP-712 standard:
import 'package:portal_flutter/portal_flutter.dart';
import 'dart:convert';

final portal = Portal();

final chainId = 'eip155:1';

// EIP-712 typed data structure
final typedData = jsonEncode({
  'types': {
    'EIP712Domain': [
      {'name': 'name', 'type': 'string'},
      {'name': 'version', 'type': 'string'},
      {'name': 'chainId', 'type': 'uint256'},
    ],
    'Message': [
      {'name': 'content', 'type': 'string'},
    ],
  },
  'primaryType': 'Message',
  'domain': {
    'name': 'Example App',
    'version': '1',
    'chainId': 1,
  },
  'message': {
    'content': 'Hello, Portal!',
  },
});

final signature = await portal.signTypedData(
  chainId: chainId,
  typedData: typedData,
);

print('EIP-712 Signature: $signature');

Raw Sign

For signing raw data without any prefix:
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Message must be hex-encoded
// "test" in hex is "74657374"
final hexMessage = '74657374';

final signature = await portal.rawSign(
  chainId: 'eip155:1',
  message: hexMessage,
  signatureApprovalMemo: 'Signing test message', // Optional
);

print('Raw signature: $signature');
Raw sign does not add any prefix to the message. Use this for signing raw data or when working with chains that don’t use Ethereum’s message prefix.

Sending Transactions

Using sendTransaction

For full control over transaction parameters:
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Monad Testnet
final chainId = 'eip155:10143';

// Send a transaction
final txHash = await portal.sendTransaction(
  chainId: chainId,
  to: '0xRecipientAddress',
  value: '0x10', // Value in wei (hex)
  data: '0x', // Optional contract data
);

print('Transaction hash: $txHash');

EIP-1559 Transactions

For EIP-1559 style transactions with priority fees:
final txHash = await portal.sendTransaction(
  chainId: 'eip155:1',
  to: '0xRecipientAddress',
  value: '0x10',
  maxFeePerGas: '0x3B9ACA00', // 1 Gwei
  maxPriorityFeePerGas: '0x3B9ACA00',
);

Generic Provider Requests

For any JSON-RPC method, use the request method:
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

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

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

Estimating Gas

final response = await portal.request(
  chainId: 'eip155:10143',
  method: 'eth_estimateGas',
  params: [{
    'from': '0xYourAddress',
    'to': '0xRecipientAddress',
    'value': '0x10',
  }],
);

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

Solana Signing

For Solana message signing, use the Solana chain ID:
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Solana Devnet
final chainId = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1';

final signature = await portal.signMessage(
  chainId: chainId,
  message: 'Hello from Solana!',
);

print('Solana signature: $signature');
Related Documentation