> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portalhq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Sign a transaction

> This example shows how the Portal Provider interacts with the blockchain.

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.

```dart theme={null}
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');
```

<Note>
  Ensure you have set the gateway URL correctly with [Infura](https://www.infura.io/) or [Alchemy](https://www.alchemy.com/) when you initialize the portal class.
</Note>

### Typed Data Signing (EIP-712)

For signing structured data according to the EIP-712 standard:

```dart theme={null}
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:

```dart theme={null}
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');
```

<Note>
  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.
</Note>

## Sending Transactions

### Using sendTransaction

For full control over transaction parameters:

```dart theme={null}
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:

```dart theme={null}
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:

```dart theme={null}
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

```dart theme={null}
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:

```dart theme={null}
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**

* [signMessage function reference](../reference/signmessage)
* [rawSign function reference](../reference/rawsign)
* [sendTransaction function reference](../reference/sendtransaction)
* [request function reference](../reference/request)
