LogoLogo
  • Welcome to Element
  • Spotlight
    • Getting Started
      • How to trade NFTs on Linea?
      • How do I create an Element account?
      • Create your profile
      • Install and connect your wallet
      • Basic information you need to know
      • How do creators set royalty?
      • Element Gas optimization method
      • FAQ
      • Key Features
        • Bulk offers
        • Multi-market Listing
        • NFT Cart
        • Make Collection Offer
        • Pro-Trade
        • Features
    • Buying NFTs
      • How to buy NFTS
      • Collection Offer
      • How to convert WETH
    • Selling NFTs
      • Listing an NFT for a Fixed Price
      • How do you manage your Listing
      • Accepting an offer on your NFT
    • Trading Fee
    • Drops on Element
    • What’s New in Element
      • Product Updates For 2023/11/3
      • Product Updates For 2023/10/20
      • Product Updates For 2023/10/13
      • Product Updates For 2022/08/19
      • Product Updates For 2022/08/24
      • Product Updates For 2022/08/25
      • Product Updates For 2022/09/04
      • Product Updates For 2022/09/09
      • Product Updates For 2022/09/14
      • Product Updates For 2022/09/24
      • Product Updates For 2022/09/27
      • Product Updates For 2022/10/15
      • Product Updates For 2022/11/14
      • Product Updates For 2022/12/05
      • Product Updates For 2023/01/04
      • Product Updates For 2023/01/09
      • Product Updates For 2023/01/15
      • Product Updates For 2023/01/22
      • Product Updates For 2023/01/22
  • Support
    • Drop Creator Support
      • Part 1: Deploy NFT Contract
      • Part 2: Edit Drop Settings
      • Part 3: Design Drop Page
      • Part 4: Edit Collection Information
      • Part 5: Publish Your Drop
      • Part 6: Upload and Reveal Items
    • Overview
    • Collection
      • Element Verification Service
      • Element Verified Creator Application
      • Tutorial for how to set collection profile and royalty
  • Event
    • Airdrop
      • Element Storm
        • Details of Invite Rebate(ETH only)
        • Details of listing reward
        • Details of Trading Rewards
      • Announcement on Quantity and Rules of ELE Air Drop
    • Activity
      • RGB++ NFT Trading Fest
      • Element Marketplace —「Say Hi to BTC Ordinals」
      • The Iliad Event
      • Element-BNBChain 2023 Adventure
      • “ELE World Cup” ---Qatar World Cup Prized Guess
      • Element Summer Rush! Element & AVAX NFT Trading Competition is on the way.
      • Element x Azuki listing activity starts. List your Azuki to get ELE rewards!
      • Element x .bit 4D/5D NFT Rewards Event
      • Element Lucky Draw is open now
      • Element Invitation Rebate Program 1.0
      • 'The Crown of Stark' LuckyDraw is coming!
      • Manta Treasure Cruise: Call of the Sea
      • Hi, Starks!
      • Holiday Mood with Element and Friends
      • The First Shoot: Element opBNB Market Live Event!
      • Element BTC Ordinals Market (beta) Live Now!
      • EPS Staking system is officially launched now! Claim starts at 0 am (UTC) daily
      • EPG Staking system is officially launched now! Claim starts at 0 am (UTC) daily
  • Branding
    • Brand & Logo
  • Join us
    • Hiring
  • Audit
    • Smart Contract
  • Developer
    • Contract Overview
    • Contract Governance
    • Deployed Contract
    • Audits
    • Order types
    • Public API
    • SDK
    • Gas Optimization
Powered by GitBook
On this page
  1. Developer

Gas Optimization

Gas Optimization

The least expensive Gas transaction contract

1.Element aggregator contract Gas optimization

Contract code optimization.

  • The main market contract addresses are constantly quantized to reduce the access to contract storage space.

  • Reduce dependencies on external Libray libraries and reduce cross-contract call function overhead.

  • Using Assembly Assembly code in core functions is more efficient than Solidity.

Intelligent routing algorithm.

1.The NFTs to be purchased are categorized by market, and the optimal smart contract entry function is selected through the intelligent routing algorithm. Each entry function is optimized to reduce loops, condition judgment, branch prediction, etc. Such as:

  • buyOneWithETH

  • batchBuyFromSingleMarketWithETH

  • batchBuyWithETH

  • buyOneWithERC20s

  • batchBuyWithERC20s

2.For native bulk purchase protocols, such as SeaPort and ElementEx, combine a single loop purchase of a single NFT into a single call for bulk purchase NFTs.

2.ElementEx Protocol transaction Protocol Gas optimization

In addition to supporting aggregators, Element also has its own separate trading protocol. ElementEx supports many advanced features and takes advantage of major trading protocols such as Seaport and 0xV4. The team has done a lot of optimization work from the macro architecture layer to the micro code layer. ElementEx achieves the lowest Gas among all transaction protocols.

Split contracts according to ERC721 and ERC1155 asset classes.

The ERC721/1155 STANDARD IS different AND THE TRADING logic is not completely the same. Most markets are processed in a single trading contract. Element Team considers that 98% of mainstream NFTS are ERC721 standard, we make the part of processing ERC721 transaction into independent contracts to achieve the optimal efficiency. ERC1155 also has separate contracts to process transactions.

Split the entry function into buy and sell directions.

Buying an NFT is BuyNow and selling an NFT is AcceptOffer. The logic of the two is different. Most markets process both buy and sell transactions in a single entry function, which is redundant. Through big data analysis, 80% of the transactions are active buying. For example, ElementEx makes buy entry buyERC721 and sell entry sellERC721. This reduces redundant judgment in dealmaking and reduces input parameters.

Split entry functions according to basic and advanced features.

ElementEx contract supports many advanced features such as ETH/WETH hybrid payment, portfolio Offer, real-time royalty, Dutch auction, British Auction, scheduled listing, bulk withdrawal, and Designated Taker purchase. In fact, 90% of users use the most basic BuyNow and are used to paying with ETH. So Element divides buying into two entrance functions: buyERC721 (basic feature purchase entrance: simple logic, low Gas) and buyERC721Ex (advanced feature purchase entrance: complex parameters, complex logic, high Gas). This not only preserves the rich trading contract characteristics, but also maximizes Gas savings.

The order structure is split into buy and sell orders.

Orders in most markets have only one structure, Order, which is distinguished according to orderType. In the above paragraph, there are two entry points for Element buying and selling. Here, we split Order into BuyOrder and SellOrder. Data for advanced features such as collection Offer will only appear in the SellOrder data. This is done in the base order structure, with fewer orderType forks and keeping BuyOrder minimal, resulting in the most common BuyNow operations and no wasted Gas.

Bitwise reuse of fields in the order structure.

ElementEx supports advanced features such as auction and scheduled listing, but these features are not used frequently. So we take something like Uint256 expiry and split it into three more fine-grained fields bitwise, taking up only one EMV to store one 256-bit slot space.

Order status is stored in bits.

In order to prevent repeated execution of orders, most markets generate 256-bit Nonce through KECCAK and then write them into the Mapping slot in the EVM storage area. Here ElementEx introduces 0xProtocol V4, which uses the first 248 bits of 256 bits as buckets and the last 8 bits as offsets. Instead of writing a new 256-bit slot for each order status, the slot is reused until a new slot is enabled for every 256 orders.

Contract code optimization.

PreviousSDK