# Getting Started with RedStone X

In the fast-moving world of decentralized finance (DeFi), front-running is a persistent threat. RedStone X provides an innovative solution through its deferred execution pattern, enabling highly efficient and secure DeFi projects.&#x20;

## Deferred Execution Mechanism&#x20;

RedStone X separates transaction execution into two steps:

1. Initiating the Transaction Users first record their intent to interact with the protocol on-chain, without specifying details like price. This prevents front-runners from manipulating oracle prices.
2. Deferred Price-Based Execution In the next block, any entity can submit the price data to the blockchain. The price is verified programmatically based on protocol rules. This price is then used to finalize the transaction. Benefits This deferred execution approach offers two major advantages:

* Robust front-running protection, securing user funds and preventing arbitrage.
* Transactions leveraging verified, tamper-proof price data, ensuring fairness. Implementing&#x20;

## Deferred Execution&#x20;

To leverage RedStone X's benefits, follow these steps:

1.  For price-sensitive transactions, have your contracts separate request and execution phases.For example, in a native to stablecoin swap, the request would record key data like amount and user, and notify keepers:

    ```
    function initiateSwap() external payable {
      bytes32 requestHash = calculateRequestHash(
        msg.value, 
        msg.sender,
        block.number

      );
      swapRequests[requestHash] = true;
      emit NewOracleDataRequest(msg.value, msg.sender, block.number);
    }
    ```
2. Deploy a Keeper Service A dedicated keeper service retrieves price info and triggers execution. This automation ensures smooth deferred execution. With RedStone X's deferred execution model, developers can build secure and efficient DeFi systems, shielded from front-running exploits. By separating request from execution based on verified data, RedStone X unlocks a new era of resilient DeFi.

For the full code example and more insights, visit the [official RedStone X documentation](https://docs.redstone.finance/docs/smart-contract-devs/get-started/redstone-x).

