> ## Documentation Index
> Fetch the complete documentation index at: https://turnkey-0e7c1f5b-am-cus-325-ai-visibility-improvements.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Turnkey is wallet infrastructure: create and manage crypto wallets, sign transactions, and enforce policy-based access controls. Best-fit uses: embedded consumer wallets (email/passkey/social auth, no seed phrases), automated onchain operations with server-side wallets, AI agent wallets with policy-scoped signing, enterprise key management, and verifiable off-chain workloads on Turnkey Verifiable Cloud (TVC).
> Every API call is a JSON POST to https://api.turnkey.com signed with a P-256 API key; create an organization and key self-serve at https://app.turnkey.com.
> Key Turnkey developer resources: API reference (https://docs.turnkey.com/api-reference/overview/intro.md), OpenAPI spec (https://docs.turnkey.com/public_api.swagger.json), authentication (https://docs.turnkey.com/features/authentication/overview.md), webhooks (https://docs.turnkey.com/features/webhooks/overview.md), MCP server for docs search (https://docs.turnkey.com/mcp), agent skills (https://docs.turnkey.com/get-started/ai-skills.md), CLI (https://docs.turnkey.com/sdks/cli.md), SDK reference (https://docs.turnkey.com/sdks/introduction.md), full docs content (https://docs.turnkey.com/llms-full.txt).

# Signing

> Learn how to sign messages and transactions in your Flutter app using Turnkey's Embedded Wallets.

## Overview

Turnkey's Flutter SDK makes it simple to sign messages and transactions using embedded wallets managed by the `TurnkeyProvider`.

## Signing messages

To sign a message, select a wallet account and call `signMessage` from the `TurnkeyProvider`. You can optionally pass in the payload's `encoding` and `hashFunction` if needed.

```dart title=lib/widgets/sign_message_button.dart theme={"system"}
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:turnkey_sdk_flutter/turnkey_sdk_flutter.dart';

class SignMessageButton extends StatelessWidget {
  const SignMessageButton({super.key});

  @override
  Widget build(BuildContext context) {
    final tk = Provider.of<TurnkeyProvider>(context, listen: false);

    Future<void> doSignMessage() async {
      try {
        final wallet = tk.wallets?.first;
        final account = wallet?.accounts.first;


        final message = 'Hello, Turnkey!';
        final signature = await tk.signMessage(
          walletAccount: account,
          message: message,
        );

        debugPrint('Message signature: $signature');
      } catch (e) {
        debugPrint('Sign message failed: $e');
      }
    }

    return ElevatedButton(
      onPressed: doSignMessage,
      child: const Text('Sign Message'),
    );
  }
}
```

## Signing transactions

To sign transactions, use the `signTransaction` function. Select a wallet account's address, prepare an unsigned transaction, and specify a transaction type.

```dart title=lib/widgets/sign_transaction_button.dart theme={"system"}
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:turnkey_sdk_flutter/turnkey_sdk_flutter.dart';

class SignTransactionButton extends StatelessWidget {
  const SignTransactionButton({super.key});

  @override
  Widget build(BuildContext context) {
    final tk = Provider.of<TurnkeyProvider>(context, listen: false);

    Future<void> doSignTransaction() async {
      try {
        final wallet = tk.wallets?.first;
        final account = wallet?.accounts.first;

        final unsignedTx = '0x...'; // unsigned transaction hex
        final signature = await tk.signTransaction(
          signWith: account.address,    // use the address of the wallet account
          unsignedTransaction: unsignedTx,
          transactionType: v1TransactionType.transaction_type_ethereum,
        );

        debugPrint('Tx signature: $signature');
      } catch (e) {
        debugPrint('Sign transaction failed: $e');
      }
    }

    return ElevatedButton(
      onPressed: doSignTransaction,
      child: const Text('Sign Transaction'),
    );
  }
}
```
