qed-builders

We are a software development company with a focus on web3 technologies and offices in Timisoara, Romania. Read our stories to find out more.

Bridge Cardano NFTs to Sandbox

Vlad Temian
qed-builders
Published in
6 min readMar 18, 2024

--

Sandbox NFT Avatars

NFT collections increasingly recognize the value of offering this new utility to their users. Particularly for vibrant communities, it provides a unique opportunity for owners to gather in a virtual world, fostering the culture, community spirit, and sense of belonging that make these collections unique.

The voxelization of an NFT is a complex and intricate process that necessitates the collaboration of artists, voxel modeling, and an entire pipeline.

This collective effort makes the process not just a task but a remarkable journey. For the current scope, we’ll take care of the ownership system and how an NFT is associated with an avatar.

Bridging the Gap across Chains

Sandbox has an internal system called a Blockchain listener that assists us in assigning ownership of a specific token.

ClayNation, the first Cardano NFT collection inside Sandbox.
ClayNation, the first Cardano NFT collection inside Sandbox.

This system ingests blocks and transactions for a given list of contracts and decodes all events for each transaction. It processes the events if they are of interest, which, in this case, is the Transfer event since avatars are pretty generic on ERC721 contracts.

Once it detects a Transfer event, we determine which wallet and account to associate the avatar with. Internally, it links the asset to the owner’s in-game account and browser-based avatar manager.

This system is designed to be simple, easy to develop on top of, extend, and understand, providing you with the confidence and reassurance you need. However, it currently only supports Ethereum networks, specifically Mainnet and Polygon.

Blockchain listener

But there are famous and notable NFT projects on other chains, some non-EVM. We are actively exploring the potential for expansion to these networks, which requires considerable effort to adapt the blockchain listener and our onboarding experience.

QED and the ClayNation team built a system based on emitting Transfer events to solve this issue. Thus, there’s no need to transfer the NFTs from other chains to Mainnet or Polygon. It is enough to build a system to map the non-EVM wallet with a Mainnet/Polygon wallet and a smart contract that produces EVM Transfer events for each non-EVM transfer.

Let’s look at ClayNation, one of the biggest names in NFTs on Cardano. Once we voxelized their avatars and established a mapping for their tokens and avatars, they started building the bridge. For it, they have 3 main components:

  • Wallet mapper — a dApp in which the owner maps their Cardano wallet with their Polygon wallet.
  • Polygon smart contract is — a smart contract that emits transfer events.
  • Off-chain syncher — an off-chain mechanism that listens to Cardano events and calls the smart contract to replicate those events on-chain.

The first component, the wallet mapper, is a small DApp that ensures the ClayNation NFT’s owner has a specific Polygon wallet.

The user must sign a transaction with a Cardano and Polygon wallet. This mapping is saved off-chain and will be used to create the transfer events. All transfer events will use this Polygon wallet, allowing our blockchain listener to associate the correct owner with the 3D avatar.

Custom DApp built by ClayNation

For the second component, we help the ClayNation team and provide a basic implementation of a smart contract that emits transfer events. This small smart contract has 4 main functions:

  • emitERC721TransferEvent — emits 1 ERC721 Transfer event.
  • emitERC721TransferEventBatch — emits as many ERC721 Transfer events as passed to it.
  • emitERC1155TransferSingleEvent — emits 1 ERC1155 TransferSingle event, possibly useful for optimization.
  • emitERC1155TransferBatchEvent — emits 1 ERC1155 TransferBatch event, possibly useful for optimization.

The bridge’s foundational architecture is built upon four essential functions, effectively negating the requirement for data storage on the Polygon side, as the original tokens are securely held on Cardano.

Clay Nation NFT Collection

This strategic approach streamlines the synchronization process by circumventing the need to mint tokens on the Polygon blockchain and burn them from Cardano and vice versa.

The system is designed to operate without token ownership, enabling entirely off-chain processing and significantly lowering operational costs.

To further enhance efficiency and reduce expenses, the bridge employs an innovative method of event aggregation.

By using the emitERC721TransferEventBatch function to process 100 events collectively, the system achieves substantial savings in gas costs. Given a gas price of 150.3 GWEI and the prevailing MATIC rates, sending a single event stands at roughly 0.00841279 MATIC, translating to about $0.025 for 100 events.

Therefore, the expense incurred for a batch of 100 events is remarkably low, at just 2.5 cents, underscoring the system’s cost-effectiveness.

The smart contract implementation is open-source and can be found on our GitHub repository.

EventBridger Smart Contract emits transfer events processed by BlockchainListener.

We need an off-chain synchronization mechanism based on Cardano on-chain transfers to link everything together. This mechanism will call the EventBridger smart contract, emitting Transfer events for specific tokens and wallets.

The system starts by fetching the latest processed block information from its database and queries the blockchain for all subsequent blocks using blockfrost.io.

For each block, it then lists all transactions, focusing on those with relevant assets, and creates a mapping of transaction inputs to outputs, detailing sender and receiver information along with asset IDs.

OffChain Syncher bridging events from Cardano to Polygon.

Next, the script checks if any transactions involve verified wallets and if there’s a change in asset ownership. If so, it updates the internal database and queues to emit events as needed. It also regularly reviews the state of verified wallets, updates balances, and adds new emit events to the queue based on recent transactions and new wallet verifications.

Finally, the system periodically processes the emit event queue, automatically emitting events via a contract on Polygon, ensuring the database remains in sync with the latest blockchain activity.

Clay Nation NFT Avatar in the Sandbox

Conclusion

Our collaboration with Sandbox and Clay Nation has created a pathway for Cardano NFTs in a lively 3D voxel world.

This has given us a glimpse of the immense potential of making NFTs more adaptable and interconnected across different blockchain platforms.

What’s particularly exciting about this project is its strong foundation, which can be modified to include other non-EVM blockchains. This means that the techniques and technologies we have developed here — from the blockchain listener to the smart contracts and off-chain synchronizers — are not just a one-time solution but a model that can be customized to bring together diverse blockchain communities.

--

--

qed-builders
qed-builders

Published in qed-builders

We are a software development company with a focus on web3 technologies and offices in Timisoara, Romania. Read our stories to find out more.

Vlad Temian
Vlad Temian

Written by Vlad Temian

Systems care-taker. Love to make the order within chaos and under pressure.