Unichain Docs

Integrating Flashblocks

Learn how to integrate Flashblocks for lightning-fast transaction confirmations on Unichain, with preconfirmations in just 200 milliseconds.

Coming Soon: Flashblocks on Unichain

Experience lightning-fast transaction confirmations on Unichain with Flashblocks. Get preconfirmations in just 200 milliseconds—designed for maximally efficient DeFi and seamless user experiences.

What are Flashblocks?

Flashblocks enable ultra-fast transaction confirmations on Unichain by providing preconfirmations - instant signals that arrive before the next block is finalized. Instead of waiting up to 1 second for block confirmation, users receive transaction feedback in just 200 milliseconds.

Key Benefits

  • 5x Faster Confirmations: Reduce perceived latency from 1 seconds to 200ms
  • Seamless Integration: Works with many existing Ethereum JSON-RPC methods using the pending tag
  • No Protocol Changes: Built as an "out-of-protocol" extension that doesn't modify Unichain's core consensus
  • Incremental Updates: Receive partial block updates as transactions are processed
  • Backward Compatible: Existing applications continue to work without modifications

How It Works

Flashblocks work by streaming partial block updates called "Flashblocks" every 200 milliseconds. Each Flashblock contains:

  • Transaction Batches: Groups of transactions processed together
  • State Updates: Account balances, nonces, and storage changes
  • Execution Results: Transaction receipts and status information

These updates are propagated to RPC providers who maintain a preconfirmation cache, allowing applications to query the latest state immediately.

Perfect For

  • DeFi Applications: Instant swap confirmations and liquidity updates
  • Marketplaces: Immediate purchase confirmations
  • Payment Systems: Instant payment verification
  • Apps: User experiences become without the normal crypto wait times

Integrating Flashblocks (Apps)

Flashblocks integration is designed to be seamless for application developers. Most existing applications can benefit from Flashblocks with minimal code changes.

RPC Endpoints

Use these Flashblocks-aware RPC endpoints for development and testing:

NetworkURL
Unichain Mainnethttps://mainnet.unichain.org
Unichain Sepoliahttps://sepolia.unichain.org

Production Note: These public endpoints are rate-limited. For production applications, see our node providers that support Flashblocks below.

Supported RPC Methods

The following standard Ethereum JSON-RPC methods support Flashblocks data when using the pending tag:

eth_getBlockByNumber

Get the latest Flashblock with all preconfirmed transactions:

curl https://sepolia.unichain.org \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getBlockByNumber",
    "params": ["pending", true],
    "id": 1
  }'

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0x1234",
    "hash": "0x0", // Placeholder during preconfirmation
    "transactions": [...], // All preconfirmed transactions
    "stateRoot": "0x...",
    "gasUsed": "0x...",
    "timestamp": "0x..."
  }
}

eth_call

Use the preconfirmation cache state to return the call result:

curl https://sepolia.unichain.org \
  -X POST \
  -H "Content-Type: application/json" \
  -d `{
    "jsonrpc": "2.0",
    "method": "eth_call",
    "params": [{"to": "0x...", "data": "0x..."}, "pending"],  // Transaction call object and block parameter
    "id": 1
  }`

eth_getTransactionReceipt

Get receipts for preconfirmed transactions immediately. Notice, no pending tag is needed:

curl https://sepolia.unichain.org \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionReceipt",
    "params": ["0x..."],
    "id": 1
  }'

eth_getBalance

Get the latest balance including preconfirmed transactions:

curl https://sepolia.unichain.org \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getBalance",
    "params": ["0x742d35Cc6634C0532925a3b8D23bb7e67E1b6e0", "pending"],
    "id": 1
  }'

eth_getTransactionCount

Get the latest nonce for sending transactions:

curl https://sepolia.unichain.org \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionCount",
    "params": ["0x742d35Cc6634C0532925a3b8D23bb7e67E1b6e0", "pending"],
    "id": 1
  }'

Library Integration

Ethers.js

import { ethers } from 'ethers';
 
const provider = new ethers.JsonRpcProvider(
  "https://sepolia.unichain.org"
);
 
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
 
async function sendFastTransaction() {
  const tx = {
    to: "0x742d35Cc6634C0532925a3b8D23bb7e67E1b6e0",
    value: ethers.parseEther("0.001"),
  };
 
  const submissionTime = Date.now();
  const transaction = await wallet.sendTransaction(tx);
  
  console.log(`Transaction hash: ${transaction.hash}`);
  
  // Wait for preconfirmation (0 confirmations)
  await transaction.wait(0);
  
  const confirmTime = Date.now();
  console.log(`Preconfirmed in ${confirmTime - submissionTime}ms`);
}

Viem

import { createWalletClient, createPublicClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { unichain } from 'viem/chains';
 
const account = privateKeyToAccount(`0x${process.env.PRIVATE_KEY}`);
 
const walletClient = createWalletClient({
  account,
  chain: unichain,
  transport: http('https://sepolia.unichain.org'),
});
 
const publicClient = createPublicClient({
  chain: unichain,
  transport: http('https://sepolia.unichain.org'),
});
 
async function sendFastTransaction() {
  const submissionTime = Date.now();
  
  const hash = await walletClient.sendTransaction({
    to: '0x742d35Cc6634C0532925a3b8D23bb7e67E1b6e0',
    value: parseEther('0.001'),
  });
  
  // Wait for preconfirmation
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
  
  const confirmTime = Date.now();
  console.log(`Preconfirmed in ${confirmTime - submissionTime}ms`);
}

Integrating Flashblocks (Wallet Providers)

Wallet providers can integrate Flashblocks to provide instant transaction feedback to users.

User Experience Benefits

  • Instant Confirmations: Show users their transaction succeeded immediately
  • Real-time Balance Updates: Update balances as soon as transactions are preconfirmed
  • Reduced Anxiety: Users don't wait wondering if their transaction went through
  • Better UX: Feels like Web2 application responsiveness

Implementation Guidelines

Transaction Status Updates

class WalletProvider {
  async sendTransaction(tx) {
    const hash = await this.submitTransaction(tx);
    
    // Show immediate pending status
    this.updateTransactionStatus(hash, 'pending');
    
    // Wait for preconfirmation
    try {
      const receipt = await this.waitForPreconfirmation(hash);
      this.updateTransactionStatus(hash, 'preconfirmed');
      
      // Optional: Wait for full confirmation
      await this.waitForFullConfirmation(hash);
      this.updateTransactionStatus(hash, 'confirmed');
    } catch (error) {
      this.updateTransactionStatus(hash, 'failed');
    }
  }
  
  async waitForPreconfirmation(hash) {
    return new Promise((resolve, reject) => {
      const checkReceipt = async () => {
        try {
          const receipt = await this.provider.getTransactionReceipt(hash);
          if (receipt) {
            resolve(receipt);
          } else {
            setTimeout(checkReceipt, 100); // Check every 100ms
          }
        } catch (error) {
          reject(error);
        }
      };
      checkReceipt();
    });
  }
}

Balance Updates

class WalletProvider {
  async getBalance(address) {
    // Get preconfirmed balance
    const balance = await this.provider.getBalance(address, 'pending');
    return balance;
  }
  
  async subscribeToBalanceUpdates(address, callback) {
    // Poll for balance changes (or use WebSocket)
    setInterval(async () => {
      const newBalance = await this.getBalance(address);
      callback(newBalance);
    }, 200); // Check every 200ms
  }
}

Using Flashblocks with a Node Provider

For production use cases, consider using a Node provider that is supporting Flashblocks on Unichain!

Getting Help

Join our Discord and look for the Unichain channel.

Last updated on

On this page