Transfer NFTs Between Layer 1 and Layer 2

·

In the rapidly evolving world of blockchain technology, Layer 2 (L2) scaling solutions have emerged as a powerful answer to the high fees and slow transaction speeds of Ethereum’s mainnet (Layer 1). One of the most practical applications of L2 networks is the seamless transfer of digital assets—especially NFTs—between chains. This guide walks you through how to transfer NFTs between Layer 1 and Layer 2 using the RedSonic API with TypeScript, covering deposit, transfer, and withdrawal processes.

Whether you're building an NFT marketplace, a gaming platform, or simply managing your digital collectibles, understanding cross-layer NFT operations is essential for optimizing cost, speed, and user experience.


Understanding Layer 1 and Layer 2 for NFTs

Before diving into code, it’s important to understand the distinction between Layer 1 and Layer 2 blockchains:

NFTs often start on L1 but can be moved to L2 for efficient trading or gameplay interactions. To fully utilize both layers, users must know how to deposit, transfer, and withdraw NFTs across them.

👉 Learn how to optimize NFT transactions across chains with advanced tools


Setting Up the Development Environment

To follow along with this tutorial, ensure you have Node.js and npm installed. Clone the official example repository:

git clone https://github.com/reddio-com/Tutorial-Examples.git
cd Tutorial-Examples/ERC721-transfer-tutorial-example
npm install

After installing dependencies, start the development server:

npm run dev

This will launch a local web application interface where you can interact with the wallet and execute NFT operations.


Testing Parameters: Using Testnet NFTs

For development and testing purposes, we’ll use the REDDIO721 contract deployed on the Sepolia testnet. This NFT collection is used in RedSonic’s public demo and allows developers to simulate real-world scenarios without spending real funds.

The contract address for REDDIO721 on Sepolia is:

0x941661bd1134dc7cc3d107bf006b8631f6e65ad5

You can acquire test NFTs by visiting RedSonic’s demo account page and clicking “Get test assets.”


Connect Your Wallet

To interact with Ethereum and RedSonic’s API, you need to connect a Web3 wallet. In this example, we use MetaMask.

Here’s how to implement wallet connection in TypeScript:

async function connectToWallet() {
  if (typeof window !== 'undefined') {
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    
    // Switch to Sepolia testnet (chain ID: 11155111)
    await provider.send("wallet_switchEthereumChain", [
      { chainId: ethers.utils.hexValue(11155111) },
    ]);

    await provider.send('eth_requestAccounts', []);
    const signer = provider.getSigner();
    const ethAddress = await signer.getAddress();

    const reddio = new Reddio({
      provider,
      env: 'test',
    });
    setReddio(reddio);

    const { privateKey, publicKey } = await reddio.keypair.generateFromEthSignature();
    setEventValue({ ...eventValue, ethAddress, starkKey: publicKey, privateKey });
  }
}

Once connected:

This ensures secure authentication across both layers using a single wallet.

👉 Start experimenting with cross-chain NFT transfers today


Deposit: Move NFTs from Layer 1 to Layer 2

To use your NFTs on Layer 2, you must first deposit them from Ethereum mainnet (or testnet). This process involves two steps:

  1. Approve the NFT contract to allow RedSonic to manage your token.
  2. Initiate the deposit via the depositERC721 API.
async function depositNFT() {
  const { starkKey, contractAddress, tokenId } = eventValue;

  if (reddio !== null) {
    const transaction = await reddio.erc721.approve({
      tokenAddress: contractAddress,
      tokenId,
    });

    await transaction?.wait();

    await reddio.apis.depositERC721({
      starkKey,
      tokenAddress: contractAddress,
      tokenId,
    });
  }
}

After clicking "Deposit," MetaMask will prompt you to confirm:

Once confirmed, your NFT is bridged to L2. You can verify the balance using RedSonic’s balance-checking tools.


Transfer: Send NFTs Between Layer 2 Users

With your NFT now on Layer 2, you can transfer it quickly and cheaply to another user’s Stark key.

async function transferNFT() {
  const { starkKey, contractAddress, tokenId, privateKey, receiver } = eventValue;

  if (reddio) {
    const result = await reddio.apis.transfer({
      starkKey,
      privateKey,
      contractAddress,
      tokenId,
      type: "ERC721",
      receiver,
    });

    console.log(result);
  }
}

This operation occurs entirely on L2—no gas fees on Ethereum—and typically completes within seconds. The recipient can then check their updated balance instantly.


Withdraw: Bring NFTs Back to Layer 1

When you want to bring your NFT back to Ethereum (mainnet or testnet), initiate a withdrawal. This is a two-step process due to security validations on L2:

Step 1: Initiate Withdrawal from Layer 2

async function withdrawNFTFromL2() {
  const { starkKey, contractAddress, tokenId, privateKey, receiver } = eventValue;
  
  if (reddio) {
    const { data } = await reddio.apis.withdrawalFromL2({
      starkKey,
      privateKey,
      receiver,
      type: "ERC721",
      contractAddress,
      tokenId,
    });
    console.log(data);
  }
}

This action moves the NFT into a withdrawal queue. Due to fraud-proof windows in some L2 systems, this step usually takes about 4 hours.

You can monitor the status via RedSonic’s withdrawal status API.

Step 2: Finalize Withdrawal on Layer 1

After the waiting period, execute the second phase—finalizing the withdrawal on Ethereum. Refer to RedSonic’s JS SDK documentation for implementation details.

Once completed, the NFT appears in your Ethereum wallet.


Frequently Asked Questions

How long does it take to withdraw an NFT from Layer 2?

Withdrawals typically require a 4-hour validation window before assets can be claimed on Layer 1. This delay ensures security through fraud-proof mechanisms.

Can I transfer any ERC-721 NFT between layers?

Yes, as long as the L2 network supports the token standard and the contract is correctly integrated with the bridge (e.g., RedSonic), most ERC-721 NFTs can be transferred.

Is there a gas cost when transferring NFTs on Layer 2?

Transfers on Layer 2 are significantly cheaper than on Ethereum mainnet. Some networks even offer near-zero fees during testing phases.

What happens if I lose my Stark key?

Your Stark key is derived from your Ethereum signature. As long as you retain access to your wallet, you can regenerate the same key pair—no permanent loss occurs.

Do I need ETH on both layers?

Yes. You’ll need ETH on Layer 1 for deposits and withdrawals (gas fees), and Layer 2 ETH for paying L2 transaction fees (if applicable).

Can I automate batch transfers?

Yes, using scripts with proper error handling and nonce management, developers can automate multiple transfers or withdrawals programmatically.

👉 Discover more about secure and scalable NFT operations


Core Keywords

By mastering these workflows, developers and users alike can unlock faster, cheaper, and more flexible NFT experiences across Ethereum’s layered ecosystem.