Handling gas and contract logic
on a chain with block-level
sharding
Handling gas and contract logic on a chain with block-level sharding
PROJECT OVERVIEW
PROJECT OVERVIEW
Following the integration of NEAR’s L2 Aurora, XP.NETWORK was ready to handle a more technically complex task: looping in NEAR itself, a blockchain with a very unusual sharded structure. A keystone of our solution is an innovative cross-chain fee oracle.
near.org

Why integrate NEAR?
NEAR is an L1 blockchain that is very different from Ethereum, BNB Chain, Polygon, and the rest of EVM chains you’re used to. Thanks to its sharded architecture, NEAR’s L1 is extremely scalable and can deliver up to 100,000 TPS while keeping transaction fees below $0.01. At the same time, NEAR does support L2s like Aurora, which provides EVM compatibility.
Another thing that we at XP.NETWORK love about NEAR is its NFT ecosystem. It does have its punks and apes, sure, but there is also a lot of unique art, such as Mr. Brown, Freaky Elves, and Bonehedz. And even in the middle of the bear market, new interesting collections keep launching.


The leading marketplace on NEAR, Paras.id, has great UI and its own token, which can be staked to earn 10-11% APY. You can even earn PARAS by staking NFTs.
For creators, NEAR offers perpetual royalties that are automatically enforced across marketplaces and even wallet-to-wallet transactions. Royalties can be customized – for example, split between several artists or DAO members.
Apart from Paras, we should mention Mintbase – a marketplace where you can build your own programmable NFTs, minters, and modules.
You might ask: if NEAR is so fast and cheap and has great NFTs, why aren’t more people familiar with it? The answer, as it often is with non-EVM chains, is having to try something different, to exit one’s comfort zone. NEAR doesn’t support MetaMask, so you need to register a brand-new NEAR wallet and – preferably – create a subaccount with an easy-to-remember name.
As developers, we also have to go beyond our comfort zone sometimes. Below we’ll tell you about some of the challenges we had to overcome to connect NEAR to XP.NETWORK – our powerful multichain NFT bridge.
XP.NETWORK and NEAR: meeting the challenge of block-level sharding
Rephrasing Tolstoy’s Anna Karenina, all EVM chains are alike, but every non-EVM chain is innovative in its own way. This fully applies to NEAR with its many ingenious structural solutions.
A few months ago, XP.NETWORK integrated Aurora, the EVM-compatible Layer-2 blockchain that is part of the NEAR ecosystem. Following the success of that integration, we received a second grant from the NEAR foundation to add the Layer-1 to our NFT bridge. It turned out to be an exciting and complicated task, primarily due to block sharding and how it affects gas.
Sharding is most commonly understood splitting the main chain into several subchains that can process transactions in parallel. MultiversX (former Elrond) uses sharding, together with Polkadot and Kusama; Ethereum will eventually switch to it.
However, NEAR’s approach is different, and its sharding technology has its own name, Nightshade. Instead of sharding the blockchain, it shards the blockchain state and transaction processing itself. It keeps the chain intact, so there’s no need for a beacon chain, like in Ethereum.
Since sharding happens at the level of each block, a single transaction can be split across several blocks. Cross-shard communication is very fast, so a split transaction is finalized within 1-2 seconds.
The complication from the bridging standpoint is that the gas for that transaction has to be supplied separately for each part. This is quite a challenge when you need to allow bridge users to send NFTs to NEAR and pay for gas in the currency of the departure chain. We also have to make sure that the storage or reverting logic for each part of the transaction is handled properly.
Introducing the fee oracle
The core of our solution is the new XP.NETWORK fee oracle. It delivers correct information about the gas fees on the destination chain, so that we can make sure that the bridging transaction succeeds.
On top of that, the oracle further secures user assets and makes the bridge more robust - all that in an efficient and cheap way.
Here’s what XP.NETWORK CTO Dima Brook has to say about it:
The fee oracle constantly monitors token prices off-chain. When a user initiates an NFT transfer, the oracle estimates the cost at destination, converts the required amount of departure chain tokens, and submits the transaction to the bridge.
The bridge then compares the oracle’s fee estimate to what’s actually expected, and if the values are the same or if the user paid more, the bridging transaction goes through. But if the fee oracle’s estimate is lower than the real fee, the transaction reverts and the user gets the money back.
The fee oracle protects both the user and the bridge. If you make a mistake and pay less in fees, your NFT won’t get stuck, but also bridge validators won’t have tokens drained from their accounts due to bad calls with low fees.
The fee oracle can be used with any chain that is supported by XP.NETWORK, but NEAR is the first network we have implemented it for. In our future posts and case studies, we’ll tell you more about how the fee oracle works.


Our NEAR integration is almost ready, so soon you’ll be able to send your NearNauts, Mr. Browns, and other NFTs from NEAR to 25+ EVM and non-EVM chains – cheaply and securely. Of course, it works the other way around, too: for the first time it will become possible to list unique NFT art from all supported chains on Paras and other NEAR marketplaces.
Integrating non-EVM chains into bridges is hard, but it’s also crucial for the ecosystem. That’s why XP.NETWORK has already received 17 grants from different blockchains to build a single interconnected, blockchain-agnostic NFT space.