Are you looking for the best and easiest way to build decentralized applications (dapps) on Linea? You’ve come to the right place. In this guide, we’ll introduce you to Moralis – the industry’s leading Web3 data provider. With Moralis’ top-tier tools, you can seamlessly integrate on-chain data into your Linea dapps with just a few lines of code, making development faster and more efficient!
For a sneak peek, check out our Wallet History endpoint in action:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY' }, }; fetch('https://deep-index.moralis.io/api/v2.2/wallets/0x5856EDF9212bdceC74301ec78AFc573B62D6A283/history?chain=linea', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
In return for calling the endpoint above, you’ll get the full history of the specified wallet. Additionally, the API response is enriched with automatic category tags, summaries, address labels, and more for each event, giving you decoded data straight out of the box. Here’s an example of what it might look like:
{ //... "result": [ { //... "native_transfers": [ { "from_address": "0x53d3801bc009867485eb69e6178e1c0deca3fddc", "from_address_label": null, "to_address": "0xde1e598b81620773454588b85d6b5d4eec32573e", "to_address_label": null, "value": "9223865045570189", "value_formatted": "0.009223865045570188", "direction": "send", "internal_transaction": false, "token_symbol": "ETH", "token_logo": "https://cdn.moralis.io/eth/0x.png" } ], "summary": "Sent 0.009224 ETH to 0xde...573e", "possible_spam": false, "category": "send" }, //... ] }
To learn more about Moralis and how to seamlessly build dapps on Linea, join us in this guide as we dive deeper into the process!
Ready to start building your own dapps on Linea? Sign up with Moralis today! You can create a free account and gain immediate access to our premier nodes and Web3 APIs!
Overview
Whether you’re building a cryptocurrency wallet, an NFT marketplace, or any other dapps on Linea, seamless access to on-chain data is essential. However, querying blockchain data has traditionally been a cumbersome and time-consuming process. Doing so from scratch demands a sophisticated underlying infrastructure, as well as manual data aggregation and decoding. This takes a lot of time that can be better spent on building features and improving the user experience of your dapps. As such, there has to be a better way, right?
Fortunately, you can now streamline on-chain data integration for your Linea dapps with Moralis – Web3’s premier infrastructure provider. Moralis allows you to query data for wallets, NFTs, tokens, and much more with just a few lines of code. If you’d like to learn more about this, join us in this guide as we introduce you to the easiest way to build dapps on Linea. Let’s dive straight in!
What is Linea?
Linea, developed by ConsenSys and launched in 2023, is a fully EVM-equivalent layer-2 (L2) scaling solution for Ethereum. Designed to enhance flexibility and scalability for dapps, Linea offers a highly attractive environment for both developers and end users!
The Linea blockchain, powered by innovative zero-knowledge (ZK) roll-up technology, offers higher throughput and lower transaction fees compared to Ethereum. This is achieved by bundling multiple off-chain transactions into single ZK-proofs, which are submitted and verified on the Ethereum blockchain in bulk. As a result, Linea provides lightning-fast transactions while maintaining the high security of the Ethereum mainnet.
Despite being a relatively new ecosystem, Linea boasts a substantial network with over one million monthly active users and more than 300 dapps. Among the prominent names on the network are Stargate, SyncSwap, and Particle Network.
Now that you have an overview of Linea, let’s explore some of the benefits of building dapps on this innovative chain!
Why Build Dapps on Linea?
Building dapps on Linea can be a great option. To highlight why, we’ll now explore five benefits of the network:
- EVM Equivalence: Linea is fully EVM equivalent, ensuring seamless compatibility with existing Ethereum smart contracts and dapps. This makes it straightforward for developers to migrate their projects to Linea without significant changes to their codebases.
- Ease of Use: With its EVM equivalence, Linea supports many familiar tools, including wallets like MetaMask, languages like Solidity, and frameworks like Truffle. This familiarity significantly simplifies the development process.
- Cost Efficiency: By lowering gas fees and increasing throughput, Linea is able to offer a cost-effective solution for both developers and end users. This efficiency is particularly advantageous for micro-transactions and dapps with a large user base.
- Scalability: Linea is designed to handle more transactions per second than Ethereum, enhancing the network’s scalability. This makes Linea an ideal platform for dapps requiring high throughputs, such as DeFi platforms and Web3 games.
- Security: As an L2 scaling solution, Linea benefits from the security of the Ethereum mainnet, ensuring that all transactions are processed safely.
Introducing Moralis – The Easiest Way to Build Dapps on Linea
The easiest way to build dapps on Linea is to leverage a Web3 data provider like Moralis. In our suite of industry-leading development tools, you’ll find nodes for all major blockchain networks and 10+ use case-specific APIs. This includes our premier NFT API, Wallet API, Token API, Price API, and many others. As such, whether you’re looking to build an NFT marketplace, cryptocurrency wallet, or any other dapps for the Linea network, we have got you covered!
But why should you use Moralis to build dapps on Linea?
- Comprehensive: Moralis provides the industry’s most detailed API responses, allowing you to access extensive data with fewer calls. Fetch information from both on- and off-chain sources with a single API request, making your dapp development more efficient.
- Simple: With full cross-chain compatibility, Moralis offers complete feature parity across all major blockchains, including Linea, Ethereum, and Polygon. This unified toolkit streamlines your developer experience, meaning you don’t have to bother with a new provider for each chain you interact with.
- Secure: Moralis sets the gold standard for enterprise-grade data security. We are proud to be the only SOC 2 Type 2 certified Web3 infrastructure provider in the industry, ensuring the highest level of protection for your projects.
Moralis Web3 APIs – Best Tools to Build Dapps on Linea
The easiest way to build dapps on Linea is to leverage our premier Web3 APIs, allowing you to seamlessly streamline on-chain data integration for your projects with a few lines of code. Due to the extensive number of specialized interfaces offered by Moralis, we won’t be able to cover them all in this guide. As such, we’ll instead introduce you to three prominent examples:
- Wallet API
- Token API
- NFT API
If you’d like to explore all our Linea-compatible interfaces, please check out our Web3 API page, where you’ll find the rest!
Wallet API
Moralis’ Wallet API is the industry’s leading tool for accessing wallet data. With this premier interface, you can seamlessly fetch any wallet’s history, token balances, net worth, profitability, and much more with just a single API call. So, whether you’re building crypto wallets, portfolio trackers, or other dapps on Linea, the Wallet API makes it easy!
To demonstrate the power of the Wallet API, here’s an example of how you can fetch a wallet’s entire history with one endpoint:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY' }, }; fetch('https://deep-index.moralis.io/api/v2.2/wallets/0x5856EDF9212bdceC74301ec78AFc573B62D6A283/history?chain=linea', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
By calling the endpoint above, you’ll receive the full history of the wallet. Additionally, the response is enriched with automatic category tags, summaries, and more, providing fully decoded data right out of the box. Here’s an example of what the response might look like:
{ //... "result": [ { //... "native_transfers": [ { "from_address": "0x53d3801bc009867485eb69e6178e1c0deca3fddc", "from_address_label": null, "to_address": "0xde1e598b81620773454588b85d6b5d4eec32573e", "to_address_label": null, "value": "9223865045570189", "value_formatted": "0.009223865045570188", "direction": "send", "internal_transaction": false, "token_symbol": "ETH", "token_logo": "https://cdn.moralis.io/eth/0x.png" } ], "summary": "Sent 0.009224 ETH to 0xde...573e", "possible_spam": false, "category": "send" }, //... ] }
Explore our official Wallet API documentation to discover other endpoints you can use to build dapps on Linea!
Token API
The Token API is the leading tool in Web3 for fetching ERC-20 data. With this top-tier interface, you can easily get token balances, metadata, owners, prices, and more using just a single line of code. Consequently, this powerful tool enables you to effortlessly create a wide range of dapps, from token explorers like Moralis Money to decentralized exchanges (DEXs) like Uniswap.
To demonstrate the accessibility of our Token API, let’s take a quick look at our endpoint for fetching balances with prices:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY' }, }; fetch('https://deep-index.moralis.io/api/v2.2/wallets/0x5856EDF9212bdceC74301ec78AFc573B62D6A283/tokens?chain=linea', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
By calling the script above, you will receive an array of all tokens held by the specified wallet. Furthermore, the response is enriched with prices, price changes over time, and additional details for each token. Here’s an example of what the response might look like:
{ //... "result": [ { "token_address": "0xa219439258ca9da29e9cc4ce5596924745e12b93", "symbol": "USDT", "name": "Tether USD", "logo": null, "thumbnail": null, "decimals": 6, "balance": "542905179549", "possible_spam": false, "verified_contract": false, "total_supply": "15290859809510", "total_supply_formatted": "15290859.80951", "percentage_relative_to_total_supply": 3.5505209406952085, "balance_formatted": "542905.179549", "usd_price": 0.9998899192502502, "usd_price_24hr_percent_change": -0.011008074974938614, "usd_price_24hr_usd_change": -0.00011008074974938609, "usd_value": 542845.4161397922, "usd_value_24hr_usd_change": -59.76340920757502, "native_token": false, "portfolio_percentage": 58.9964 }, //... ] }
Explore our Token API documentation to learn more about our other endpoints!
NFT API
Moralis’ NFT API is the best tool for accessing NFT data. This premier interface allows you to obtain NFT balances, metadata, prices, and much more with single endpoints. This makes it the perfect API for building NFT marketplaces, Web3 games, and other dapps that rely on NFT data!
To highlight the benefits of the NFT API, let’s take a look at our endpoint for fetching balances:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOUR_API_KEY' }, }; fetch('https://deep-index.moralis.io/api/v2.2/0x1F5876Da8Ed41b8DB49b9A82EA690fd8011394d1/nft?chain=linea', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
Calling the endpoint above will provide you with an array of NFTs held by the specified wallet. Here’s an example of what the response might look like:
{ //... "result": [ { "amount": "1", "token_id": "4", "token_address": "0x0872ec4426103482a50f26ffc32acefcec61b3c9", "contract_type": "ERC1155", "owner_of": "0x1f5876da8ed41b8db49b9a82ea690fd8011394d1", "last_metadata_sync": "2024-05-23T08:08:31.529Z", "last_token_uri_sync": "2024-05-23T08:08:31.454Z", "metadata": "{\"name\":\"Linea Voyage - Delta Edition\",\"description\":\"The Delta Edition represents the inception of the network, the moment of instantiation of the testnet and activation of the community effort, sending waves of energy throughout the network, and setting into motion the potential to come.\",\"image\":\"ipfs://Qmb31479z12SzfoskmhN2KRHRtZ3fnmm3TKeET4VtXs1Q9\",\"animation_url\":\"ipfs://Qmdu7CwEP5dSm5Y7iyV8AhPdJygpKkKeyqA1SyVezVkdHD\",\"attributes\":[{\"trait_type\":\"Tier\",\"value\":\"4\"}]}", "block_number": "3912275", "block_number_minted": null, "name": "Linea Voyage", "symbol": "VOYAGE", "token_hash": "9fb8de84306e2d372edcf8f25f058d00", "token_uri": "https://ipfs.moralis.io:2053/ipfs/QmfFuKPuUPyPMytHvhfBHcspqBSw4sQsXsbmhAFDVrTJUL", "minter_address": "ERC1155 tokens don't have a single minter", "verified_collection": false, "possible_spam": false, "collection_logo": null, "collection_banner_image": null }, //... ] }
To learn more about our other endpoints, please visit the official NFT API documentation page!
3-Step Tutorial: How to Build Dapps on Linea with Moralis
Now that you have explored the best tools for building dapps on Linea, we’ll guide you through a tutorial on how to use them. Specifically, we’ll show you how to get the native balance of any address in three simple steps using our Wallet API:
- Step 1: Obtain Your Moralis API Key
- Step 2: Write a Script to Call Our Native Balance Endpoint
- Step 3: Run the Code
However, before proceeding, let’s cover some necessary prerequisites!
Prerequisites
To follow along with the steps below, ensure you have the following prerequisites ready:
Step 1: Obtain Your Moralis API Key
If you haven’t already, register for a free account with Moralis by clicking the “Start for Free” button at the top right:
Once logged in, navigate to the “Home” tab to find your API key:
Copy and save the key for now, as you’ll need it in the second step!
Step 2: Write a Script Calling the Native Balances Endpoint
Open your preferred IDE, set up a folder, and initialize a project using the following terminal command:
npm init
Install the required dependencies by running the terminal command below:
npm install node-fetch --save npm install moralis @moralisweb3/common-evm-utils
Add "type": "module"
to the ”package.json” file:
Create a new ”index.js” file and add the following code:
import fetch from 'node-fetch'; const options = { method: 'GET', headers: { accept: 'application/json', 'X-API-Key': 'YOU_API_KEY' }, }; fetch('https://deep-index.moralis.io/api/v2.2/0x2898730f10411D6E92cad809e78cc3a7Ea82C695/balance?chain=eth', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err));
Replace YOUR_API_KEY
with your Moralis API key and configure the address
parameter to fit your query:
That’s it for the code! All that remains now is to run the script!
Step 3: Run the Code
Open a new terminal, navigate to your project’s root folder, and run the input below to execute the script:
node index.js
In return, you’ll get the native balance of the specified wallet. Here’s an example of what it might look like:
{ balance: '904846316993485' }
That’s it! Getting on-chain data doesn’t have to be more challenging than this when using Moralis. From here, you can follow the same steps to call any of our other endpoints. With these tools, you now have everything you need to build amazing dapps on Linea!
Summary: How to Build Dapps on Linea
When building dapps on Linea, you need a seamless way to integrate on-chain data into your project. However, doing so from scratch is a bothersome and time-consuming process. It requires setting up an underlying infrastructure and manually aggregating and decoding the data. Fortunately, you can now streamline the process with a Web3 data provider like Moralis!
Moralis provides the tools you need to seamlessly integrate on-chain data into your dapps. Our comprehensive toolkit includes nodes for over 20 networks and more than ten use case-specific APIs, such as the Token API, Wallet API, and Streams API.
Here’s why you should build dapps on Linea with Moralis:
- Comprehensive: Our outcome-driven APIs provide more data with fewer API calls compared to the competition, making your dapp development on Linea more efficient.
- Cross-Chain: Our API suite is fully cross-chain compatible, eliminating the need for a new provider for each blockchain you interact with. The supported networks include Linea, Ethereum, Polygon, BSC, Optimism, Arbitrum, Avalanche, and many more.
- Secure: Moralis is the only SOC 2 Type 2 certified Web3 infrastructure provider, ensuring enterprise-grade data security.
So, if you’d like to start building dapps on Linea yourself, remember to sign up with Moralis. You can create an account for free, and you’ll gain instant access to our top-tier APIs and nodes!
Additionally, if you’re serious about building dapps on Linea, be sure to check out other tools offered by Moralis. For instance, to get free testnet tokens you can use during your development endeavors, make sure to check out our Linea Goerli faucet article now!
Read More: moralis.io