<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[megabyte0x | Verifiable Web3 and AI engineering]]></title><description><![CDATA[Technical writing on Web3 infrastructure, verifiable systems, DAO governance, AI agents, and developer tooling by megabyte0x.]]></description><link>https://blog.megabyte.sh</link><generator>RSS for Node</generator><lastBuildDate>Sun, 31 May 2026 18:30:07 GMT</lastBuildDate><atom:link href="https://blog.megabyte.sh/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Verifiable DAO Proposal Risk Agent: from “trust the dashboard” to “verify the vote”]]></title><description><![CDATA[DAO governance has a trust problem hiding in plain sight: voters are asked to approve executable bytes they rarely have time, tooling, or context to inspect.
A forum post may say, “raise a supply cap.]]></description><link>https://blog.megabyte.sh/verifiable-dao-proposal-risk-agent-from-trust-the-dashboard-to-verify-the-vote</link><guid isPermaLink="true">https://blog.megabyte.sh/verifiable-dao-proposal-risk-agent-from-trust-the-dashboard-to-verify-the-vote</guid><category><![CDATA[eigencloud]]></category><category><![CDATA[dao-agent]]></category><category><![CDATA[ai agents]]></category><category><![CDATA[secir]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Wed, 13 May 2026 05:00:00 GMT</pubDate><content:encoded><![CDATA[<p>DAO governance has a trust problem hiding in plain sight: voters are asked to approve executable bytes they rarely have time, tooling, or context to inspect.</p>
<p>A forum post may say, “raise a supply cap.” The actual payload may also touch an oracle, introduce a new dependency, transfer an admin role, or change a bridge configuration. For most voters, those details are buried inside <code>(target, value, calldata)</code> tuples and protocol-specific contracts. Existing dashboards can simulate proposals, but the voter still has to trust the dashboard operator, its database, and its domain name.</p>
<p>That is the wrong trust model for decisions that move protocol risk.</p>
<h2>The problem today</h2>
<p>DAO proposals are increasingly complex. A single governance action can touch risk parameters, proxy implementations, oracle sources, treasury approvals, and cross-chain execution paths. The higher the complexity, the harder it becomes for voters to answer the basic question: <strong>what will this proposal actually do if it passes?</strong></p>
<p>The current process has three major gaps:</p>
<ol>
<li><p><strong>Human-readable descriptions can drift from executable payloads.</strong> A proposal title and forum post are not the source of truth. The calldata is.</p>
</li>
<li><p><strong>Simulation tools are often centralized.</strong> A green dashboard is useful, but it is still a claim made by a service operator.</p>
</li>
<li><p><strong>Voting windows are short.</strong> Voters need a fast, reproducible signal before the window closes, not a post-mortem after execution.</p>
</li>
</ol>
<p>In other words, the governance system is decentralized, but the analysis layer that informs votes is often not.</p>
<h2>The DAO Risk Agent solution</h2>
<p>The Verifiable DAO Proposal Risk Agent turns proposal review into a deterministic, signed verification pipeline.</p>
<p>Given an Aave governance proposal URL or supported Snapshot proposal URL, the agent:</p>
<ul>
<li><p>resolves the actual executable payload;</p>
</li>
<li><p>decodes calldata using verified ABIs from Etherscan or Sourcify;</p>
</li>
<li><p>forks mainnet at a deterministic proposal lifecycle block;</p>
</li>
<li><p>simulates execution locally with Anvil;</p>
</li>
<li><p>snapshots important protocol state before and after execution;</p>
</li>
<li><p>builds a structured state diff;</p>
</li>
<li><p>runs a versioned YAML ruleset over that diff;</p>
</li>
<li><p>classifies the proposal as <code>SAFE</code>, <code>WARNING</code>, or <code>CRITICAL</code>;</p>
</li>
<li><p>emits a canonical JSON report; and</p>
</li>
<li><p>signs the report hash with the agent identity.</p>
</li>
</ul>
<p>The output is not just a screenshot or a mutable dashboard page. It is a verifiable artifact. Anyone can recompute the canonical report hash, recover the signing address, and check that the report was produced by the expected agent under the expected ruleset and watchlist.</p>
<p>This changes the review conversation. Instead of asking, “Do we trust this website?”, voters can ask, “Does this signed report match the payload, block, ruleset, and agent identity we expect?”</p>
<h2>Why this matters for DAOs</h2>
<p>The agent is designed for the kinds of changes that create real protocol risk:</p>
<ul>
<li><p>admin or owner role transfers;</p>
</li>
<li><p>proxy implementation upgrades;</p>
</li>
<li><p>oracle source changes;</p>
</li>
<li><p>liquidation-threshold changes;</p>
</li>
<li><p>large supply or borrow cap changes;</p>
</li>
<li><p>timelock-delay reductions;</p>
</li>
<li><p>treasury transfers or approvals;</p>
</li>
<li><p>new dependencies outside the known watchlist; and</p>
</li>
<li><p>bridge, DVN, or multisig configuration changes.</p>
</li>
</ul>
<p>These are exactly the changes that can hide inside ordinary-looking proposals. The DAO Risk Agent does not replace human governance review; it gives reviewers a forcing function. It surfaces concrete state changes that humans can debate before voting.</p>
<h2>How EigenCloud helps</h2>
<img src="https://cdn.hashnode.com/uploads/covers/62df4c8b790e138f3d397df0/bd39ba4c-e0b1-460e-bd0a-2236d0c86f85.png" alt="" style="display:block;margin:0 auto" />

<p>EigenCloud, through EigenCompute, supplies the trust layer this kind of agent needs.</p>
<p>Running the agent on EigenCompute means the critical simulation and signing path can be tied to an attested container, an app wallet identity, and an operator set backed by EigenLayer economic security. The report is no longer merely “hosted by someone.” It is produced by a specific container image, signed by a specific agent identity, and inspectable through EigenCloud’s verification surface.</p>
<p>EigenCloud helps in four practical ways:</p>
<ol>
<li><p><strong>Container attestation</strong> — voters and integrators can connect a report to the code image that produced it.</p>
</li>
<li><p><strong>App wallet identity</strong> — reports are signed by the agent identity, not by a random server key controlled by an operator.</p>
</li>
<li><p><strong>Operator-set redundancy and economic security</strong> — the trust model moves away from a single centralized operator and toward EigenLayer-backed execution.</p>
</li>
<li><p><strong>Agent-native infrastructure</strong> — the agent can use EigenCompute deployment, persistent storage for reusable artifacts, and EigenCloud’s AI gateway for optional plain-English advisory notes without making those notes part of the signed report.</p>
</li>
</ol>
<p>The signed report remains the source of truth. Optional IPFS artifacts, registry anchors, UI summaries, and LLM advisory text are useful context, but they do not change the canonical report hash.</p>
<h2>From governance dashboards to governance evidence</h2>
<p>The goal is not to make every proposal automatically safe. No ruleset can catch every future attack. The goal is to make trust explicit.</p>
<p>A voter should be able to see:</p>
<ul>
<li><p>which payload was analyzed;</p>
</li>
<li><p>which block was used for simulation;</p>
</li>
<li><p>what changed before and after execution;</p>
</li>
<li><p>which rules fired;</p>
</li>
<li><p>which agent signed the report;</p>
</li>
<li><p>which ruleset and watchlist were used; and</p>
</li>
<li><p>whether the signature still verifies.</p>
</li>
</ul>
<p>That is the difference between a dashboard and evidence.</p>
<p>DAO governance needs more than readable proposal descriptions. It needs verifiable risk analysis that survives adversarial conditions, short voting windows, and operator trust assumptions. The Verifiable DAO Proposal Risk Agent is a step toward that future: proposal review that is deterministic, signed, and built for decentralized trust.</p>
<h2>Links</h2>
<ul>
<li><p>Public URL: <a href="https://verifiable-proposal.vercel.app/">https://verifiable-proposal.vercel.app/</a></p>
</li>
<li><p>GitHub URL: <a href="https://github.com/megabyte0x/verifiable%5C_proposal">https://github.com/megabyte0x/verifiable\_proposal</a></p>
</li>
<li><p>Eigen Cloud Dashboard URL: <a href="https://verify.eigencloud.xyz/app/0x73e33474CccFda5D64160804F94F7DE0C2c85d69">https://verify.eigencloud.xyz/app/0x73e33474CccFda5D64160804F94F7DE0C2c85d69</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[EigenisedNews: Verifiable News Research for Humans and Agents]]></title><description><![CDATA[The internet gives us more news than any person or organization can properly examine. AI has made that faster, but not always safer. Most AI news tools can summarize an article in seconds, yet they of]]></description><link>https://blog.megabyte.sh/eigenisednews-verifiable-news-research-for-humans-and-agents</link><guid isPermaLink="true">https://blog.megabyte.sh/eigenisednews-verifiable-news-research-for-humans-and-agents</guid><category><![CDATA[eigencloud]]></category><category><![CDATA[ai-news-analytics]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Tue, 12 May 2026 05:00:00 GMT</pubDate><content:encoded><![CDATA[<p>The internet gives us more news than any person or organization can properly examine. AI has made that faster, but not always safer. Most AI news tools can summarize an article in seconds, yet they often hide the most important parts of the work:</p>
<ul>
<li><p>Which source was actually used?</p>
</li>
<li><p>Was the article interpreted from more than one angle?</p>
</li>
<li><p>Did the model challenge the article's framing or simply repeat it?</p>
</li>
<li><p>Can a reader, editor, researcher, or agent verify how the result was produced?</p>
</li>
</ul>
<p>This is the problem eigenisedNews is built to solve. It is not just another summarizer. It is a product for turning one news article into an inspectable research brief with visible disagreement, source binding, and a verification path.</p>
<h2>The problem we face today</h2>
<p>News moves quickly. Narratives form before the facts are fully understood. Teams need to understand what an article says, what it implies, and where it may be weak or incomplete.</p>
<p>Today, that work is usually split between two imperfect options.</p>
<p>The first option is manual research. It is careful, but slow. Analysts have to read the article, identify its framing, check the strongest arguments for it, and then challenge that same framing from the other side.</p>
<p>The second option is generic AI summarization. It is fast, but often too opaque. A model may compress the article into a confident answer without making the disagreement visible. It may also mix outside assumptions into the response without clearly showing where the evidence boundary begins and ends.</p>
<p>That creates a trust gap. People do not only need faster answers. They need a way to inspect how an answer was produced, especially when the article is sensitive, market-moving, politically charged, or operationally important.</p>
<p>Autonomous agents face the same issue. An agent can fetch, summarize, and route information automatically, but it still needs a reliable research primitive: a way to submit an article, receive a structured analysis, pay when required, and verify the output before using it downstream.</p>
<h2>The solution EigenisedNews provides</h2>
<p>eigenisedNews starts with a simple product experience:</p>
<ol>
<li><p>Paste a news article URL.</p>
</li>
<li><p>The product fetches that article once.</p>
</li>
<li><p>The system prepares one shared article context.</p>
</li>
<li><p>A planning agent creates two research directions.</p>
</li>
<li><p>A pro agent analyzes the strongest case for the article's framing.</p>
</li>
<li><p>A contra agent analyzes the strongest case against, or the strongest complication of, that same framing.</p>
</li>
<li><p>A main agent summarizes where the two perspectives agree, diverge, and what the reader should take away.</p>
</li>
</ol>
<p>The key product decision is that both perspectives use the same source material. The disagreement is not created by cherry-picking different articles. It comes from interpreting the same article through two opposing lenses.</p>
<p>That makes the output more useful than a normal summary. A reader can see the article's main claim, the case for accepting it, the case for questioning it, and the final comparison in one place.</p>
<p>The product also preserves provenance. The response can include prompt bindings, article hashes, model run metadata, a signed manifest, and verification details. In the UI, this appears as a research brief first, with deeper proof and diagnostic information available when the user needs it.</p>
<p>In practical terms, eigenisedNews helps users answer:</p>
<ul>
<li><p>What is this article really saying?</p>
</li>
<li><p>What is the strongest argument in favor of its framing?</p>
</li>
<li><p>What is the strongest argument against that framing?</p>
</li>
<li><p>What did each agent see and produce?</p>
</li>
<li><p>Can this result be checked later?</p>
</li>
</ul>
<h2>How EigenCloud helps</h2>
<img src="https://cdn.hashnode.com/uploads/covers/62df4c8b790e138f3d397df0/3e282490-6871-464f-810b-d296f7b22604.png" alt="" style="display:block;margin:0 auto" />

<p>EigenCloud makes eigenisedNews stronger because the product is not only about generating text. It is about producing research that can be connected to a trustworthy execution environment.</p>
<p>For a verification-focused AI product, the runtime matters. EigenCloud helps by giving the application a better foundation for confidential compute, runtime identity, deployment provenance, and signed outputs.</p>
<p>That matters for three product reasons.</p>
<h3>1. A stronger trust boundary</h3>
<p>When a user receives a research brief, they should not have to trust only the interface. They should be able to connect the result to the system that produced it. EigenCloud gives eigenisedNews a more credible execution boundary than a normal hosted AI app.</p>
<h3>2. Signed research artifacts</h3>
<p>eigenisedNews can sign research results and bind them to article content, prompts, outputs, and deployment metadata. This turns the response from a disposable AI answer into an artifact that can be inspected, stored, and verified.</p>
<h3>3. Verification as part of the product</h3>
<p>The verification path is not separate from the product story. EigenCloud helps eigenisedNews show where the app ran, which build produced the result, and how the signed output connects back to the deployed system.</p>
<p>For teams using AI in real workflows, this is important. The value is not only that the analysis is fast. The value is that the analysis has a clearer audit trail.</p>
<h2>How agents can utilize eigenisedNews</h2>
<p>EigenisedNews is designed for both humans and autonomous agents.</p>
<p>Human users can open the app, paste an article, and read the two-sided brief. Agents can use the same capability through the API.</p>
<p>The agent-facing workflow is built around paid research:</p>
<ul>
<li><p>Agents discover the service through the OpenAPI, x402, verification, and skill endpoints.</p>
</li>
<li><p>They submit a news article URL to the paid research route.</p>
</li>
<li><p>If payment is required, they receive a <code>402 Payment Required</code> challenge.</p>
</li>
<li><p>They pay with a supported payment flow and retry the same request.</p>
</li>
<li><p>They receive the signed research response.</p>
</li>
<li><p>They can pass the result into downstream workflows such as monitoring, editorial triage, market intelligence, due diligence, or alerting.</p>
</li>
</ul>
<p>This gives agents a reusable research primitive. Instead of building their own article fetcher, prompt flow, payment flow, and verification flow, an agent can call eigenisedNews when it needs a structured two-sided analysis of a news article.</p>
<p>That is the bigger product direction: AI agents should not only consume information. They should be able to buy, verify, and reuse specialized services that produce trustworthy intermediate work.</p>
<h2>Why this matters</h2>
<p>The future of news analysis is not just faster summaries. It is inspectable research.</p>
<p>EigenisedNews gives users and agents a product that makes disagreement visible, keeps the source boundary clear, and uses EigenCloud to make the result more verifiable.</p>
<p>It helps people move faster without pretending that speed alone creates trust.</p>
<h2>Links</h2>
<ul>
<li><p>Live URL: <a href="https://eigenised-news.vercel.app/">https://eigenised-news.vercel.app/</a></p>
</li>
<li><p>GitHub URL: <a href="https://github.com/megabyte0x/eigenisedNews">https://github.com/megabyte0x/eigenisedNews</a></p>
</li>
<li><p>EigenCloud Dashboard: <a href="https://verify.eigencloud.xyz/app/0x62B98291bdaab3FE0E12b4693e6D79f391501437">https://verify.eigencloud.xyz/app/0x62B98291bdaab3FE0E12b4693e6D79f391501437</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Fermah]]></title><description><![CDATA[Zero Knowledge Proofs (ZKPs) have evolved tremendously in the past few years. There are now multiple proving systems, each with its pros and cons, and tons of use cases.

ZK is the endgame.

With every improvement or introduction of a proving system ...]]></description><link>https://blog.megabyte.sh/fermah</link><guid isPermaLink="true">https://blog.megabyte.sh/fermah</guid><category><![CDATA[Ethereum]]></category><category><![CDATA[ZKP]]></category><category><![CDATA[eigenlayer]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Sat, 26 Apr 2025 03:49:58 GMT</pubDate><content:encoded><![CDATA[<p>Zero Knowledge Proofs (ZKPs) have evolved tremendously in the past few years. There are now multiple proving systems, each with its pros and cons, and tons of use cases.</p>
<blockquote>
<p>ZK is the endgame.</p>
</blockquote>
<p>With every improvement or introduction of a proving system and algorithm, there's in complexity for the software and the hardware. Every application cannot use every type of proving algorithm, and every type of hardware cannot run every proving system.</p>
<p>This eventually creates a new problem for generating ZKPs.</p>
<h1 id="heading-problem-in-generating-zero-knowledge-proof">Problem in generating Zero Knowledge Proof</h1>
<p>Zero-knowledge proofs definitely increase the network/system's speed and throughput, but <strong>generating proofs is a resource-intensive process</strong> that <strong>requires a different setup for different proving systems.</strong></p>
<p>So here there's both a demand and supply problem. And Fermah solves this problem.</p>
<h1 id="heading-what-is-fermah">What is Fermah?</h1>
<p><a target="_blank" href="https://www.fermah.xyz/">Fermah</a> is a 2-sided marketplace for proof generation.</p>
<p>Fermah helps in the cheap, fast and reliable generation of Zero Knowledge proofs.</p>
<p>Under the hood, Fermah is an Eigen Layer AVS module.</p>
<h2 id="heading-2-sided-marketplace">2-sided Marketplace</h2>
<p>Fermah marketplace consists <strong>Seekers</strong> on the demand side and <strong>Prover Nodes</strong> on the supply side.</p>
<h3 id="heading-seekers-demand">Seekers (Demand)</h3>
<p>The whitelisted users that can submit Proof Requests.</p>
<h3 id="heading-prover-nodes-supply">Prover Nodes (Supply)</h3>
<p>The nodes that generate proofs for the Proof Requests assigned to them. These prover nodes consists of Eigen Layer Operators which provide computational resources like CPU and GPU.</p>
<h1 id="heading-how-does-fermah-marketplace-work">How does Fermah marketplace work?</h1>
<p>There are three major components of the Fermahs's proof marketplace:</p>
<ol>
<li><p>Seeker</p>
</li>
<li><p>Prover Node</p>
</li>
<li><p>Matchmaker</p>
</li>
</ol>
<p><img src="https://storage.googleapis.com/papyrus_images/ec154d21e76ccbbbfc5f65b28ec1665b.png" alt /></p>
<p>Seeker first sends a request to generate proof to <strong>Matchmaker</strong> which is the core and is responsible for allocating requests to different Provider nodes.</p>
<p>The Matchmaker allocate the request based on the requirements of the proof request and maintaining competitive pricing. This orchestration ensures the optimization of the utilization rate of machines and fast generation of the proof, with the core goal to minimize the cost of generating proofs.</p>
<h1 id="heading-proving-system-supported-in-fermah">Proving System supported in Fermah</h1>
<p>The Fermah's architecture is build to support any proving system. Currently most of the major proving systems are supported and more will be add soon.</p>
<p>Proving systems currently supported:</p>
<ul>
<li><p><a target="_blank" href="https://docs.succinct.xyz/">SP1 by Succinct Labs</a></p>
</li>
<li><p><a target="_blank" href="https://dev.risczero.com/api/">The RISC Zero zkVM</a></p>
</li>
<li><p><a target="_blank" href="https://jolt.a16zcrypto.com/">Jolt by a16z</a></p>
</li>
<li><p><a target="_blank" href="https://www.zeroknowledgeblog.com/index.php/groth16">Groth16 by Jens Groth</a></p>
</li>
<li><p>check latest details <a target="_blank" href="https://docs.fermah.xyz/introduction/supported-proof-systems">here</a></p>
</li>
</ul>
<h1 id="heading-current-users-of-fermah">Current users of Fermah</h1>
<p>The proof marketplace brought a cheap and fast way to generate zero knowledge proofs which has been a big requirement for the L2 squencers and other infrastructure components in the blockchain.</p>
<h2 id="heading-zksync">ZKSync</h2>
<p>ZKSync's Elastic Network helps devs by providing aggregation of the zero knowledge proofs for their app chains, and as the ecosystem expands the proof generation will cost expand proportionately. To solve this, ZKSync is partnering with Fermah for generating proofs for their sequencers.</p>
<p>This partnership will help ZKSync:</p>
<ul>
<li>Increase resilience through decentralization</li>
</ul>
<ul>
<li><p>Lower proving costs via market competition</p>
</li>
<li><p>Enhanced scalability without bottlenecks</p>
</li>
</ul>
<h2 id="heading-scroll">Scroll</h2>
<p>Scroll have a complete proving pipeline where they generate different proofs (Chunk Proofs, Batch Proofs, Bundle Proofs) before submitting it to the Ethereum. This cost heavy process is now being powered by the Fermah's universal proof generation capabilities.</p>
<h2 id="heading-gateway">Gateway</h2>
<p>Gateway's Presto is a Platform to deploy ZK rollup in few clicks. Integration with Fermah will help all the ZK rollups to get proofs generated in a fast and reliable way.</p>
<h1 id="heading-who-can-use-fermah-for-proof-generation">Who can use Fermah for proof generation?</h1>
<p>Fermah can support any type of Proving system and it already supports major of them, therefore can network or application which requires can to generate proof can utilize Fermah proof market.</p>
<h2 id="heading-polygons-agglayer">Polygon's Agglayer</h2>
<p><a target="_blank" href="https://docs.agglayer.dev/">Polygon's Agglayer</a> uses <a target="_blank" href="https://docs.agglayer.dev/agglayer/core-concepts/pessimistic-proof/">Pessimistic Proof</a> to prove that withdrawal claim made on any chain connected to Agglayer are backed by deposits made to the unified bridge contract.</p>
<p><img src="https://storage.googleapis.com/papyrus_images/6d436b347b823025471190ee05fb0408.png" alt /></p>
<p>The proofs are being generated using SP1 zkVM and the Plonky3 proving system which is supported by the Fermah marketplace.</p>
<p>This integration can help Agglayer in generating proof in a cost-effective manner and removing any possible bottlenecks for scalability.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>To conclude this post it will be right to say the infrastructure and research around ZK has been on exponential growth, and Fermah will play a critical role in generating cost-effective proof for the app chains, L2s, or basically anything that requires proof generation.</p>
<p>Also, more AVSs like Fermah on Eigen Layer will provide the infrastructure with shared economic security for the upcoming consumer applications in crypto.</p>
<hr />
<p>Thanks for reading.</p>
<p>If you have any queries or feedback, <a target="_blank" href="https://x.com/megabyte0x">DM</a></p>
<p><em>Keep Building (,🚀)</em></p>
]]></content:encoded></item><item><title><![CDATA[Eigen Layer: The trusted, verifiable cloud]]></title><description><![CDATA[Building applications on blockchain is not as easy as building applications using a traditional stack. On blockchain, every state transition in the application relatively costs more, usually brings scalability issues due to the limitations of block s...]]></description><link>https://blog.megabyte.sh/eigen-layer-the-trusted-verifiable-cloud</link><guid isPermaLink="true">https://blog.megabyte.sh/eigen-layer-the-trusted-verifiable-cloud</guid><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Wed, 23 Apr 2025 07:19:36 GMT</pubDate><content:encoded><![CDATA[<p>Building applications on blockchain is not as easy as building applications using a traditional stack. On blockchain, every state transition in the application relatively costs more, usually brings scalability issues due to the limitations of block space and always requires a consensus to reach the quorum, which takes several minutes to reach the cryptoeconomic finality (~12 min on Ethereum mainnet). And for the infrastructure projects, bootstrapping their own decentralised network takes the majority cut of their funding, leading to the project’s token devaluation.</p>
<p>Eigen Layer focuses on solving all the above issues and more in the blockchain industry, it’s not only helping the infrastructure projects but the base layer, i.e., Ethereum mainnet, to get more decentralised and rewarding for the ETH stakers. Let’s understand how 👇🏻</p>
<h1 id="heading-what-is-eigen-layer">What is Eigen Layer?</h1>
<p>Eigen Layer is are set of contracts that enables Ethereum’s consensus layer stakers/validators to opt in to validate new AVS modules built on top of Ethereum by enabling additional slashing conditions on their staked $ETH.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745246960966/3f0f1f76-75f3-4572-b33f-3f8a891ab63e.png" alt class="image--center mx-auto" /></p>
<p>This enables validators that are already present in the Ethereum network to earn additional rewards in exchange for the computational power, storage, etc, with their native staking yield from validating Ethereum blocks.</p>
<h1 id="heading-why-do-validators-join-the-eigen-layer">Why do validators join the Eigen Layer?</h1>
<p>When a block is being created on Ethereum, the state transition needs to be validated by a network of validators. When the majority of the network accepts the transition, the block is said to be <em>“finalised”</em>. To be part of this consensus network, the validators are required to stake 32 $ETH, which is subject to <a target="_blank" href="https://ethereum.org/en/developers/docs/consensus-mechanisms/pos/rewards-and-penalties/#slashing">slashing</a> in case of malicious activity by the validator and after every epoch, validators receive <a target="_blank" href="https://ethereum.org/en/developers/docs/consensus-mechanisms/pos/rewards-and-penalties/#rewards">rewards</a> for their honest work. For a few validators who have a basic setup, this is good incentive as it keeps the network secure and decentralised, but many validators have a high-end setup whose computational power has not been utilised to the full extent. Eigen Layer solves this!</p>
<p>Eigen Layer enables validators to provide their computational power and other resources while keeping their staked ETH in the consensus network. To be part of this, validators need to change their $ETH withdrawal credentials to the Eigen Layer smart contracts and opt in for the modules they like to validate, while keeping in mind that each module brings its own additional slashing mechanism. For example, in the <a target="_blank" href="https://ethereum.org/en/developers/docs/data-availability/">Data Availability</a> module, the validators are responsible for providing storage, and in exchange, every time the service is used, they will be rewarded. And in case of any malicious activity, their staked $ETH will be slashed based on the conditions imposed by the Data Availability module developer.</p>
<p>This whole process is known as <em>“restaking”.</em></p>
<h2 id="heading-anything-for-solo-stakers">Anything for Solo Stakers?</h2>
<p>Yes! Eigen Layer encourages solo stakers (or home stakers) to join the ecosystem. Solo stakers are usually the ones who don’t have high computational power or resources but want to contribute to making the Ethereum network decentralised.</p>
<p>For these solo stakers, Eigen Layer provides two options:</p>
<ol>
<li><p>Opt in to AVSs on the Eigen Layer by providing the validation services directly. This might require additional resources from solo stakers.</p>
</li>
<li><p>Delegate the Eigen Layer operation to another entity. This doesn’t require additional resources from solo stakers.</p>
</li>
</ol>
<p>Both options provide an opportunity to earn additional rewards apart from their native Ethereum yield while contributing to the decentralisation and censorship resistance of the Ethereum network.</p>
<h1 id="heading-what-are-avs-modules-in-the-eigen-layer">What are AVS modules in the Eigen Layer?</h1>
<p>Blockchain has several limitations, like inaccessibility to off-chain data, high cost of zk proof generation, and many more. These limitations can be addressed by deploying services off-chain, but that brings the problem of verification and security, therefore, we require a network that can run these services and verify them with economic security. Eigen Layer solves this also!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745316853228/dc6f5521-0bd5-4379-b4d5-b3fec26fffa9.png" alt class="image--center mx-auto" /></p>
<p>In the Eigen Layer, you can create your own actively validated service (AVS) modules, which will be validated by validators who opt for it. Taking the last example, a DA AVS module, which requires active validation of the block data by a decentralised network of validators, can be built on the Eigen Layer. The AVS module developer will set the slashing conditions required to be accepted by the validator opting in. This makes the DA availability layer decentralised, with the Cost of Corruption (CoC) relatively higher than a fresh network, without bootstrapping the liquidity and spending millions in incentivisation on their own.</p>
<blockquote>
<p>Cost of Corruption (CoC) is the cost required to create an adverse condition. For example, an AVS module with $20M in staked will cost a minimum $10M to create an adverse condition.</p>
</blockquote>
<p>Some more examples for AVS modules: Price Oracle, ZK proof generation, TEE, basically anything that requires active validation of the correct execution of the service.</p>
<h1 id="heading-delegation-in-eigen-layer">Delegation in Eigen Layer</h1>
<p>Many would like to participate in the Eigen Layer ecosystem, but don’t have the requirements fulfilled to become an operator. For this, Eigen Layer provides an option to delegate their stake to any operator of their choice and earn rewards.</p>
<p>To note, if the chosen operator gets slashed, the d stakes also get slashed.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>To conclude this, we can say <strong><em>Eigen Layer creates a marketplace for decentralisation.</em></strong></p>
<ul>
<li><p>AVS module developers can buy decentralisation at a relatively cheaper price,</p>
</li>
<li><p>ETH Validators (or Eigen Operators) can earn additional rewards for their stake $ETH and utilise the complete computational power of the system, and</p>
</li>
<li><p>Anyone (or Delegators) can participate in the network by delegating, which eventually increases the CoC for AVSs.</p>
</li>
</ul>
<hr />
<p>Thanks for reading! If you have any queries, feel free to <a target="_blank" href="http://x.com/megabyte0x">DM</a> 🫡</p>
<p>Feedback is always appreciated 🙌🏻</p>
<p>Also, to learn more about Eigen Layer, checkout <a target="_blank" href="https://linktr.ee/0xcoordinated">Coordinated.</a></p>
<p><em>Keep Building (🧱, 🚀)</em></p>
]]></content:encoded></item><item><title><![CDATA[Actor Oriented Model: Part 2]]></title><description><![CDATA[gm again!
This is Part 2 of the AOM series. In the first part, we discuss the fundamentals of The actor-oriented model.
https://megabyte0x.xyz/blogs/actor-oriented-model-part-1
 
In this part, we will discuss the Lifecycle of Actors and Communication...]]></description><link>https://blog.megabyte.sh/actor-oriented-model-part-2</link><guid isPermaLink="true">https://blog.megabyte.sh/actor-oriented-model-part-2</guid><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Mon, 15 Jul 2024 13:00:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721047321234/bb456ede-276e-4bda-9aba-2f20a7e49cfe.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>gm again!</p>
<p>This is Part 2 of the AOM series. In the first part, we discuss the fundamentals of The actor-oriented model.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://megabyte0x.xyz/blogs/actor-oriented-model-part-1">https://megabyte0x.xyz/blogs/actor-oriented-model-part-1</a></div>
<p> </p>
<p>In this part, we will discuss the <strong>Lifecycle of Actors and Communication b/w Actors.</strong></p>
<hr />
<h1 id="heading-lifecycle-of-actors">Lifecycle of Actors</h1>
<p>In the AOM, <strong>Actors can create other actors</strong>. This brings in the parent-child hierarchy and contributes to the scalable model.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721040878299/1d295bca-1795-46a2-85ae-48ba3407e662.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-child-actor-properties">Child Actor Properties</h2>
<p>As explained before, every actor is isolated, i.e., they have their own memory, state management, and message queue. This also applies to child actors. So, when a parent actor creates a child actor, the child actor will have a separate state, memory, and message queue from the parent actor.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721041221282/1b64be51-6209-4c77-ac6b-21461d4e0722.png" alt class="image--center mx-auto" /></p>
<p>Having separate state management, memory, and message queues helps create highly efficient and scalable network models. For example, a parent actor can create a separate child actor for each function, and since the child actor has the same properties as other actors, all the child actors (and their respective functions) can be executed simultaneously, creating high-speed computation.</p>
<h2 id="heading-parent-child-actor-relationship">Parent-Child Actor Relationship</h2>
<p>In a parent-child relationship, parents have some supervision over their child, and the same is implemented in the parent-child actors. Parent actors can supervise child actors using different strategies for different conditions.</p>
<p>Parent actors can manage the lifecycle of child actors, including</p>
<ul>
<li><p>creation,</p>
</li>
<li><p>monitoring,</p>
</li>
<li><p>restarting,</p>
</li>
<li><p>and termination.</p>
</li>
</ul>
<p>For example, If a child actor gets into a deadlock, the parent actor can restart or terminate that child actor.</p>
<h1 id="heading-communication-bw-actors">Communication b/w actors</h1>
<p>The only way for an actor to communicate with another actor is by using the messages.</p>
<p>For Example:</p>
<p>If <strong>actor2</strong> wants to get a value of a variable <code>count</code> from <strong>actor1,</strong> they will need to go through the following process of message passing:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1721033020733/4e22d038-a34c-42a3-a405-15ca7184c9a7.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>The <strong>actor2</strong> will send a message to <strong>actor1</strong> to get the <code>count</code> value.</p>
</li>
<li><p>The actor1 will receive the message, process the message and send a message, including the <code>count</code> value, back to <strong>actor2.</strong></p>
</li>
</ol>
<p>The following are the key characteristics of the message passing:</p>
<ul>
<li><p>Asynchronous Communication</p>
</li>
<li><p>Message Queue</p>
</li>
<li><p>Message Immutability</p>
</li>
<li><p>Message Processing</p>
</li>
<li><p>Message Handling and Context Switching</p>
</li>
<li><p>Fault Tolerance and Error Handling</p>
</li>
</ul>
<p>Let's understand each of them.</p>
<h2 id="heading-asynchronous-communication">Asynchronous Communication</h2>
<p>When an actor(sender) sends a message to another actor(receiver), they can execute the remaining code without waiting for a reply. This removes the sender's dependency on the receiver; now, both can work simultaneously.</p>
<h2 id="heading-message-queue">Message Queue</h2>
<p>When a message is sent, it is wrapped in an envelope and placed in the receiver's message queue.</p>
<p>Each actor has a dedicated message queue where incoming messages are stored until the actor processes them.</p>
<h2 id="heading-message-immutability">Message Immutability</h2>
<p>After sending a message, the message and its content can't be changed. This ensures the consistency of the system and prevents any side effects that might occur due to this.</p>
<h2 id="heading-message-processing-loop">Message Processing Loop</h2>
<p>Every Actor has an event loop that keeps looking for the new message received in the message queue.</p>
<p>When a new message is found, the following happens:</p>
<ol>
<li><p>The message gets dequeued from the message queue.</p>
</li>
<li><p>The corresponding handler function is then called for the message in the actor.</p>
</li>
</ol>
<p>This ensures that the actor processes only one message at a time and maintains a single-threaded execution model, i.e., a message starts processing after the previous message is being processed completely.</p>
<h2 id="heading-message-handling">Message Handling</h2>
<p>When a message is dequeued from the message queue, the actor's message handlers are invoked to handle it.</p>
<p>The handler's invocation may update the actor's current state (like changing the variable values), send new messages (a response back to the sender), or create child actors (new actors to distribute the computation).</p>
<h2 id="heading-fault-tolerance-and-error-handling">Fault Tolerance and Error Handling</h2>
<p>If an actor encounters an error while processing a message, the actor system or the parent actor can manage the actor according to the defined supervision strategy.</p>
<p>For example:</p>
<p>If an actor encounters an error while processing a message, the actor system will detect the error. Depending on the supervision strategy, the actor system or the parent actor can restart or terminate the actor or report this error to a higher level in the hierarchy.</p>
<hr />
<p>Thanks for reading! If you have any queries, feel free to DM 🫡</p>
<p>Feedback is always appreciated 🙌🏻</p>
<p><em>Keep Building (🧱, 🚀)</em></p>
]]></content:encoded></item><item><title><![CDATA[Actor Oriented Model: Part 1]]></title><description><![CDATA[The Actor Oriented Model(AOM) is a conceptual model used in software engineering for concurrent computation.
Using AOM, developers can build highly scalable distributed networks that have the potential to grow and improve the efficiency of different ...]]></description><link>https://blog.megabyte.sh/actor-oriented-model-part-1</link><guid isPermaLink="true">https://blog.megabyte.sh/actor-oriented-model-part-1</guid><category><![CDATA[actor oriented]]></category><category><![CDATA[ao ]]></category><category><![CDATA[Blockchain]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Thu, 11 Jul 2024 12:30:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720698316687/8a296ce7-05df-4893-a22d-e7ffc5a3b609.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The Actor Oriented Model(AOM) is a conceptual model used in software engineering for concurrent computation.</p>
<p>Using AOM, developers can build highly scalable distributed networks that have the potential to grow and improve the efficiency of different technologies, like blockchain, as they scale.</p>
<p><strong>The AOM series</strong> will help you to understand the core concepts of AOM.</p>
<p><em>LFG (🧱.🚀)</em></p>
<hr />
<h1 id="heading-objectives">Objectives</h1>
<ul>
<li>Understand the principles of AOM</li>
</ul>
<h1 id="heading-what-is-an-actor">What is an Actor?</h1>
<p>Actor is the basic unit of computation of the AOM.</p>
<ul>
<li><p>It is <strong>autonomous</strong>,</p>
</li>
<li><p>it <strong>can execute concurrently</strong> with other actors,</p>
</li>
<li><p>and can only <strong>communicate through message passing</strong> with other actors.</p>
</li>
</ul>
<p>Being autonomous enables the actor to have its own state management, which is not shared with other actors.</p>
<p>Since the state is not shared with other actors, no actor is required to wait for the execution of other actors, enabling the parallel execution of multiple actors simultaneously.</p>
<p>If the actors want to communicate with other actors, they need to use message-passing flow, which is the only method for actors to communicate with each other.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720774853401/bb90bcc4-d7b6-4c18-8fae-169de4fa7651.png" alt class="image--center mx-auto" /></p>
<p>You can imagine an actor as a piece of code with its own class and variables and is not dependent on the variables or classes of other code to get executed. If an actor <em>(actor2)</em> wants to read any variable, the source actor <em>(actor1)</em> will execute a separate function to send a message with the requested data.</p>
<h1 id="heading-state-management">State Management</h1>
<p>Every actor has its own state, which means its own memory that is not linked to other actors.</p>
<p>This enables actors to execute without any external requirement outside of their scope.</p>
<h1 id="heading-concurrency">Concurrency</h1>
<p>As the actors are independent in both their computation limits and state management, multiple actors can be executed simultaneously.</p>
<p>This enables parallel computation, bringing high scalability to the applications.</p>
<h1 id="heading-message-passing">Message Passing</h1>
<p>Complex applications require communications to share data between different computation units (or actors, in this case). Message passing among the actors makes this possible.</p>
<blockquote>
<p>Example:</p>
<p>An actor (actor1) wants to know the state of the variable <code>price</code> in another actor (actor2). To do this, actor1 will first send a message to actor2 with the request. Actor2 will compute the message request and then create another message with the state of the variable <code>price</code> to actor1.</p>
</blockquote>
<p>As per the AOM,</p>
<ul>
<li><p>messages are <strong>immutable,</strong> meaning they cannot be changed once created.</p>
</li>
<li><p>actors can process only one message at a time.</p>
</li>
</ul>
<hr />
<p>That's it for Part 1. <em>(I know it's really short, but I will increase the depth progressively.)</em></p>
<p><em>Thanks for reading!</em></p>
<p>Any feedback is appreciated 🙌🏻</p>
<p><em>Keep Building (🧱,🚀)</em></p>
]]></content:encoded></item><item><title><![CDATA[AO - 100% Community TGE]]></title><description><![CDATA[gm
Recently, I have been studying about Tokenomics. I came across a "Fair Launch" by AO during my study. AO is the Hyper Parallel Computational layer built on top of Arweave, and a few days back, they had their Token Generate Event (TGE).
The excitin...]]></description><link>https://blog.megabyte.sh/ao-tokenomics</link><guid isPermaLink="true">https://blog.megabyte.sh/ao-tokenomics</guid><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Tue, 09 Jul 2024 15:55:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720624733583/9ed9db2b-642d-496b-8805-a76f4e679f77.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>gm</p>
<p>Recently, I have been studying about Tokenomics. I came across a "Fair Launch" by AO during my study. AO is <em>the Hyper Parallel Computational layer built on top of Arweave</em>, and a few days back, they had their Token Generate Event (TGE).</p>
<p>The exciting part about AO Tokenomics is its stakeholders.</p>
<p><img src="https://pbs.twimg.com/media/GO1LIFTakAA2tZh?format=png&amp;name=medium" alt="Image" /></p>
<p>The stakeholders include <strong>ONLY THE COMMUNITY.</strong> However, the team is confident that the Ecosystem Development will go smoothly.</p>
<p>I am intrigued by how this will work for the core AO dev team, ecosystem projects on AO, for stakeholders in Arweave, and for general community members. So, I sat one night and read the latest draft on AO.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://x.com/megabyte0x/status/1803939982832472413">https://x.com/megabyte0x/status/1803939982832472413</a></div>
<p> </p>
<p>Here are some of my critical findings about AO tokenomics. I hope you find something useful.</p>
<p><em>LFG 💪🏻</em></p>
<hr />
<h1 id="heading-total-supply">Total Supply</h1>
<p>Fundamentals of Bitcoin inspire AO Tokenomics.</p>
<p>There can only be a 21M supply of AO tokens like Bitcoin. These tokens will be minted over the years with 4 year smooth-halving.</p>
<h1 id="heading-circulating-supply">Circulating Supply</h1>
<p>The method of circulation is genuinely fascinating.</p>
<p>The AO tokens were minted every 5 minutes from the launch of the AO network on February 27th, 2024.</p>
<p>Minting new tokens every 5 minutes accumulated to <strong>1.425%</strong> monthly of the remaining supply. Minting like this is equivalent to 4 years of halving like Bitcoin, but instead of doing it abruptly, it's done in a flow.</p>
<p>A small visual to get it into the perspective:</p>
<p><img src="https://pbs.twimg.com/media/GO1LMr6XsAA3D2F?format=png&amp;name=medium" alt="Image" /></p>
<h1 id="heading-distribution">Distribution</h1>
<p>AO is built on Arweave, <em>the permanent data storage network</em>, which provides economic security to AO, <em>the computation layer</em>, and permanent storage and validation for all the messages passed on AO in a truly decentralised manner. This is only possible because of <strong>$AR</strong>, <em>the native token on Arweave.</em></p>
<p>This brings two types of participants who can earn AO during the minting period.</p>
<ol>
<li><p>$AR Holders</p>
</li>
<li><p>Users who bridge the assets</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720513309185/83e2cc5f-be65-4ccd-994c-9bb7097cd2eb.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-ar-holders">$AR Holders</h2>
<p>As mentioned above, the AO was minted from the network launch on 27 February. In four months, this accumulated to more than 1M $AO, distributed proportionately among AR holders.</p>
<p>Further, to continue incentivising the Arweave Community (including miners), <strong><em>1/3rd</em> of the newly minted AO</strong> will be distributed to $AR holders.</p>
<h2 id="heading-bridged-assets">Bridged Assets</h2>
<p>Users can bridge assets from other networks to AO networks to contribute to the economic security of their network.</p>
<p>Users are highly incentivised to bridge their assets from other networks to AO.</p>
<ul>
<li><p>First, they can use (not right now) the bridged assets in the wide varieties of applications on AO and</p>
</li>
<li><p>Second, they will mint AO.</p>
</li>
</ul>
<p>After bridging assets like stETH, <strong>users will earn <em>2/3rd</em> of newly minted AO tokens</strong> proportionately.</p>
<p>The bridging is divided into phases.</p>
<ul>
<li><p>Currently, phase 1 is in process, during which you can deposit stETH from Ethereum Mainnet to the AO network and mint AO but cannot use stETH in the AO Network.</p>
</li>
<li><p>In the coming phases, the stETH will be available within the AO Network while minting AO for the users.</p>
</li>
</ul>
<h1 id="heading-ecosystem-growth">Ecosystem Growth</h1>
<p>The above sections explain how the AO will be distributed to 100% of the community.</p>
<p>This raises the question of how the development of different projects on AO and the AO itself will be sustained. The answer is <strong>Bridged Assets.</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720520633177/029eb4d0-2960-468f-91a9-67007316decc.png" alt class="image--center mx-auto" /></p>
<p>As per the <a target="_blank" href="https://5z7leszqicjtb6bjtij34ipnwjcwk3owtp7szjirboxmwudpd2tq.arweave.net/7n6ySzBAkzD4KZoTviHtskVlbdab_yylEQuuy1BvHqc">AO's latest paper</a>, ecosystem growth is divided into two parts:</p>
<ul>
<li><p>Permissionless Ecosystem Funding</p>
</li>
<li><p>Permaweb Ecosystem Development Guild (PEDG)</p>
</li>
</ul>
<h2 id="heading-permissionless-ecosystem-funding">Permissionless Ecosystem Funding</h2>
<p>The idea of permissionless ecosystem funding is really simple. The community will support the projects in their development and provide potential revenue.</p>
<p>Community members can interact with applications using their bridged assets. When the team receives these bridged assets, projects can earn AO with the proportionate liquidity they can gather from the community, providing the team with sufficient funds for development. This makes the whole process permissionless and removes the requirement for grants to keep building.</p>
<h2 id="heading-permaweb-ecosystem-development-guild">Permaweb Ecosystem Development Guild</h2>
<p>The PEDG includes six core teams that contribute to the development and maintenance of AO. These teams are funded by the native yield of the bridged assets, like stETH on Ethereum Mainnet.</p>
<hr />
<p>Thanks for reading!</p>
<p>Any feedback is appreciated 🙌🏻</p>
<p><em>Keep Building (🧱,🚀)</em></p>
]]></content:encoded></item><item><title><![CDATA[Fair Token Launch]]></title><description><![CDATA[You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time. - John Lydgate

In Web3, space protocols try to deliver the best possible airdrop. Now, ever...]]></description><link>https://blog.megabyte.sh/fair-token-launch</link><guid isPermaLink="true">https://blog.megabyte.sh/fair-token-launch</guid><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Wed, 19 Jun 2024 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720182628724/e212bb93-9c56-4167-8297-dc22f911753e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time. - John Lydgate</p>
</blockquote>
<p>In Web3, space protocols try to deliver the best possible airdrop. Now, every protocol has a different definition of "best." Some think that providing a good share to the community is best, some believe that keeping the investors happy is best, some say giving it to all is best, and some say let's do it and think of the consequences later is best.</p>
<p>Indeed, every one of them has their reasons. We (or at least I) are no one to say why you did this, or you should have done this because we ( or at least I) are here to bring revolution to the internet, not ONLY for the money 🙂</p>
<p>My recent foray into tokenomics has been an enlightening journey, one that will equip me to build my own in the future. This created a Frequency Illusion, and I started noticing the <a target="_blank" href="https://x.com/aoTheComputer/status/1801284939612123244">"Fair Launch" which AO</a> did a few days back.</p>
<p>My inspiration for this blog came from a recent 'Fair Launch' I observed and the subsequent discussions and insights shared by various community members. This led me to jot down the most crucial factors a protocol should consider before embarking on an airdrop.</p>
<p><em>Let's dive in 🏊‍♂️</em></p>
<h2 id="heading-community">Community</h2>
<p>Protocols excel in their tech, but only with their community to support them.</p>
<p>The community members contributed to the protocol without self-interest and because they believed in the product.</p>
<p>Protocols should define before their airdrop what type of community members will be rewarded for their contributions.</p>
<h2 id="heading-early-contributors">Early Contributors</h2>
<p>Every protocol now was (in many cases is) a startup.</p>
<blockquote>
<p>A startup is a new venture with a small, motivated team focused on innovation and rapid growth.</p>
</blockquote>
<p>Rewarding the team who helped you reach the airdrop is something that every protocol should do in one way or another.</p>
<p>Early contributors can also include the computer geek lying on his mattress and creating valuable PR to make your protocol more efficient, secure, or understandable. They can also include a few of your advisors who are not technically on your team but have always reviewed your codebase, pitches, designs, etc.</p>
<p>But it should be clear to both you (as a protocol) and them (as a contributor) that the protocol should not be liable for this. Contributions can be considered volunteered work if tokenomics are not in favor (which I can't think of the case why they wouldn't).</p>
<h2 id="heading-sybil-resistance">Sybil Resistance</h2>
<blockquote>
<p>Sybil attacks exploit the network by using multiple fake identities.</p>
</blockquote>
<p>It's no news that the crypto space is filled with Airdrop hunters. <em>I also tried and failed miserably.</em></p>
<p>These airdrop hunters include some college students who got a taste of money, some serious hackers running bots at once to get qualified, and others.</p>
<p>Many protocols use several ways to avoid this, and that's great. Giving the airdrop to these hunters is discouraging for other community members.</p>
<h2 id="heading-criteria">Criteria</h2>
<p>Every protocol needs to define criteria when they are approaching the airdrop.</p>
<p>This is mainly done when the "Check Eligibility" site goes live, which is the clean way.</p>
<p>You define the criteria after taking the snapshots = You avoid many bots and hunters already.</p>
<p>However, I have seen many protocols announce their criteria for upcoming airdrops to bring in more liquidity. This works, but again, it shifts the focus from the community and building the future to filling one's pockets. Adopting this has made several airdrops worthless to both airdrop hunters and genuine community members.</p>
<h2 id="heading-allocation-of-tokens">Allocation of Tokens</h2>
<p>I guess this is the most important point of all. The protocol founders should always consider this before raising funds.</p>
<p>In the crypto space, many protocols with even great tech are required to raise funds to keep building before going to the mainnet due to the niche category from where they need to hire and the infrastructure cost they have to bear in the starting at least. In most cases, raising funds comes at the cost of allocating tokens to investors. Though these allocations have vested periods to prevent the spike in the circulating supply of tokens (or dumping of tokens), issues arise with this.</p>
<p>I know and understand two of them:</p>
<ul>
<li><p>Suppose the token distribution aligns with the community (releasing most tokens to the community). In that case, it dramatically impacts the token price, affecting investors' portfolios and making them unhappy.</p>
</li>
<li><p>Suppose the token distribution is aligned towards generic distribution (or some other term). In that case, the distribution of tokens to the community can be halted in several ways. One is making the token non-transferrable for some period. This safeguards the investor's portfolio, but community members lose interest because they genuinely believe in the product and don't want to be treated like that or because they are airdrop hunters who trade 24 hours to make money.</p>
</li>
</ul>
<p>There are many other reasons why token allocation should be considered from the start by the founders and the team if they are sure that they will be holding the token.</p>
<h2 id="heading-eligibility-check">Eligibility Check</h2>
<p><strong>Use Excel.</strong></p>
<p>This is what the community wants. Community members just want to know whether they are eligible. There shouldn't be any reason they need to connect their wallets and sign a transaction.</p>
<p>The approach of connecting a wallet and signing the transaction only motivates scammers to build clones and harm others. Many incidents have already happened where members sign malicious transactions in the belief of the product and the team and get caught in severe scams. Making community members connect their wallets should be avoided as much as possible.</p>
<h2 id="heading-preparation-for-distribution">Preparation for Distribution</h2>
<p>The distribution phase of the token is done in several ways a few of them are:</p>
<ul>
<li><p>directly sending allocated funds to the wallet.</p>
</li>
<li><p>making the user sign a transaction.</p>
</li>
<li><p>making the user sign a transaction and connecting their socials to claim the tokens. (this helps in avoiding sybil attacks)</p>
</li>
</ul>
<p>Whichever method the protocol chooses, they should be ready with clear definitions and guidelines for claiming the token in the form of a post on X or a blog. This helps prevent(up to an extent) users from visiting phishing sites and getting scammed.</p>
<p>Protocols should also consider the following points:</p>
<ul>
<li><p>The claim site should be able to handle high traffic.</p>
</li>
<li><p>The network on which they are distributing the token should not get bottlenecked</p>
</li>
<li><p>Deleting the scam links from the comments on socials (can help, but it is a tedious process)</p>
</li>
</ul>
<hr />
<p>These were my 2 cents on the Fair Launch.</p>
<p>Let me know your thoughts on the above points by simply DMing me.</p>
<p>Thanks for reading!</p>
<p><em>Keep Building (🧱,🚀)</em></p>
<hr />
<ul>
<li><p>Twitter <a target="_blank" href="https://twitter.com/megabyte0x">@megabyte0x</a></p>
</li>
<li><p>GitHub <a target="_blank" href="https://github.com/megabyte0x">@megabyte0x</a></p>
</li>
<li><p>Email <a target="_blank" href="mailto:contact@megabyte0x.xyz">contact@megabyte0x.xyz</a></p>
</li>
<li><p><a target="_blank" href="https://warpcast.com/megabyte">Farcaster</a> | <a target="_blank" href="https://hey.xyz/profile/0x01a79c">Lens</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[How to Succeed with a Startup]]></title><description><![CDATA[I recently saw Sam Altman's session on YouTube regarding How to succeed with a startup.
This session resonated with me, my co-founder, and our team.
Today, I am sharing some of the key points of the sessions and what I am doing as the co-founder of 0...]]></description><link>https://blog.megabyte.sh/how-to-succeed-with-a-startup</link><guid isPermaLink="true">https://blog.megabyte.sh/how-to-succeed-with-a-startup</guid><category><![CDATA[Startups]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Tue, 18 Jun 2024 18:30:00 GMT</pubDate><content:encoded><![CDATA[<p>I recently saw Sam Altman's session on YouTube regarding <strong>How to succeed with a startup.</strong></p>
<p>This session resonated with me, my co-founder, and our team.</p>
<p>Today, I am sharing some of the key points of the sessions and what I am doing as the co-founder of <a target="_blank" href="https://0rbit.co">0rbit 💫</a>.</p>
<h2 id="heading-1-building-a-good-product">1. Building a Good Product</h2>
<p>Building a good product is the hardest part of the startup. The product should be so good that people recommend it to others, creating a network effect. If this is achieved, 80% of the work is done.</p>
<h2 id="heading-2-easy-to-understand">2. Easy to Understand</h2>
<p>The product should be easy to understand. Considering we are building <a target="_blank" href="https://0rbit.co">0rbit</a> the Decentralized Oracle infrastructure, our product should be easy to understand for the developers who will use it. The audience type should be considered while analyzing if people can understand.</p>
<h2 id="heading-3-exponential-growth-in-the-market">3. Exponential growth in the market</h2>
<blockquote>
<p>The market started to undergo or will soon undergo exponential growth.</p>
</blockquote>
<p>Building a product in this type of market ensures the growth of the product overtime as the market grows.</p>
<h2 id="heading-4-fake-trends-amp-real-trends">4. Fake Trends &amp; Real Trends</h2>
<p>Real trends are the ones that will actually happen, like the adoption of <a target="_blank" href="https://ao.arweave.dev">AO</a> to build a decentralized permaweb, where people showed self-interest and wanted to use the product. Fake trends are the ones where founders make the community buy the product, but no one actually uses it.</p>
<h2 id="heading-5-evangelical-founder">5. Evangelical Founder</h2>
<p>A guy in the startup, usually the founder(s), will go out and sell the product, raise funds, and explain the product to the people- <strong>The face of the company.</strong></p>
<h2 id="heading-6-ambitious-vision">6. Ambitious Vision</h2>
<p>Your vision shouldn't overshadow others but grow organically. People become interested in the team's ambitious vision.</p>
<h2 id="heading-7-hard-startup-vs-easy-startup">7. Hard Startup vs Easy Startup</h2>
<p>The correct market state makes raising funding easy. However, getting people interested in the product and its vision is challenging.</p>
<h2 id="heading-8-confident-and-definitive-view-of-the-future">8. Confident and Definitive View of the Future</h2>
<p>The founders should be confident and have definitive views of the future. They should be able to adapt to market changes and pivot if necessary to achieve the vision.</p>
<h2 id="heading-9-huge-if-it-works">9. Huge if it works</h2>
<p>The product has and creates value in the ecosystem; if it works, it will be huge and grow exponentially. Again, this lies in the product quality and the vision.</p>
<h2 id="heading-10-team">10. TEAM</h2>
<blockquote>
<p>The team you built is the company you built.</p>
</blockquote>
<p>Building a great team is the most important thing to do after picking the right market and the product.</p>
<p>Every "successful" founder goes through the journey of</p>
<p>building the product -&gt; building a company = building a team.</p>
<h3 id="heading-optimists">Optimists</h3>
<p>Startups need to have an optimistic team. The world will say no to you and your product, but the team should always be upbeat and step up to the challenges.</p>
<h3 id="heading-idea-generators">Idea Generators</h3>
<p>The team should be able to generate ideas. This is achievable if the team consists of people who understand the product, the vision, and the market.</p>
<h3 id="heading-well-figure-it-out-attitude">"We'll Figure it Out" Attitude</h3>
<p>If you ever face some problem that looks unsolvable or the end of the company (<em>there will be many</em>), the team should have the attitude to stand up and say we will figure it out. This is important for founders; they know the team has their backs in the hard times. Investors trust the team and don't pull out the funding. And, of course, the success of the company.</p>
<h3 id="heading-ive-got-it-attitude">"I've Got IT" Attitude</h3>
<p>The early team members should step up independently, take ownership, and solve the problem.</p>
<h3 id="heading-action-bias">Action Bias</h3>
<p>The startups must move fast and take action without having all the data. The team should be able to adapt to these situations and move at the required pace.</p>
<h3 id="heading-the-blessing-of-inexperience">The Blessing of Inexperience</h3>
<blockquote>
<p>A statement from Steve Wozniak, co-founder of Apple.</p>
<p>The best things he did at Apple came from not having experience and the money.</p>
</blockquote>
<p>Being inexperienced in something is an advantage to an early startup because it allows you to solve problems in non-traditional ways without knowing they were previously unsolvable.</p>
<h2 id="heading-11-momentum">11. Momentum</h2>
<blockquote>
<p>Never lose momentum.</p>
</blockquote>
<p>The founders should always maintain momentum while building the product during the startup journey. If you lose momentum once, it becomes difficult to regain it within the team and yourself.</p>
<p><em>I think I made this mistake before and saw the repercussions</em></p>
<h2 id="heading-12-competitive-analysis">12. Competitive Analysis</h2>
<p>The founders should be aware of the market competition and clearly understand the product's position. This helps them gain the trust of the investors.</p>
<h2 id="heading-13-sensible-bussiness-model">13. Sensible Bussiness Model</h2>
<p>The founders should have some idea of how the company will make money, and investors need to know how the company will sustain itself.</p>
<p><em>In the case of 0rbit, we are aligned toward building a community-focused, self-sustainable network. Building a business model around this takes much time and is challenging.</em></p>
<h2 id="heading-14-distribution-strategy">14. Distribution Strategy</h2>
<p>The founders should have a sensible idea of the product's distribution strategy before reaching out to the investors.</p>
<p><em>In our case, being an infrastructure layer moves our focus towards building a developer community. This will help in the distribution of the product automatically when the developers realize that the product is easy to use and help them bring ANY data from the Internet to the Blockchain. I am not sure whether this is the correct approach or not :)</em></p>
<h2 id="heading-15-frugality-focus-obsession-love">15. Frugality, Focus, Obsession, Love</h2>
<p>The above four points should be clear to the founders.</p>
<p><em>For me, frugality is one motivation to build a great product. No one likes to be frugal, but you need to be when building a company; you can't spend $$$ on promotions when your product is 💩.Focus is something I am learning right now. Before, I used to focus on multiple things, but today, I need to focus on different things under one umbrella.Obsession and love are always there in me to build products for the community; the only difference this time is that I am building a company around it.</em></p>
<h2 id="heading-16-why-startup-win">16. Why Startup Win</h2>
<h3 id="heading-one-yes-or-one-no">One Yes or One No</h3>
<blockquote>
<p>Look for ideas that sound bad but are good.</p>
</blockquote>
<p>In big companies, you need multiple yeses to get a product out. In startups, you need only one yes to get the product out.</p>
<h3 id="heading-fast-changing-markets">Fast-Changing Markets</h3>
<blockquote>
<p>Startups have the advantage of agility and speed.</p>
</blockquote>
<p>Startups can adapt to market changes quickly and pivot if necessary. This is a huge advantage over big companies.</p>
<h3 id="heading-platform-shifts">Platform Shifts</h3>
<p>Startups can change their trajectory in a day if they see a market change or a new platform shift. This takes a considerable amount of time in big companies.</p>
<hr />
<p>If you are building a startup, I recommend watching the session. It will help you understand the startup journey and the challenges you will face.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=0lJKucu6HJc&amp;t=1s">https://www.youtube.com/watch?v=0lJKucu6HJc&amp;t=1s</a></div>
<p> </p>
<p>Apologies if I mistakenly interpreted any of the points. I am still learning and trying to understand the startup journey.</p>
<p>Thanks for reading!</p>
<p><em>Keep Building (🧱,🚀)</em></p>
<hr />
<ul>
<li><p>Twitter <a target="_blank" href="https://twitter.com/megabyte0x">@megabyte0x</a></p>
</li>
<li><p>GitHub <a target="_blank" href="https://github.com/megabyte0x">@megabyte0x</a></p>
</li>
<li><p>Email contact@megabyte0x.xyz</p>
</li>
<li><p><a target="_blank" href="https://warpcast.com/megabyte">Farcaster</a> | <a target="_blank" href="https://hey.xyz/profile/0x01a79c">Lens</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Become a Delegator in Graph Protocol on ARB]]></title><description><![CDATA[gm gm gm!!!
It's been a great journey so far with The Graph Protocol on Ethereum but to scale and to provide the benefits of its services to everyone The Graph Protocol is now shifting to Arbitrum One.
With this shift, many changes are coming for the...]]></description><link>https://blog.megabyte.sh/delegator-in-graph-protocol-on-arb</link><guid isPermaLink="true">https://blog.megabyte.sh/delegator-in-graph-protocol-on-arb</guid><category><![CDATA[Ethereum]]></category><category><![CDATA[Blockchain]]></category><category><![CDATA[Arbitrum]]></category><category><![CDATA[staking]]></category><category><![CDATA[Blockchain technology]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Thu, 02 Nov 2023 04:13:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1698849250379/7c1fd36a-8a56-42b6-894d-b21e7d579d22.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>gm gm gm!!!</p>
<p>It's been a great journey so far with The Graph Protocol on Ethereum but to scale and to provide the benefits of its services to everyone The Graph Protocol is now shifting to Arbitrum One.</p>
<p>With this shift, many changes are coming for the community members, one of them is for <strong>Delegators.</strong></p>
<blockquote>
<p>If you are already a Delegator on the Ethereum Mainnet Network, head to this tutorial to shift your delegated GRT from Ethereum Mainnet to Arbitrum:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://yasshhh.hashnode.dev/a-guide-to-seamlessly-transferring-delegation-from-ethereum-mainnet-to-arbitrum">https://yasshhh.hashnode.dev/a-guide-to-seamlessly-transferring-delegation-from-ethereum-mainnet-to-arbitrum</a></div>
<p> </p>
</blockquote>
<p>But before going through the whole process it's better to know about Delegators and things to consider before delegating.</p>
<p><strong><em>Now LFG!!!!!!!🚀🚀🚀🚀🚀</em></strong></p>
<h1 id="heading-who-participates-in-delegating">WHO participates in Delegating?</h1>
<p>People who delegate(or stake) are known as <strong>Delegators,</strong> and...</p>
<p>Delegators are network participants who <strong>stake GRT</strong> to one or more Indexers.</p>
<blockquote>
<p>To learn about all the participants in The Graph Protocol, check this out:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1689630196427812864?s=20">https://twitter.com/megabyte0x/status/1689630196427812864?s=20</a></div>
<p> </p>
</blockquote>
<p>Many community members are not able to run their own Graph Node because it requires high technical skills and resources, but they can still <strong>contribute to the security of the network</strong> by being a Delegator. They don't need to run their node and contribute to the security by staking <strong>GRT</strong>.</p>
<h1 id="heading-benefits-from-delegating">BENEFITS from Delegating</h1>
<p>Upon staking or DELEGATING, they</p>
<ul>
<li><p><strong>earn fees by the cut from the Indexers' query Fees.</strong></p>
</li>
<li><p>Contribute to <strong>the security of the network.</strong></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694452178351/2e937b11-ba2d-4f44-9382-87ccc69b33df.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-things-to-consider-before-delegating">things to CONSIDER before Delegating</h1>
<p>There are several things one should consider before starting delegating:</p>
<ul>
<li><p><strong>Delegation Tax</strong></p>
<p>  When you delegate GRT, 0.5% of the total gets burned.</p>
<blockquote>
<p>For Example:</p>
<p>When you stake 100 GRT, 0.5 GRT will be burned.</p>
</blockquote>
<p>  This brings a bit of calculation to estimate the amount of time you need to wait to get back the Delegation Tax amount as a Reward Amount from the Indexer.</p>
</li>
<li><p><strong>Unbounding Period</strong></p>
<p>  If you want to undelegate (unstake) your <strong>GRT</strong> you will be required to wait for 28 days. During these 28 days, your <strong>GRT</strong> will be locked and earning NO REWARDS.</p>
</li>
<li><p><strong>Trustworthy Indexer</strong></p>
<p>  This is the most important thing to consider. <strong>YOU NEED TO CHOOSE YOUR INDEXER VERY WISELY.</strong></p>
<p>  There are two values you should look out for:</p>
<ul>
<li><p><strong>Indexing Rewards Cut:</strong> This value states the % of the rewards INDEXER will be keeping.</p>
<blockquote>
<p>For Example:</p>
<p>If the Indexing Rewards Cut is 80% that means INDEXER will be keeping 80% of the reward, and DELEGATOR(YOU) will be getting 20% of the reward.</p>
</blockquote>
</li>
<li><p><strong>Query Fee Cut:</strong> This works exactly like the Indexing Rewards Cut ☝🏻 but there's one more thing to consider, <strong>Query Fee Rewards increase with time based upon the activity of the network.</strong></p>
<blockquote>
<p>Keep an eye on the network activity, more activity means more query rewards means more Query Fee Cut Rewards.</p>
</blockquote>
</li>
</ul>
</li>
</ul>
<p>    You can calculate your <strong>approximate rewards</strong> using the below formulas for getting the most out of the Indexers:</p>
<p>    <img src="https://thegraph.com/docs/_next/static/media/Delegation-Reward-Formula.830d3733.png" alt="Delegation Image 3" /></p>
<ul>
<li><p><strong>Indexer Delegation Pool</strong></p>
<p>  Every delegator owns the number of shares proportional to the <strong>GRT</strong> they delegated into the pool.</p>
<p>  It's simple math, the more share you own more rewards you will be collecting than others.</p>
<p>  <img src="https://thegraph.com/docs/_next/static/media/Share-Forumla.5d1b4e4a.png" alt="Share formula" /></p>
</li>
<li><p><strong>Considering the delegation capacity</strong></p>
<p>  Currently, the Delegation Ratio is set to 16, which means if the Indexer has staked 1M <strong>GRT</strong> then the max capacity is 16M <strong>GRT</strong>.</p>
<p>  Butttttt.... if users staked in a total of 18M <strong>GRT</strong> to this indexer, then the extra 2M (18M-16M) <strong>GRT</strong> will not be used for earning rewards.</p>
</li>
</ul>
<blockquote>
<p>oooooofff...😮‍💨 a lot of things to CONSIDERRRRR....😩</p>
<p>but remember: "Hard💪🏻 stuff brings the best rewards."</p>
</blockquote>
<p>Let's have some action now!!</p>
<h1 id="heading-actually-delegating">actually DELEGATING!</h1>
<p>Now let's play with some <em>GRT Tokens...</em></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">🔴</div>
<div data-node-type="callout-text">[NOT A FINANCIAL ADVICE] The next part is only for LEARNING purposes, none of it is FINANCIAL ADVICE.</div>
</div>

<h2 id="heading-prerequisites">prerequisites</h2>
<ul>
<li><p><strong>GRT</strong> either on Ethereum Mainnet or Arbitrum One</p>
</li>
<li><p>Native ETH on Arbitrum One.</p>
</li>
<li><p>Calculator 😂 (It's for you I am good at math 😏)</p>
</li>
</ul>
<h2 id="heading-getting-grt-on-arb">getting GRT on ARB</h2>
<p>if you have <strong>GRT</strong> on ARB already, congrats! You are one step ahead and can move to the next section.</p>
<p>For those who don't have <strong>GRT</strong> on ARB, let's experience some true web3 UX 😜</p>
<h3 id="heading-bridging-eth-from-ethereum-mainnet-to-arbitrum-one">bridging ETH from Ethereum Mainnet to Arbitrum One</h3>
<p>To get your GRT from Ethereum Mainnet to Arbitrum One you need to bridge it, and for that follow the steps:</p>
<ol>
<li><p>Head to the Official Arbitrum Bridge (<a target="_blank" href="https://bridge.arbitrum.io/">https://bridge.arbitrum.io/</a>)</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694456485355/3a231a41-d384-49f5-88bd-47ea2a0fb6cc.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Connect your wallet and select <strong>GRT,</strong> <strong>Ethereum Mainnet (FROM)</strong> and <strong>Arbitrum ONE (TO)</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694456663366/64101e34-832f-457a-a07f-10f66fce2da9.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Enter the amount of <strong>GRT</strong> you want to bridge.</p>
</li>
<li><p>Click on <strong>"Move funds to Arbitrum One"</strong> and approve and confirm the transaction.</p>
</li>
<li><p>Now wait!!!</p>
</li>
</ol>
<blockquote>
<p>After tremendous anxiety full waiting, you are ready to delegate.</p>
</blockquote>
<h2 id="heading-choosing-and-analyzing-the-indexer">choosing and analyzing the INDEXER</h2>
<p>To earn with full potential Indexers need to be transparent and honest, this will help you and other Delegators in analyzing and calculating their true rewards.</p>
<p>Follow these steps:</p>
<ul>
<li><p>Head to <strong>Indexers on Arbitrum Network in the Graph Explorer</strong> (<a target="_blank" href="https://thegraph.com/explorer/participants/indexers?chain=arbitrum-one">https://thegraph.com/explorer/participants/indexers?chain=arbitrum-one</a>)</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694457148459/68fded37-cd81-441f-bb3e-2f06b5052768.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Connect your wallet and sign in to The Graph Explorer.</p>
</li>
<li><p>1st thing to consider is to choose an Indexer from both tech and non-technical perspectives.</p>
  <div data-node-type="callout">
  <div data-node-type="callout-emoji">⚠</div>
  <div data-node-type="callout-text">NOTE: I am choosing some random. [YOU ARE NOT AT ALL ADVISED TO CHOOSE THE SAME]</div>
  </div>

<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694458709929/acc844be-9b4c-41e9-a61e-28831da2c69d.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Analyzing the factors:</p>
<p>  From the above image, we have the following parameters:</p>
  <details><summary>Max Capacity: 3.4M and Delegation Received: 1.6M</summary><div data-type="detailsContent">This means only <strong>1.8M</strong> [3.4-1.6] tokens will earn rewards.</div></details><details><summary>Indexing Reward Cut: 27%</summary><div data-type="detailsContent">This means you [Delegators] will receive only<strong> 73%</strong> of the Indexing Reward.</div></details><details><summary>Query Fee Cut: 80%</summary><div data-type="detailsContent">This means you [Delegators] will receive only <strong>20%</strong> of the Query Fee Reward.</div></details>

</li>
</ul>
<h2 id="heading-final-steps">final steps!!</h2>
<p>I am fine with the amount I'll be receiving, so I'll be following these steps:</p>
<ul>
<li><p>click on <strong>"Delegate"</strong></p>
</li>
<li><p>enter the <strong>amount of GRT I want to delegate(stake),</strong> i.e., 1000.</p>
</li>
<li><p><strong>grant Access</strong> to the <strong>GRT</strong> tokens</p>
</li>
<li><p>hit "<strong>DELEGATE"</strong></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1698411640077/2c8429c1-e9e4-4543-bdb5-754c5274d33c.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p>Congrats 🥳🥳🥳 You have Delegated GRT and now you are contributing to the security💪🏻 of the network while earning rewards!💰!</p>
</blockquote>
<hr />
<p>You can see your delegated amount and other details by clicking on your profile and selecting the <strong>delegating tab.</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694462024940/9f4dd1f2-902d-46f8-94cb-982e1ddcd2ec.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694462161955/560f3f35-108b-4d6d-96c2-c768325871e8.png" alt class="image--center mx-auto" /></p>
<hr />
<h1 id="heading-references">References</h1>
<ul>
<li><p><a target="_blank" href="https://thegraph.com/docs/en/network/delegating/">Graph Docs</a></p>
</li>
<li><p><a target="_blank" href="https://thegraph.com/explorer/participants/indexers?chain=arbitrum-one">Graph Explorer</a></p>
</li>
</ul>
<hr />
<p>If you learned something from this blog, do consider sharing your learnings with me through DM either on <a target="_blank" href="https://www.twitter.com/megabyte0x"><em>Twitter</em></a> <em>or</em> <a target="_blank" href="https://linkedin.com/in/megabyte0x"><em>LinkedIn</em></a> <em>or</em> <a target="_blank" href="https://lenster.xyz/u/megabyte0x"><em>Lenster.</em></a></p>
<blockquote>
<p>To keep learning about The Graph Protocol join me with <a target="_blank" href="https://t.me/TheGraph_India">The Graph Protocol India.</a></p>
</blockquote>
<p><strong><em>Happy Learning 🙌🏻</em></strong></p>
<p><strong><em>Keep BUIDLing 🧱🚀</em></strong></p>
]]></content:encoded></item><item><title><![CDATA[Building a TokenSwap Subgraph]]></title><description><![CDATA[gm gm gm!!!
Indexing Blockchain Data is really really hard and indexing transactions of something like Uniswap is a lethal task. But The Graph Protocol greatly reduces the complexity of this.
We will be learning how to build, deploy, and play with Su...]]></description><link>https://blog.megabyte.sh/building-token-swap-subgraph</link><guid isPermaLink="true">https://blog.megabyte.sh/building-token-swap-subgraph</guid><category><![CDATA[subgraph]]></category><category><![CDATA[GraphQL]]></category><category><![CDATA[Blockchain]]></category><category><![CDATA[Ethereum]]></category><category><![CDATA[Solidity]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Fri, 27 Oct 2023 05:52:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1694020968182/ad8d2e56-b8ac-4427-964a-15f3c2904756.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>gm gm gm!!!</p>
<p><em>Indexing Blockchain Data is really really hard</em> and indexing transactions of something like <a target="_blank" href="https://uniswap.org/">Uniswap</a> is a lethal task. But <a target="_blank" href="https://thegraph.com/"><strong>The Graph Protocol</strong></a> greatly reduces the complexity of this.</p>
<p>We will be learning how to build, deploy, and play with Subgraph for a simple Token Swapping Contract.</p>
<p>The following are the prerequisites for this tutorial:</p>
<ul>
<li><p>Basic Solidity and GraphQL understanding.</p>
</li>
<li><p><a target="_blank" href="https://classic.yarnpkg.com/lang/en/docs/install/">Yarn</a></p>
</li>
<li><p><a target="_blank" href="https://remix.ethereum.org/">Remix</a></p>
</li>
<li><p><a target="_blank" href="https://code.visualstudio.com/download">VS Code</a></p>
</li>
</ul>
<hr />
<h1 id="heading-building-the-token-swap-contract">Building the Token Swap Contract</h1>
<p>This is the Token Swap Contract we will be using for our example.</p>
<div class="gist-block embed-wrapper" data-gist-show-loading="false" data-id="2877d16843008371ff19cc93a3ac778d"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a href="https://gist.github.com/megabyte0x/2877d16843008371ff19cc93a3ac778d" class="embed-card">https://gist.github.com/megabyte0x/2877d16843008371ff19cc93a3ac778d</a></div><p> </p>
<p>The following are the main functions we will be focusing on in our subgraph:</p>
<ul>
<li><p><code>addLiquidity(uint256 _tokenAmount)</code>: This adds liquidity to the pool and emits <code>GraphKitExchange__LiquidityAdded</code> event.</p>
</li>
<li><p><code>removeLiquidity(uint256 _amount)</code>: This removes liquidity from the pool and emits <code>GraphKitExchange__LiquidityRemoved</code> event.</p>
</li>
<li><p><code>ethToTokenSwap(uint256 _minTokens)</code>: This swaps ETH to the Token and emits <code>GraphKitExchange__ETHToTokenSwap</code> event.</p>
</li>
<li><p><code>tokenToETHSwap(uint256 tokenSold, uint256 minTokens)</code>: This swaps Token to ETH and emits <code>GraphKitExchange__TokenToETHSwap</code> event.</p>
</li>
</ul>
<p>Having these above events is important as the Graph Nodes will be listening to these events and storing the data (defined in schema) as it gets emitted.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">To learn more about Events in Solidity, check <a target="_blank" href="https://www.youtube.com/watch?v=sas02qSFZ74&amp;t=12120s">this</a> out.</div>
</div>

<p>This is the Basic ERC20 Contract we will be using:</p>
<div class="gist-block embed-wrapper" data-gist-show-loading="false" data-id="1cd407947d578059235287cc275f5f0d"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a href="https://gist.github.com/megabyte0x/1cd407947d578059235287cc275f5f0d" class="embed-card">https://gist.github.com/megabyte0x/1cd407947d578059235287cc275f5f0d</a></div><p> </p>
<hr />
<h1 id="heading-deploy-the-contracts">Deploy the Contracts</h1>
<p>Now deploy these contracts using Remix on Polygon Munbai Testnet.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">⚠</div>
<div data-node-type="callout-text">Make sure to deploy <code>Token.sol</code> first and then use that contract address and deploy <code>GraphKitExchange.sol</code></div>
</div>

<p>Head to your <a target="_blank" href="https://remix.ethereum.org/">Remix IDE</a> and follow the steps:</p>
<ol>
<li><p>Connect with the Injected Provider and select Polygon Mumbai Testnet as the network.</p>
</li>
<li><p>Get some <strong>TEST MATIC</strong> on Mumbai Testnet from the Faucet, <a target="_blank" href="https://faucet.polygon.technology/">here</a>.</p>
</li>
<li><p>Deploy <code>Token.sol</code></p>
<ol>
<li><p>Copy the above contract and paste it into the Remix file.</p>
</li>
<li><p>Then select the contract and enter the constructor parameters. I have entered <code>MEGABYTE</code>,<code>MB</code> and <code>100000000000000000000</code></p>
</li>
<li><p>Hit Transact.</p>
</li>
</ol>
</li>
</ol>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693137850817/9aef89e0-3162-4dd8-897c-86a3d5f1088f.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>Copy the above GraphKitExchange code and paste the content of <code>GraphKitExchange.sol</code> in the Remix File.</p>
</li>
<li><p>Copy the <code>Token.sol</code> Contract Address</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693135922129/b1d0c93c-d3b8-4c3f-821a-52fcd49e70b6.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Select the GraphKitExchange.sol, paste the Token Contract Address, and hit Transact.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693135989441/6c457f82-1f84-4cc0-adf9-443878d6edcc.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Verify the contracts on the <a target="_blank" href="https://mumbai.polygonscan.com/">Mumbai Scan</a></p>
<blockquote>
<p>Learn how to do it <a target="_blank" href="https://www.quicknode.com/guides/ethereum-development/smart-contracts/different-ways-to-verify-smart-contract-code#method-3-verify-via-remixide--etherscan-plug-in">here</a>.</p>
</blockquote>
</li>
<li><p>Keep both the contract addresses handy, we will be using them shortly.</p>
<blockquote>
<p>Here are mine though:<br />Token Contract: <a target="_blank" href="https://mumbai.polygonscan.com/address/0xB2887fA56b2601cB5877A99188c3f23731F671F5">0xB2887fA56b2601cB5877A99188c3f23731F671F5</a></p>
<p>Exchange Contract: <a target="_blank" href="https://mumbai.polygonscan.com/address/0xd8F178e60F3A7434F0F4E2519e6C2B89575f8123">0xd8F178e60F3A7434F0F4E2519e6C2B89575f8123</a></p>
</blockquote>
</li>
</ol>
<hr />
<blockquote>
<p>Congrats your contracts are ready 🔥</p>
<p>Let's deploy the Subgraph for the same 🚀</p>
</blockquote>
<hr />
<h1 id="heading-build-the-subgraph">Build the Subgraph</h1>
<p>To build the Subgraph, these are the steps that need to be followed:</p>
<ul>
<li><p>Create a Subgraph on Subgraph Studio.</p>
</li>
<li><p>Install the Graph Protocol CLI</p>
</li>
<li><p>Initialize your Subgraph⁠</p>
</li>
<li><p>Deploying a Subgraph to Subgraph Studio</p>
</li>
</ul>
<blockquote>
<p>Before building the subgraph, if you wanna revisit the concepts of Subgraph check this out 👇🏻</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1689177201147805696">https://twitter.com/megabyte0x/status/1689177201147805696</a></div>
<p> </p>
</blockquote>
<h2 id="heading-create-a-subgraph-on-subgraph-studio">Create a subgraph on Subgraph Studio</h2>
<ol>
<li><p>Head to <a target="_blank" href="https://thegraph.com/studio">https://thegraph.com/studio</a></p>
</li>
<li><p>Create Subgraph on Polygon Mumbai Testnet</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693137682942/bbf55fac-e7f6-410b-a582-0d985eb926a7.png" alt class="image--center mx-auto" /></p>
<ol>
<li>Keep the <strong>Subgraph Slug</strong> and <strong>Deploy Key</strong> handy.</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693138083744/3a972c77-9ccf-46bb-b692-0bf9e459e9fd.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-install-the-graph-protocol-cli">Install the Graph Protocol CLI</h2>
<p>You need to install <code>graph-cli</code> to use the Subgraph Studio from your system.</p>
<p>Follow the steps for installing it:</p>
<ol>
<li><p>Open up your terminal.</p>
</li>
<li><p>Paste the following command and hit ENTER:</p>
<pre><code class="lang-bash"> yarn global add @graphprotocol/graph-cli
</code></pre>
</li>
</ol>
<h2 id="heading-initialize-your-subgraph">Initialize your Subgraph⁠</h2>
<p>It's time to start working on your Subgraph:</p>
<ol>
<li><p>Create a new directory.</p>
<p> <code>mkdir tokenSwapSubgraph</code></p>
</li>
<li><p>Initialize the subgraph [Paste your subgraph slug]</p>
<p> <code>graph init --studio &lt;SUBGRAPH_SLUG&gt;</code></p>
</li>
<li><p>Choose <code>ethereum</code> as the protocol</p>
</li>
<li><p>Enter the subgraph slug name</p>
</li>
<li><p>Name the directory.</p>
</li>
<li><p>Select <code>mumbai</code> as the Ethereum Network</p>
</li>
<li><p>Enter the Contract Address for <code>GraphKitExchange.sol</code> contract.</p>
</li>
<li><p>Use the default start block.</p>
</li>
<li><p>Enter the name of the contract, here is <code>GraphKitExchange</code></p>
</li>
<li><p>Select <code>true</code> for <strong>the index contract event as entities</strong></p>
</li>
<li><p>Type <code>y</code> for entering a new contract address (for <code>Token.sol</code>)</p>
</li>
<li><p>Type <code>n</code> for providing local ABI path.</p>
</li>
<li><p>Enter the name of the contract, here is <code>Token</code></p>
</li>
</ol>
<p>Here's how it will look in your terminal 👇🏻</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693141891831/6ca51d7f-3321-4607-bdbf-92364cc70240.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693141908775/4f10f8a1-a851-4e36-bb9e-8dd444e4022c.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>Go to your subgraph directory</p>
<p> <code>cd graphkitexchange</code></p>
<p> In the directory, you can see the following files:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693143605841/d1d09396-6929-407c-bcaa-362600e52d76.png" alt class="image--center mx-auto" /></p>
<p> In the <code>src</code> directory you will see that it auto-generated the mappings for your subgraph as per the events in your contracts.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693143672187/e5cc4fa5-885f-4423-9138-b162c34c1d2c.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<blockquote>
<p>Your Subgraph is ready now. It's time to deploy it.</p>
</blockquote>
<h2 id="heading-deploy-the-subgraph">Deploy the Subgraph</h2>
<p>We are almost done! Let's deploy our subgraph.</p>
<ol>
<li><p>Authenticate your Graph Studio Key [Get Deploy Key from your subgraph studio]</p>
<pre><code class="lang-bash"> graph auth --studio &lt;DEPLOY KEY&gt;
</code></pre>
</li>
<li><p>Deploy your subgraph with your <code>subgraph slug</code></p>
<pre><code class="lang-bash"> graph deploy --studio graphkitexchange
</code></pre>
</li>
<li><p>Enter the <code>v0.0.1</code> as the version for your subgraph</p>
</li>
<li><p>In the end, you will see this 👇🏻</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693143955284/5daa5f9a-a7b1-41bb-a756-4a0abf24ceac.png" alt class="image--center mx-auto" /></p>
<p> Here you got the <mark>subgraph endpoint, </mark> <a target="_blank" href="https://api.studio.thegraph.com/query/48418/graphkitexchange/v0.0.1">https://api.studio.thegraph.com/query/48418/graphkitexchange/v0.0.1</a></p>
</li>
</ol>
<blockquote>
<p>Whoo!!! That's a lot of work! But congrats 🤩 You deployed your subgraph for a Token Swapping Contract.</p>
</blockquote>
<h1 id="heading-play-with-the-subgraph-using-subgraph-studio">Play with the Subgraph using Subgraph Studio</h1>
<p>So, it's time to use a decentralized, most effective and inexpensive way of querying the blockchain data.</p>
<p>I'll be using a Subgraph Playground for the same. [Not a frontend dev... hehe]</p>
<h2 id="heading-creating-txn-on-the-contracts">Creating Txn on the contracts</h2>
<p>Before using the subgraph we need to create some transactions so we can query them.</p>
<p>Follow the steps to approve <code>GraphKitExchange</code>'s contract address on <code>Token</code> Contract.</p>
<ol>
<li><p>Open your <code>Token.sol</code> contract on Mumbai Scan, and head towards the <code>Contract</code> Tab. <a target="_blank" href="https://mumbai.polygonscan.com/address/0xB2887fA56b2601cB5877A99188c3f23731F671F5#code"><em>Here's mine.</em></a></p>
</li>
<li><p>Click on the <code>Write</code> tab below <code>Contract</code> tab. <em>Since you have already verified the contract, you will be able to Write transactions on it using the Etherscan UI.</em></p>
</li>
<li><p>Connect your Metamask with the Etherscan by clicking on <code>Connect to Web3</code></p>
</li>
<li><p>Now head to the <code>approve</code> function and open the modal.</p>
</li>
<li><p>Enter the address of the <code>GraphKitExchange</code> contract address and the amount in <code>wei</code></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693510431413/53f78846-0f4d-4489-b0ea-130d57be35ea.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on <code>Write</code> and confirm the transaction.</p>
</li>
</ol>
<div data-node-type="callout">
<div data-node-type="callout-emoji">😀</div>
<div data-node-type="callout-text">Since we have approved <strong>5 MB </strong>to <strong>GraphKitExchange Contract</strong> it's time to add some Liquidity into the contract.</div>
</div>

<p>Follow these steps to create your first transaction on the <code>GraphKitExchange</code> Contract:</p>
<ol>
<li><p>Open your <code>GraphKitExchange.sol</code> contract on Mumbai Scan, and head towards the <code>Contract</code> Tab. <a target="_blank" href="https://mumbai.polygonscan.com/address/0xd8F178e60F3A7434F0F4E2519e6C2B89575f8123#code"><em>Here's mine.</em></a></p>
</li>
<li><p>Click on the <code>Write</code> tab below <code>Contract</code> tab. <em>Since you have already verified the contract, you will be able to Write transactions on it using the Etherscan UI.</em></p>
</li>
<li><p>Connect your Metamask with the Etherscan by clicking on <code>Connect to Web3</code></p>
</li>
<li><p>Click on <code>addLiquidity</code> and enter the 5 Matic and 5 MB (in wei) into the respective fields.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693510952482/66c8aba4-0104-42fd-9fc9-797b4d8ae11f.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on <code>Write</code> and confirm the transaction.</p>
</li>
<li><p>You will see a <code>View Transaction</code> button, click on it and copy the <code>transaction hash</code></p>
</li>
</ol>
<blockquote>
<p>Voila! We are good to go with our subgraph.</p>
</blockquote>
<h2 id="heading-querying-the-subgraph">Querying the Subgraph</h2>
<p>Now we have a transaction ready in your GraphKitExchange Contract waiting to be queried by us.</p>
<p>Let's do this, by following these steps:</p>
<ol>
<li><p>Head to your deployed Subgraph and select the playground. Mine is <a target="_blank" href="https://thegraph.com/studio/subgraph/graphkitexchange/playground">https://thegraph.com/studio/subgraph/graphkitexchange/playground</a></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693509839817/5d64bd1f-2b70-45ba-9e24-f540da489a88.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now paste this into the query</p>
<pre><code class="lang-graphql"> <span class="hljs-keyword">query</span> MyQuery {
   graphKitExchangeLiquidityAddeds 
 (<span class="hljs-symbol">where:</span> {<span class="hljs-symbol">transactionHash:</span> <span class="hljs-string">"Your Transaction Hash"</span>}){
     _ethAmount
     _lpAmount
     _tokenAmount
     _user
   }
 }
</code></pre>
 <div data-node-type="callout">
 <div data-node-type="callout-emoji">💢</div>
 <div data-node-type="callout-text">In "Your Transaction Hash" be sensible and paste your transaction hash 😂</div>
 </div>

<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693511663832/f72e3998-0962-41e8-b148-7585a9f752fa.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now click on that <strong>YOUTUBE PLAY BUTTON</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693511706315/8847b6bb-f25b-42a3-979f-cf27dfa6c18b.png" alt class="image--center mx-auto" /></p>
<p> As you can see on the right side we got this 👇🏻</p>
<pre><code class="lang-json"> {
   <span class="hljs-attr">"data"</span>: {
     <span class="hljs-attr">"graphKitExchangeLiquidityAddeds"</span>: 
       [{
         <span class="hljs-attr">"_ethAmount"</span>: <span class="hljs-string">"5000000000000000000"</span>,
         <span class="hljs-attr">"_lpAmount"</span>: <span class="hljs-string">"5000000000000000000"</span>,
         <span class="hljs-attr">"_tokenAmount"</span>: <span class="hljs-string">"5000000000000000000"</span>,
         <span class="hljs-attr">"_user"</span>: <span class="hljs-string">"0x1cb30cb181d7854f91c2410bd037e6f42130e860"</span>
       }]
     }
 }
</code></pre>
<p> It has the same data we emitted in our <code>GraphKitExchange__LiquidityAdded</code> but we didn't require to have the node setup or to some centralised node provided for this query.</p>
<p> Querying with The Graph Protocol is superfast, decentralized and inexpensive.</p>
</li>
<li><p>TASK: Use the rest of the functions and query the subgraph for the events they emit.</p>
</li>
</ol>
<hr />
<h1 id="heading-reference-links">Reference Links</h1>
<ul>
<li><p><a target="_blank" href="https://jeiwan.net/posts/programming-defi-uniswap-1/">Uniswap Book [V1 Part -1]</a></p>
</li>
<li><p><a target="_blank" href="https://jeiwan.net/posts/programming-defi-uniswap-2/">Uniswap Book [V1 Part -2]</a></p>
</li>
<li><p><a target="_blank" href="https://jeiwan.net/posts/programming-defi-uniswap-3/">Uniswap Book [V1 Part -3]</a></p>
</li>
<li><p><a target="_blank" href="https://thegraph.com/docs/en/developing/creating-a-subgraph/">Graph Docs</a></p>
</li>
</ul>
<hr />
<p>I hope you have learned something today with this quite long blog.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">😁</div>
<div data-node-type="callout-text">To learn more about <strong>The Graph Protocol</strong>, join me with <a target="_blank" href="https://t.me/TheGraph_India">The Graph India Community</a></div>
</div>

<p>If you have any queries, DM me on <a target="_blank" href="https://twitter.com/megabyte0x">Twitter</a>, <a target="_blank" href="https://lenster.xyz/u/megabyte0x">Lenster</a> or <a target="_blank" href="https://linkedin.com/in/megabyte0x">LinkedIn</a>.</p>
<p>Happy Learning 🙌🏻</p>
<p><strong><em>Keep Building 🧱🚀</em></strong></p>
]]></content:encoded></item><item><title><![CDATA[Deploy your OWN Hyperlane]]></title><description><![CDATA[gm gm gm!!!Hyperlane is a Permissionless Protocol which means that anyone can deploy their own Hyperlane Protocol on any chain without requiring any permission from the core team.
In this tutorial, we will learn how to deploy Hyperlane on Polygon zkE...]]></description><link>https://blog.megabyte.sh/deploy-your-own-hyperlane</link><guid isPermaLink="true">https://blog.megabyte.sh/deploy-your-own-hyperlane</guid><category><![CDATA[Solidity]]></category><category><![CDATA[Blockchain]]></category><category><![CDATA[crosschain bridge]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[Ethereum]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Thu, 21 Sep 2023 06:01:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1694936945010/8872b468-d139-4873-87e0-6c4aa3f0af1b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>gm gm gm!!!<br /><strong><em>Hyperlane is a Permissionless Protocol</em></strong> which means that anyone can deploy their own Hyperlane Protocol on any chain without requiring any permission from the core team.</p>
<p>In this tutorial, we will learn how to deploy Hyperlane on <a target="_blank" href="https://wiki.polygon.technology/docs/zkevm/">Polygon zkEVM</a> Testnet, <a target="_blank" href="https://wiki.polygon.technology/docs/pos/getting-started/">Polygon</a> Mumbai Testnet and Sepolia.</p>
<p>There are 5 steps we need to follow so LFG🚀</p>
<h1 id="heading-prerequisites">Prerequisites</h1>
<ul>
<li><p><a target="_blank" href="https://classic.yarnpkg.com/lang/en/docs/cli/install/">Yarn</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/">Git and GitHub Knowledge</a></p>
</li>
<li><p>Understanding of Blockchain</p>
</li>
<li><p>Solidity Experience (BONUS)</p>
</li>
</ul>
<blockquote>
<p>Before moving forward, if you like to understand Hyperlane in-depth (which you should!) check this out:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://blog.megabyte0x.xyz/a-z-of-hyperlane">https://blog.megabyte0x.xyz/a-z-of-hyperlane</a></div>
<p> </p>
</blockquote>
<h1 id="heading-setup-keys">Setup Keys</h1>
<p>When you deploy Hyperlane Protocol it includes Smart Contracts, Validators and Relayers therefore we will be requiring <strong>Key Pair</strong> for each of them.</p>
<h2 id="heading-keys-for-deployment">Keys for Deployment</h2>
<p>To deploy smart contracts you will need to have a <strong>key pair</strong> with the funds for all the chains you will be deploying.</p>
<p>To create the <strong>key pair</strong>, follow the steps:</p>
<ul>
<li><p>Open your Terminal and enter the following command</p>
<pre><code class="lang-bash">  cast wallet new
</code></pre>
<p>  This will generate a new <strong>key pair</strong> for you, which will look like this 👇🏻</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1695271307360/af69b0d0-75a9-421b-b7c2-53147bc13899.png" alt class="image--center mx-auto" /></p>
  <div data-node-type="callout">
  <div data-node-type="callout-emoji">⚠</div>
  <div data-node-type="callout-text">THIS IS A TESTING WALLET.</div>
  </div>
</li>
<li><p>Save your Public Address and Private Key.</p>
</li>
<li><p>Fund your Address with the tokens of all the networks.</p>
<ul>
<li><p>For ETH on Polygon zkEVM Testnet and Polygon Mumbai Testnet use <a target="_blank" href="https://faucet.polygon.technology/">Polygon Faucet.</a></p>
</li>
<li><p>For ETH on Sepolia use <a target="_blank" href="https://sepoliafaucet.com/">Alchemy Faucet</a>.</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-keys-for-validators">Keys for Validators</h2>
<p>For this tutorial, we will be using the default <a target="_blank" href="https://docs.hyperlane.xyz/docs/protocol/sovereign-consensus/multisig-ism">Hyperlane's Multisig ISM</a>. Multisig ISM is a module that takes several signatures from validators before completing the transaction. Therefore, we will be using <strong>4 addresses</strong> with threshold <strong>one</strong>.</p>
<p>You can take any 4 of your Public Addresses, and keep them handy for later use.</p>
<blockquote>
<p>Make sure to have a Private Key secured for the Public addresses you will be using.<br />You can generate Key Pairs using the above method.</p>
</blockquote>
<h1 id="heading-setting-up-the-repo">Setting up the Repo</h1>
<p>The Hyperlane Core team provided us with a repository that you can use to deploy Hyperlane on your preferred chain.</p>
<p>Follow these steps to set up the Hyperlane Deployment repo:</p>
<ul>
<li><p>Open your terminal at your preferred directory.</p>
</li>
<li><pre><code class="lang-bash">    git <span class="hljs-built_in">clone</span> https://github.com/hyperlane-xyz/hyperlane-deploy.git
</code></pre>
</li>
<li><pre><code class="lang-bash">    <span class="hljs-built_in">cd</span> hyperlane-deploy
</code></pre>
</li>
<li><pre><code class="lang-bash">    yarn install
</code></pre>
</li>
</ul>
<h1 id="heading-adding-the-custom-chain">Adding the custom chain</h1>
<p>Hyperlane's core team has provided a few chains in the SDK. You can check them out <a target="_blank" href="https://docs.hyperlane.xyz/docs/resources/addresses">here</a>.</p>
<p>To add a chain apart from the provided chains, follow these steps:</p>
<ul>
<li><p>Open <code>config/chains.ts</code> There you will find the configuration example for adding new chains.</p>
</li>
<li><p>Add the following configuration for the Polygon zkEVM Testnet:</p>
<pre><code class="lang-typescript">    polygonzkevmtestnet: {
      name: <span class="hljs-string">'polygonzkevmtestnet'</span>,
      chainId: <span class="hljs-number">1442</span>,
      protocol: ProtocolType.Ethereum,
      nativeToken: {
        name: <span class="hljs-string">'ether'</span>,
        symbol: <span class="hljs-string">'ETH'</span>,
        decimals: <span class="hljs-number">18</span>,
      },
      rpcUrls: [
        {
          http: <span class="hljs-string">'https://rpc.public.zkevm-test.net'</span>,
        },
      ],
      blockExplorers: [
        {
          name: <span class="hljs-string">'Polygon Scan'</span>,
          url: <span class="hljs-string">'https://testnet-zkevm.polygonscan.com'</span>,
          apiUrl: <span class="hljs-string">'https://api-zkevm.polygonscan.com/api'</span>,
        },
      ],
      isTestnet: <span class="hljs-literal">true</span>,
    },
</code></pre>
</li>
</ul>
<h1 id="heading-adding-the-validator-keys">Adding the Validator Keys</h1>
<p>For this tutorial, we are using the default <a target="_blank" href="https://docs.hyperlane.xyz/docs/protocol/sovereign-consensus/multisig-ism">Multisig</a> as our Interchain Security Module.</p>
<p>Follow these steps, for setting up the keys:</p>
<ul>
<li><p>Open <code>config/multisig_ism.ts</code>. There you will find the configuration example for adding new chains and their keys.</p>
</li>
<li><p>Add the keys for your validator:</p>
<pre><code class="lang-typescript">    polygonzkevmtestnet: {
      threshold: <span class="hljs-number">1</span>,
      <span class="hljs-keyword">type</span>: ModuleType.LEGACY_MULTISIG,
      validators: [
        <span class="hljs-string">'0xabcabcabcabcabcabcabcabcabcabcabcabcabca'</span>,
        <span class="hljs-string">'0xabcabcabcabcabcabcabcabcabcabcabcabcabca'</span>,
        <span class="hljs-string">'0xabcabcabcabcabcabcabcabcabcabcabcabcabca'</span>,
        <span class="hljs-string">'0xabcabcabcabcabcabcabcabcabcabcabcabcabca'</span>,
      ],
    },
</code></pre>
</li>
<li><p><code>threshold</code> is 1 which means only one of the validator's signatures is required.</p>
</li>
</ul>
<blockquote>
<p>Woohoooo!!! You are done with the setup for the deployment of HYPERLANE on Polygon zkEVM testnet with remotes Mumbai and Sepolia.</p>
</blockquote>
<hr />
<h1 id="heading-deploying-the-hyperlane">Deploying the Hyperlane</h1>
<p>To deploy Hyperlane, run the following command on your terminal.</p>
<pre><code class="lang-bash">DEBUG=hyperlane* yarn ts-node scripts/deploy-hyperlane.ts --<span class="hljs-built_in">local</span> polygonzkevmtestnet \
  --remotes mumbai sepolia \
  --key 0xbeda2b3910bae7dbfb4e65e9c0931f001066d4f0df257b77ad55093fa271bde2
</code></pre>
<p>In the above command,</p>
<ul>
<li><p>we are running the <code>deploy-hyperlane.ts</code> script</p>
</li>
<li><p>with <code>polygonzkevmtestnet</code> as <code>local</code> chain and</p>
</li>
<li><p><code>mumbai</code> and <code>sepolia</code> as remotes. Since <code>mumbai</code> and <code>sepolia</code> are already provided by the Hyperlane SDK we don't need to add the configurations again.</p>
</li>
<li><p>the value after <code>key</code> param is your <strong>private key</strong> to the address that contains funds for all the networks.</p>
</li>
</ul>
<p>After running the command, wait for a few minutes till your terminal looks like this 👇🏻</p>
<hr />
<p>Congrats!!! You just <strong>Deployed</strong> Hyperlane on Polygon zkEVM Testnet.</p>
<p>But to test this out, you will need to run your Validators and Relayers for all the chains you deployed (local + remote). To learn how to setup Validators and Relayers check them out 👇🏻</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://blog.hyperlaneindia.xyz/hyperlane-relayers-setup-guide">https://blog.hyperlaneindia.xyz/hyperlane-relayers-setup-guide</a></div>
<p> </p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://blog.hyperlaneindia.xyz/hyperlane-validators-setup-guide">https://blog.hyperlaneindia.xyz/hyperlane-validators-setup-guide</a></div>
<p> </p>
<hr />
<p>Thanks for going through the whole blog, I hope you learned something today.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">If you wanna explore more check out the <a target="_blank" href="https://docs.hyperlane.xyz">Hyperlane Docs</a>, and if you have any queries get them resolved in <a target="_blank" href="http://t.me/c/1264208834/1">Hyperlane India Telegram Channel.</a></div>
</div>

<p>Let me know if you have any doubts on <a target="_blank" href="https://twitter.com/megabyte0x"><em>Twitter</em></a><em>,</em> <a target="_blank" href="https://lenster.xyz/u/megabyte0x"><em>Lenster</em></a> <em>or</em> <a target="_blank" href="https://linkedin.com/in/megabyte0x"><em>LinkedIn</em></a><em>.</em></p>
<p><strong><em>Happy Learning 🙌🏻</em></strong></p>
<p><strong><em>Keep Building 🧱🚀</em></strong></p>
]]></content:encoded></item><item><title><![CDATA[A-Z of Hyperlane]]></title><description><![CDATA[gm gm gm!!!
Even with the vast network of blockchain, with 1000s of nodes and 100s of chains (L1, L2, L3....) the users are getting restricted in utilizing the complete potential of the decentralized network. Reason? Some application works on ETH, so...]]></description><link>https://blog.megabyte.sh/a-z-of-hyperlane</link><guid isPermaLink="true">https://blog.megabyte.sh/a-z-of-hyperlane</guid><category><![CDATA[Solidity]]></category><category><![CDATA[Blockchain]]></category><category><![CDATA[Polygon]]></category><category><![CDATA[Ethereum]]></category><category><![CDATA[hyperlane]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Sat, 02 Sep 2023 11:32:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1694094779379/19fba965-6afe-4c0b-bb91-83a13f2f3da1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>gm gm gm!!!</p>
<p>Even with the vast network of blockchain, with 1000s of nodes and 100s of chains (L1, L2, L3....) the users are getting restricted in utilizing the complete potential of the decentralized network. Reason? Some application works on ETH, some on Polygon, some on Gnosis, and so on and on!</p>
<p>In the ever-growing network of Blockchain Networks, or <strong><em>different blockchain networks</em></strong> developers are required to build chain-agnostic applications.</p>
<blockquote>
<p><em>No dependency on one chain, and no restriction for any user.</em></p>
</blockquote>
<p>Now solving this interoperability issue between different chains requires devs to build robust and more importantly secure designs, which is a highly technical and resourceful process, and to save devs from going through such pain <a target="_blank" href="https://www.hyperlane.xyz"><strong>Hyperlane</strong></a> comes into the picture.</p>
<p>In this article, we are going to learn almost all about Hyperlane and it works, so grab a coffee ☕️ and LFG 🚀</p>
<hr />
<h1 id="heading-what-is-hyperlane">What is Hyperlane?</h1>
<p><strong>Hyperlane is a Permissionless Interoperability Protocol</strong> that helps devs send arbitrary data across chains⛓</p>
<blockquote>
<p>Read in short here:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1686628441888804864">https://twitter.com/megabyte0x/status/1686628441888804864</a></div>
<p> </p>
</blockquote>
<p><strong>"Permissionless"</strong> means <em>no one requires any sort of permission</em> from the Hyperlane Team to use Hyperlane SDK, Contracts, or even while deploying on new chains as I did👇🏻</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1651938319570456577">https://twitter.com/megabyte0x/status/1651938319570456577</a></div>
<p> </p>
<p><strong>"Interoperability"</strong> means <em>sending between different chains</em>. Imagine initiating a transaction on ETH on certain to close a position on Polygon.</p>
<p>Hyperlane is a <strong>complete modular protocol</strong> that helps devs to customize it according to their application requirements.</p>
<p>The following are the key components of Hyperlane:</p>
<ul>
<li><p>Mailbox</p>
</li>
<li><p>Interchain Security Module [ISM]</p>
</li>
<li><p>Interchain Gas Payment [IGP]</p>
</li>
<li><p>Agents</p>
</li>
</ul>
<blockquote>
<p>You can either learn about all of them in deep one by one or go directly to the last section for a quick view with examples.</p>
</blockquote>
<h1 id="heading-mailbox">Mailbox</h1>
<p><strong><em>Mailbox is an on-chain API to send and receive interchain messages.</em></strong></p>
<blockquote>
<p>You can also check this out:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1686979539291762688">https://twitter.com/megabyte0x/status/1686979539291762688</a></div>
<p> </p>
</blockquote>
<p>Mailbox is the middle-man [but CODE] which helps devs to connect between different chains and leverage it to build something out of the box.</p>
<p>Their contracts are required to be present on every <a target="_blank" href="https://docs.hyperlane.xyz/docs/resources/addresses">chain supported by Hyperlane.</a></p>
<p>Mailbox Interface has two functions that are required to be present in the cross-chain contracts, those are the following:</p>
<ul>
<li><p><code>dispatch</code></p>
</li>
<li><p><code>process</code></p>
</li>
</ul>
<h2 id="heading-dispatch">dispatch</h2>
<p>This is used to send the data from the origin chain to the destination chain.</p>
<p>It accepts several params:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693564023609/bc6ce931-e81f-49df-80a3-e962ee166066.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p><code>_destinationDomain (uint32)</code>: domain for the destination chain as per the Hyperlane Docs or the deployer.</p>
</li>
<li><p><code>_recipient Address (bytes32)</code>: address of the recipient.</p>
</li>
<li><p><code>_messageBody (bytes)</code>: Raw bytes content of message body</p>
</li>
</ul>
<p>It works by following these steps:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693564190795/f026d50f-6fe4-43d5-bdf6-070f91c4f8ac.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>First, check whether the message length exceeds the 2KiB length.</p>
</li>
<li><p>It formats the _<code>messageBody</code> using <a target="_blank" href="https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/solidity/contracts/libs/Message.sol">Message.sol</a> according to the needs.</p>
</li>
<li><p><a target="_blank" href="https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/solidity/contracts/libs/Message.sol">Message.sol</a> provides a function <code>.id()</code> that returns keccak256(_message). This _id is saved into the <a target="_blank" href="https://medium.com/@josephdelong/ethereum-2-0-deposit-merkle-tree-13ec8404ca4f">"incremental" Merkle Tree.</a></p>
</li>
<li><p>The Merkle Tree is used to verify fraud proofs in Hyperlane's Staking and Slashing Protocol.</p>
</li>
</ul>
<h2 id="heading-process">process</h2>
<p>This is used on the destination chain to receive the message.</p>
<p>It accepts the following two params:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693564279003/2b1971f7-4392-4c37-8af9-5b7aa9374df9.png" alt class="image--center mx-auto" /></p>
<p>It works by following these steps:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693593889185/09afb654-cf53-4afd-9fb4-8c843424fa5e.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p><code>_message</code> is the formatted message from the <a target="_blank" href="https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/solidity/contracts/libs/Message.sol">Message.sol</a></p>
</li>
<li><p><code>_metadata</code> is the specific Arbitrary metadata provided by the relayer used by <a target="_blank" href="https://docs.hyperlane.xyz/docs/protocol/sovereign-consensus">ISM</a> to verify <code>_message</code></p>
</li>
<li><p>Then it checks whether this <code>_id</code> is in the array of delivered messages or not. If it is, then it reverts with <strong>"delivered"</strong> else add it to the array of delivered messages.</p>
</li>
<li><p>Then it gets the ISM Address for the <code>recepientAddress</code>.</p>
</li>
<li><p>If the recipient has defined a specific ISM it returns that else uses the default ISM for the chain.</p>
</li>
<li><p>It uses the ISM address to verify messages received by the Mailbox.</p>
</li>
<li><p>After all verification, it emits the message received event using the <code>IMessageRecepient.sol</code></p>
</li>
</ul>
<blockquote>
<p>Learn more about Mailbox <a target="_blank" href="https://docs.hyperlane.xyz/docs/protocol/messaging">here</a>.</p>
</blockquote>
<h1 id="heading-interchain-security-modules">Interchain Security Modules</h1>
<p><strong>ISM verifies the particular messages delivered on the destination chain are <em>actually</em> sent from the origin chain.</strong></p>
<blockquote>
<p>You can also check this out:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1687471625724383232">https://twitter.com/megabyte0x/status/1687471625724383232</a></div>
<p> </p>
</blockquote>
<p>ISM is used in the Mailbox, to verify the message Mailbox received from the relayer before executing txns.</p>
<p>Developers can define specific ISM for their applications or can use pre-built ISMs provided by the team, using the <code>ISpecifiesInterchainSecurityModule.sol</code></p>
<p>ISMs are:</p>
<p><img src="https://pbs.twimg.com/media/F2sYYrcbsAA_Zii?format=png&amp;name=900x900" alt="Image" /></p>
<details><summary>Configurable</summary><div data-type="detailsContent">ISM can be configured as per the application requirements, with all the additional parameters required by the application.</div></details><details><summary>Composable</summary><div data-type="detailsContent">Devs can use more than one ISM in their application to increase security and work according to the consensus of the chain.</div></details><details><summary>Customizable</summary><div data-type="detailsContent">Devs can use IInterfaceSecurityModule.sol and can build the whole ISM according to their needs.</div></details>

<p>Each ISM has two main components:</p>
<p><img src="https://pbs.twimg.com/media/F2sYjIaboAENMUY?format=jpg&amp;name=900x900" alt="Image" /></p>
<h2 id="heading-verify">verify</h2>
<p><img src="https://pbs.twimg.com/media/F2sYnasaIAAJ47k?format=jpg&amp;name=900x900" alt="Image" /></p>
<p>It takes two params:</p>
<ul>
<li><p><code>message(bytes)</code>: Message that needs to be verified.</p>
</li>
<li><p><code>metadata(bytes)</code>: Off-chain Arbitrary bytes provided by the Relayers.</p>
</li>
</ul>
<h2 id="heading-moduletype">moduleType</h2>
<p>It signals relayers about the type of module to be included in the metadata.</p>
<h2 id="heading-implementation">Implementation</h2>
<p>Implementation of a specific ISM in an application is done by using the <code>ISpecifiesInterchainSecurityModule.sol</code></p>
<p><img src="https://pbs.twimg.com/media/F2sYwiQaoAAeO6b?format=jpg&amp;name=900x900" alt="Image" /></p>
<p>There are different prebuilt ISMs provided by the team:</p>
<ul>
<li><p>MultisigISM</p>
</li>
<li><p>RoutingISM</p>
</li>
<li><p>AggregationISM</p>
</li>
<li><p>OptimisticISM</p>
</li>
<li><p>WormholeISM</p>
</li>
<li><p>HookISM</p>
</li>
</ul>
<blockquote>
<p>Learn more about ISM <a target="_blank" href="https://docs.hyperlane.xyz/docs/protocol/sovereign-consensus">here</a>.</p>
</blockquote>
<h1 id="heading-interchain-gas-paymaster">Interchain Gas Paymaster</h1>
<p><strong><em>On-chain API to pay Relayer(s) to deliver the message on the destination chain.</em></strong></p>
<blockquote>
<p>You can also refer to this:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1687818750635261954">https://twitter.com/megabyte0x/status/1687818750635261954</a></div>
<p> </p>
</blockquote>
<p>An interchain message requires two transactions:</p>
<p><img src="https://pbs.twimg.com/media/F2xWNzRboAEXST_?format=png&amp;name=900x900" alt="Image" /></p>
<ol>
<li><p>Txn on the origin chain to send the message.</p>
</li>
<li><p>Txn on the destination chain to receive the message.</p>
</li>
</ol>
<p>When users send the message from The <strong>Mailbox on the Origin Chain</strong> to the Relayer, they also need to send the gas fee amount to the Relayer to cover the fee on the Destination Chain. This gas fee is calculated with IGP and paid to the Relayer simultaneously.</p>
<p><img src="https://pbs.twimg.com/media/F2xWONJbYAAw1XU?format=png&amp;name=small" alt="Image" /></p>
<p>IGP Provides us with two functions:</p>
<p><img src="https://pbs.twimg.com/media/F2xWOp5aIAAVYqF?format=png&amp;name=small" alt="Image" /></p>
<ul>
<li><p><code>payGasFor()</code></p>
</li>
<li><p><code>quoteGasPayment()</code></p>
</li>
</ul>
<h2 id="heading-payforgas">payForGas</h2>
<p><img src="https://pbs.twimg.com/media/F2xWPEsbkAATs-U?format=jpg&amp;name=small" alt="Image" /></p>
<p>It takes these params:</p>
<ul>
<li><p><code>_messageId</code></p>
</li>
<li><p><code>destinationDomain</code></p>
</li>
<li><p><code>gasAmount</code></p>
</li>
<li><p><code>refundAddress</code></p>
</li>
</ul>
<p>When the user sends the above parameters, the following are the next steps:</p>
<p><img src="https://pbs.twimg.com/media/F2xWPhAbYAAoOdW?format=jpg&amp;name=small" alt="Image" /></p>
<ul>
<li><p>It first gets the gas fee required on Destination Chain by calling <code>quoteGasPayment()</code></p>
</li>
<li><p>If the required amount is less than the <code>msg.value</code>, then go forward else revert.</p>
</li>
<li><p>It calculates the overpaid amount.</p>
</li>
<li><p>If the overpaid amount is more than 0, then send the amount to the <code>refundAddress</code>, else move forward.</p>
</li>
<li><p>Emits Event of GasPayment.</p>
</li>
</ul>
<h2 id="heading-quotegaspayment">quoteGasPayment</h2>
<p><img src="https://pbs.twimg.com/media/F2xWQUJawAAO1bE?format=png&amp;name=small" alt="Image" /></p>
<p>It takes the following parameters:</p>
<ul>
<li><p><code>_destinationDomain</code></p>
</li>
<li><p><code>_gasAmount</code></p>
</li>
</ul>
<p>When it receives the above parameters, it follows like this:</p>
<p><img src="https://pbs.twimg.com/media/F2xWQusbYAEBM5_?format=jpg&amp;name=small" alt="Image" /></p>
<ul>
<li><p>It first gets the token exchange rate and the gas price for the Destination Chain.</p>
</li>
<li><p>Then it calculates the gas fee on the Destination Chain.</p>
</li>
<li><p>At last, calculates the number of native tokens required on the Origin Chain and returns it.</p>
</li>
</ul>
<h2 id="heading-complete-workflow">Complete Workflow</h2>
<p>This is the complete <strong>workflow of Interchain Gas Payment</strong> on the Origin Chain to deliver the message on the Destination Chain:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693593387030/9e0f9d6d-a728-46ec-9c5d-8efe81f9253f.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p>Learn more about Interchain Gas Payment <a target="_blank" href="https://docs.hyperlane.xyz/docs/protocol/interchain-gas-payments">here</a>.</p>
</blockquote>
<h1 id="heading-agents">Agents</h1>
<p><strong><em>Off-chain actors that power Hyperlane.</em></strong></p>
<blockquote>
<p>You can also refer to this:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1688514083287678977">https://twitter.com/megabyte0x/status/1688514083287678977</a></div>
<p> </p>
</blockquote>
<p>There are three Agents in Hyperlane Protocol:</p>
<p><img src="https://pbs.twimg.com/media/F27OnUSbEAAjnPk?format=jpg&amp;name=900x900" alt="Image" /></p>
<p>Since Hyperlane is a Permissionless Interoperability protocol, you can take the role of any agent and contribute to the security of the network.</p>
<h2 id="heading-validators">Validators</h2>
<p>They sign the current Merkle root which they receive from the <code>Mailbox.latestCheckpoint()</code></p>
<p><img src="https://pbs.twimg.com/media/F27OnzdbMAEA2Os?format=jpg&amp;name=900x900" alt="Image" /></p>
<p>Validators are supposed to sign the checkpoint after it reaches the finality to maintain the security of the network.</p>
<p>After signing the checkpoint, validators post signatures on the available storage so that the Relayers can aggregate them.</p>
<h2 id="heading-relayers">Relayers</h2>
<p>Relayers are responsible for delivering messages to the recipient.</p>
<p><img src="https://pbs.twimg.com/media/F27OocLaAAAXIDS?format=png&amp;name=small" alt="Image" /></p>
<p>It works as follows:</p>
<ol>
<li><p>observe Mailbox for the new messages.</p>
</li>
<li><p>Use Mailbox to get the ISM implemented by the recipient.</p>
</li>
<li><p>aggregate the metadata for the ISM.</p>
</li>
<li><p>deliver the message.</p>
</li>
</ol>
<p>Relayers can also make configurations for the messages they want to deliver:</p>
<ul>
<li><p>A sender/recipient whitelist.</p>
</li>
<li><p>A sender/recipient blacklist</p>
</li>
<li><p>Getting paid on-chain after delivering.</p>
</li>
</ul>
<p>The relayers get incentivized during the time they process the message with the gas fee.</p>
<h2 id="heading-watchtowers">Watchtowers</h2>
<p>They are the snipers in the Hyperlane protocol. They look for frauds and convicts (malicious validators) happening in the validator network and kill them by slashing the validator stake. Watchtowers are incentivized when they submit the correct report of fraud.</p>
<blockquote>
<p>Learn more about Agents <a target="_blank" href="https://docs.hyperlane.xyz/docs/protocol/agents">here</a>.</p>
</blockquote>
<hr />
<h1 id="heading-story-time">Story Time</h1>
<p>Jim wants to send an arbitrary message (data) to Dwight from <strong><em>Polygon zkEVM to Ethereum with Hyperlane.</em></strong></p>
<p><img src="https://pbs.twimg.com/media/F3AXEMZb0AEz0Df?format=jpg&amp;name=medium" alt="Image" /></p>
<blockquote>
<p>You can also refer to this:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://twitter.com/megabyte0x/status/1688875226745253888?s=20">https://twitter.com/megabyte0x/status/1688875226745253888?s=20</a></div>
<p> </p>
</blockquote>
<p>The following steps will be required to transfer the data:</p>
<p><img src="https://pbs.twimg.com/media/F3AXE5EbkAAfJJA?format=jpg&amp;name=medium" alt="Image" /></p>
<ol>
<li><p>Jim sends the <code>message data</code>, <code>recipient address</code>, and <code>chain</code> where the recipient is to the <strong>Polygon zkEVM Mailbox contract.</strong></p>
</li>
<li><p><strong>Mailbox</strong> <strong>emits an event</strong> that gets indexed.</p>
</li>
<li><p><strong>Validators</strong> <strong>sign</strong> the latest checkpoint.</p>
</li>
<li><p>The <strong>signature gets stored in the</strong> <strong>database</strong>.</p>
</li>
<li><p>During the above process, Jim <strong>pays the gas fee using</strong> <strong>IGP</strong>.</p>
</li>
<li><p>When the gas fee is transferred to the <strong>Relayer</strong>.</p>
</li>
<li><p>The <strong>relayer sends the message and metadata</strong> on the ETH Mainnet.</p>
</li>
<li><p>The <code>messageBody</code> sent to <strong>ISM</strong> <strong>to get verified.</strong></p>
</li>
<li><p>The message gets <strong>delivered to Dwight on the ETH Mainnet</strong>.</p>
</li>
</ol>
<hr />
<blockquote>
<p>Whoo!!🤩 This was quite a lot of workflow and solidity contracts understanding.</p>
</blockquote>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">If you wanna explore more check out the <a target="_blank" href="https://docs.hyperlane.xyz">Hyperlane Docs</a>, and if you have any queries get them resolved in <a target="_blank" href="http://t.me/c/1264208834/1">Hyperlane India Telegram Channel.</a></div>
</div>

<p>You can connect with me on <a target="_blank" href="https://twitter.com/megabyte0x">Twitter</a>, <a target="_blank" href="https://lenster.xyz/u/megabyte0x">Lenster</a> or <a target="_blank" href="https://linkedin.com/in/megabyte0x">LinkedIn</a>.</p>
<p>Happy Learning 🙌🏻</p>
<p>Keep Building 🧱🚀</p>
]]></content:encoded></item><item><title><![CDATA[How to build Reddit's NFT Marketplace using Polygon and Paper 📄]]></title><description><![CDATA[gm gm gm!!!
Indeed, in the current scenario, few NFT marketplaces cater to non-web3 users, primarily due to the poor User Experience (UX) they have to face.
A significant barrier to entry for these users is the complexity of the Web3 ecosystem, inclu...]]></description><link>https://blog.megabyte.sh/nft-marketplace-using-paper</link><guid isPermaLink="true">https://blog.megabyte.sh/nft-marketplace-using-paper</guid><category><![CDATA[NFT]]></category><category><![CDATA[Solidity]]></category><category><![CDATA[hardhat]]></category><category><![CDATA[Blockchain]]></category><category><![CDATA[ethers]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Thu, 13 Apr 2023 13:25:02 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1681392273768/17c82152-a97d-4c15-9bee-031c3aacdb62.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>gm gm gm!!!</p>
<p>Indeed, in the current scenario, few NFT marketplaces cater to non-web3 users, primarily due to the poor User Experience (UX) they have to face.</p>
<p>A significant barrier to entry for these users is the complexity of the Web3 ecosystem, including the need to understand concepts such as wallets, private keys, and gas fees. Moreover, the onboarding process can be tedious and confusing, with users having to set up and manage wallets and acquire cryptocurrency to interact with the marketplace. To address these issues and make NFT marketplaces more accessible to non-web3 users, <em>it's essential to focus on improving UX.</em></p>
<p>In this guide, you’ll learn how to create a marketplace on Polygon and make it easy for non-crypto natives to use the marketplace by allowing them to <strong>log in with their emails</strong> and transfer NFTs with a **<em>single click</em>.</p>
<h2 id="heading-reddits-success-with-nfts-so-far">Reddit’s success with NFTs so far</h2>
<p>Reddit is perhaps the best example of a company that brought NFTs to the masses. So far, they’ve brought NFTs to 7+ million people.</p>
<p>Reddit’s avatars were a massive success, partly because most customers don’t even know they’re using NFTs. They think of them as digital collectibles.</p>
<p>Reddit made the experience of claiming (and now buying) NFTs seamless. Users don’t need to know anything about Metamask, don’t need to hold any crypto, and don’t need to worry about remembering their seed phrases.</p>
<p>If we want NFTs to reach even more people, we should learn from Reddit’s success: Making NFTs simple for non-crypto native users will increase adoption.</p>
<p>That’s why I’ve created this guide: anyone can easily copy what worked for Reddit—specifically offering email-based login and payments via credit card. We’ll be doing this using Polygon (great for low-cost transactions) and [<a target="_blank" href="https://withpaper.com/?utm_source=megabyte">Paper</a>] (SDKs for NFT commerce).</p>
<h2 id="heading-avoid-using-metamask-as-the-only-wallet-for-your-dapp">Avoid using Metamask as the only wallet for your DApp</h2>
<p>Here the main reasons why you should avoid betting on MetaMask alone:</p>
<ol>
<li><p>Limited Web3 knowledge can make average users hesitant to use MetaMask.</p>
</li>
<li><p>Installing and connecting the wallet to your DApp may confuse many users.</p>
</li>
<li><p>Managing private keys can be complex, posing significant concerns for users and the product. Since there is no solution for recovering a private key once it is lost or stolen, this presents a considerable issue.</p>
</li>
</ol>
<h2 id="heading-reasons-for-bad-ux-in-most-dapps">Reasons for bad UX in most DApps</h2>
<p>Every DApp aims to achieve decentralization to harness blockchain technology's potential fully. To do so, they often rely on traditional wallets that offer security and decentralization. However, like the Blockchain Trilemma, these DApps may need help with scalability.</p>
<p>For users who manage to create a wallet and store their private keys "safely," the next challenge arises when dealing with funds. Users must on-ramp crypto tokens and then spend them to interact with the DApp, significantly hindering new user onboarding.</p>
<p>Several other factors contribute to a poor user experience, such as needing to sign every interaction, always having the wallet accessible, and more. These issues can create an overall negative experience for users.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://tenor.com/en-GB/view/how-do-we-fix-this-saturday-night-live-whats-the-solution-whats-the-answer-solution-gif-21179541">https://tenor.com/en-GB/view/how-do-we-fix-this-saturday-night-live-whats-the-solution-whats-the-answer-solution-gif-21179541</a></div>
<p> </p>
<h2 id="heading-an-alternative-approach-for-login-in-dapps">An alternative approach for login in DApps</h2>
<p>Instead of relying on externally owned accounts (EOAs), developers can create smart contracts that act as user accounts and execute transactions on behalf of the user. This approach can improve user onboarding and the overall user experience of the DApp.</p>
<p>Several Ethereum improvement proposals (EIPs) try to define the concept of using smart contracts as wallets. After nine years of research, EIP-4337 was officially approved for account abstraction (AA).</p>
<p>AA offers customizable logic for wallet creation, transaction gas payment, and alternative tokens instead of Ether for gas fees. One such option is creating a wallet using an email address, where the user's email generates a private key. This key is then divided using cryptographic functions and shared between the user's device and the application service providers. The service provider can then pay for transaction gas, sign transactions, and assist users with private key recovery.</p>
<h2 id="heading-papers-solution-to-bad-ux">Paper's Solution to bad UX</h2>
<p>The Paper offers an <a target="_blank" href="https://docs.withpaper.com/docs/embedded-wallet-service-overview">Embedded Wallet SDK</a> that helps address user experience issues by providing the following features:</p>
<ol>
<li><p>Create user wallets using email or social logins.</p>
</li>
<li><p>Sign messages or call blockchain methods without requiring prompts or gas fees.</p>
</li>
<li><p>Enable users to access or recover their wallets on any device.</p>
</li>
<li><p>Allow users to connect to other apps through WalletConnect.</p>
</li>
</ol>
<p><a target="_blank" href="https://withpaper.com/?utm_source=megabyte">Paper</a> helps developers create seamless user experiences and scale their apps without setting up their own infrastructure.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://tenor.com/en-GB/view/ive-learned-so-much-nick-zetta-basically-homeless-i-learned-a-lot-i-gained-a-lot-of-knowledge-gif-19144056">https://tenor.com/en-GB/view/ive-learned-so-much-nick-zetta-basically-homeless-i-learned-a-lot-i-gained-a-lot-of-knowledge-gif-19144056</a></div>
<p> </p>
<h2 id="heading-lets-buidl-our-own-marketplace">Let's BUIDL (🧱,🚀) our own marketplace</h2>
<p>Today, we will build an NFT marketplace to minimize friction for onboarding non-Web3 users. We'll achieve this by providing the option to create a wallet using any email and enabling gasless NFT transfers.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://tenor.com/en-GB/view/lets-start-building-building-builder-lets-do-it-lets-go-gif-14530338">https://tenor.com/en-GB/view/lets-start-building-building-builder-lets-do-it-lets-go-gif-14530338</a></div>
<p> </p>
<h3 id="heading-functionalities">Functionalities</h3>
<p>We will be implementing the following functionalities in our marketplace:</p>
<ol>
<li><p>Email login for the DApp</p>
</li>
<li><p>Single click for buying and transferring the NFT.</p>
</li>
</ol>
<h3 id="heading-tech-stack">Tech Stack</h3>
<p>We build the marketplace with the following technologies:</p>
<ol>
<li><p>React.js</p>
</li>
<li><p>Ethers.js</p>
</li>
<li><p>Paper's <a target="_blank" href="https://docs.withpaper.com/docs/embedded-wallet-service-overview">Embedded Wallet SDK</a></p>
</li>
</ol>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li><p>NPM or Yarn installed in your system.</p>
</li>
<li><p>Basic understanding of React.js</p>
</li>
</ul>
<h3 id="heading-environment-setup">Environment Setup</h3>
<p>To set up the initial code (contract + UI) <em>[Thanks to</em> <a target="_blank" href="https://github.com/OMGWINNING/NFT-Marketplace-Tutorial"><em>OMGWINNING</em></a> <em>for this]</em>, open your terminal in your preferred directory and enter the following commands:</p>
<pre><code class="lang-bash">git <span class="hljs-built_in">clone</span> https://github.com/megabyte0x/NFT-Marketplace-Starter_Code.git

<span class="hljs-built_in">cd</span> NFT-Marketplace-Starter_Code

npm install
</code></pre>
<p>Create a new file in the root directory named <code>.env</code> and paste the following content:</p>
<pre><code class="lang-bash">REACT_APP_ALCHEMY_API_URL=<span class="hljs-string">"&lt;Paste Alchemy URL HERE&gt;"</span>
REACT_APP_PRIVATE_KEY=<span class="hljs-string">"&lt;Paste your Private Key here&gt;"</span>
REACT_APP_PINATA_KEY=<span class="hljs-string">"&lt;Paste Pinata key here&gt;"</span>
REACT_APP_PINATA_SECRET=<span class="hljs-string">"&lt;Paste Pinata Secret key here&gt;"</span>
REACT_APP_PAPER_SECRET=<span class="hljs-string">"&lt;Paste Paper SDK secret key here&gt;"</span>
</code></pre>
<p>Obtain the required values by signing up on <a target="_blank" href="https://dashboard.alchemy.com/">Alchemy</a>, <a target="_blank" href="https://pinata.cloud/signup">Pintata</a>, and <a target="_blank" href="https://withpaper.com/dashboard/auth-settings">Paper</a>.</p>
<pre><code class="lang-bash">npm install @paperxyz/embedded-wallet-service-sdk
</code></pre>
<p>Finally, start the development server with the following command:</p>
<pre><code class="lang-bash">npm start
</code></pre>
<blockquote>
<p>Your development environment is now ready!</p>
</blockquote>
<h3 id="heading-initializing-the-paper-sdk">Initializing the Paper SDK</h3>
<p>Create a file in the <code>src</code> folder named <code>paper.js</code>. This is where we will initialize the SDK.</p>
<p>Copy and paste the following code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { PaperEmbeddedWalletSdk } <span class="hljs-keyword">from</span> <span class="hljs-string">"@paperxyz/embedded-wallet-service-sdk"</span>;

<span class="hljs-keyword">import</span> { UserStatus } <span class="hljs-keyword">from</span> <span class="hljs-string">"@paperxyz/embedded-wallet-service-sdk"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> sdk = <span class="hljs-keyword">new</span> PaperEmbeddedWalletSdk({
  <span class="hljs-attr">clientId</span>: process.env.REACT_APP_PAPER_SECRET,
  <span class="hljs-attr">chain</span>: <span class="hljs-string">"Mumbai"</span>,
});

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> socialLogin = <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">await</span> sdk.auth.loginWithPaperModal();
    <span class="hljs-keyword">return</span> sdk.getUser();
  } <span class="hljs-keyword">catch</span> (e) {
    <span class="hljs-built_in">console</span>.log(e);
  }
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> socialLogout = <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">await</span> sdk.auth.logout();
  } <span class="hljs-keyword">catch</span> (e) {
    <span class="hljs-built_in">console</span>.log(e);
  }
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> getUser = <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-keyword">const</span> user = <span class="hljs-keyword">await</span> sdk.getUser();
  <span class="hljs-keyword">return</span> user;
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> getSigner = <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-keyword">let</span> signer;
  <span class="hljs-keyword">const</span> user = <span class="hljs-keyword">await</span> getUser();
  <span class="hljs-keyword">if</span> (user.status === UserStatus.LOGGED_OUT) {
    <span class="hljs-keyword">return</span>;
  }
  <span class="hljs-keyword">try</span> {
    signer = <span class="hljs-keyword">await</span> getUser().then(<span class="hljs-function">(<span class="hljs-params">user</span>) =&gt;</span> {
      <span class="hljs-keyword">return</span> user.wallet.getEthersJsSigner();
    });
  } <span class="hljs-keyword">catch</span> (e) {
    <span class="hljs-built_in">console</span>.log(e);
  }
  <span class="hljs-keyword">return</span> signer;
}
</code></pre>
<ul>
<li><p><code>sdk</code> initializes Paper's <a target="_blank" href="https://docs.withpaper.com/docs/embedded-wallet-service-overview">Embedded Wallet SDK</a> by passing our Paper's Secret Key and the chain we will be using, "Mumbai".</p>
</li>
<li><p><code>socialLogin</code> is the function that opens the modal for social login using email.</p>
</li>
<li><p><code>socialLogout</code> is the function to log out of the user.</p>
</li>
<li><p><code>getUser</code> is the function that retrieves information about the user, such as their wallet and wallet address.</p>
</li>
<li><p><code>getSigner</code> is a function that returns the Ethereum signer for signing transactions.</p>
</li>
</ul>
<p>Now that we initialized our SDK, let's connect it to the rest of the code.</p>
<h3 id="heading-enabling-email-login">Enabling email login</h3>
<p>Since <code>Navbar</code> is the component that will be helping us connect the wallet so, let's go to <code>src/components/Navbar.js</code></p>
<p>Copy and paste this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { Link } <span class="hljs-keyword">from</span> <span class="hljs-string">"react-router-dom"</span>;
<span class="hljs-keyword">import</span> { useEffect, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { useLocation } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-router'</span>;

<span class="hljs-keyword">import</span> { socialLogin, socialLogout, getUser } <span class="hljs-keyword">from</span> <span class="hljs-string">"../paper.js"</span>;

<span class="hljs-keyword">import</span> { UserStatus } <span class="hljs-keyword">from</span> <span class="hljs-string">"@paperxyz/embedded-wallet-service-sdk"</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Navbar</span>(<span class="hljs-params"></span>) </span>{

  <span class="hljs-keyword">const</span> [connected, toggleConnect] = useState(<span class="hljs-literal">false</span>);
  <span class="hljs-keyword">const</span> location = useLocation();
  <span class="hljs-keyword">const</span> [currentAddress, updateAddress] = useState(<span class="hljs-string">'0x'</span>);
  <span class="hljs-keyword">const</span> [currentUser, updateUser] = useState(<span class="hljs-literal">null</span>);

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updateButton</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> ethereumButton = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'.enableEthereumButton'</span>);
    ethereumButton.classList.remove(<span class="hljs-string">"hover:bg-blue-70"</span>);
    ethereumButton.classList.remove(<span class="hljs-string">"bg-blue-500"</span>);
    ethereumButton.classList.add(<span class="hljs-string">"hover:bg-green-70"</span>);
    ethereumButton.classList.add(<span class="hljs-string">"bg-green-500"</span>);
  }

  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">connectWithPaperWallet</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">await</span> socialLogin().then(<span class="hljs-function">(<span class="hljs-params">user</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span> (UserStatus.LOGGED_IN_WALLET_INITIALIZED === user.status) {
          setUser();
        }
      });
    } <span class="hljs-keyword">catch</span> (e) {
      <span class="hljs-built_in">console</span>.log(e);
    }
  }

  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">logout</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">await</span> socialLogout().then(<span class="hljs-function">() =&gt;</span> {
        setUser();
      });
    } <span class="hljs-keyword">catch</span> (error) {
      <span class="hljs-built_in">console</span>.log(error);
    };
  }

  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setUser</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">await</span> getUser().then(<span class="hljs-function">(<span class="hljs-params">user</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span> (user.status === UserStatus.LOGGED_OUT) {
          toggleConnect(<span class="hljs-literal">false</span>);
          updateUser(<span class="hljs-literal">null</span>);
          updateAddress(<span class="hljs-string">'0x'</span>);
          <span class="hljs-keyword">return</span>;
        }
        updateUser(user);
        updateAddress(user.walletAddress);
        toggleConnect(<span class="hljs-literal">true</span>);
        updateButton();
      })
    } <span class="hljs-keyword">catch</span> (error) {
      <span class="hljs-built_in">console</span>.error(error);
    }
  }

  useEffect(<span class="hljs-function">() =&gt;</span> {
    setUser();
  }, [currentUser]);
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Navbar;
</code></pre>
<p>Here, we've defined several state variables and a few functions to connect the wallet using Paper's SDK.</p>
<ul>
<li><p><code>updateButton()</code> updates the UI for the Connect Wallet button.</p>
</li>
<li><p><code>connectWithPaperWallet()</code> uses the <code>socialLogin</code> function defined in <code>paper.js</code> to open a modal where users can sign in using their email. If the user signs in successfully, it will update the state of <code>currentUser</code> and <code>currentAddress</code>.</p>
</li>
<li><p>The <code>logout()</code> function uses the <code>socialLogout</code> function defined in <code>paper.js</code> to log out of the current user. This ensures that when the user clicks the logout button, their session will be terminated, and their wallet will be disconnected from the DApp.</p>
</li>
<li><p>Similarly, the <code>setUser()</code> function is called whenever either <code>connectWithPaperWallet()</code> or <code>logout()</code> is called. This function sets the state variables such as <code>currentUser</code>, <code>currentAddress</code>, and <code>connected</code>. It retrieves the latest user information and updates the state variables accordingly. This updates the UI with the user's connection status and ensures a smooth user experience.</p>
</li>
<li><p><code>useEffect</code> initiates when the <code>currentUser</code> changes, retrieving the latest changes in the user state and updating the state variables accordingly.</p>
</li>
</ul>
<p>Next, let's create the returning component in this:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//....</span>

  }, [currentUser]);

<span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">""</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"w-screen"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'flex items-end justify-between py-3 bg-transparent text-white pr-5'</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'flex items-end ml-5 pb-2'</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'inline-block font-bold text-xl ml-2'</span>&gt;</span>
                NFT Marketplace
              <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'w-2/6'</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'lg:flex justify-between font-bold mr-10 text-lg'</span>&gt;</span>
              {location.pathname === "/" ?
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'border-b-2 hover:pb-0 p-2'</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/"</span>&gt;</span>Marketplace<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                :
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'hover:border-b-2 hover:pb-0 p-2'</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/"</span>&gt;</span>Marketplace<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
              }
              {location.pathname === "/sellNFT" ?
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'border-b-2 hover:pb-0 p-2'</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/sellNFT"</span>&gt;</span>List My NFT<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                :
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'hover:border-b-2 hover:pb-0 p-2'</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/sellNFT"</span>&gt;</span>List My NFT<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
              }
              {location.pathname === "/profile" ?
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'border-b-2 hover:pb-0 p-2'</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/profile"</span>&gt;</span>Profile<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                :
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'hover:border-b-2 hover:pb-0 p-2'</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">"/profile"</span>&gt;</span>Profile<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
              }
              <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"enableEthereumButton bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded text-sm"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{connectWithPaperWallet}</span>&gt;</span>{connected ? "Connected" : "Connect Wallet"}<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
                {connected &amp;&amp; <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"enableEthereumButton bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded text-sm"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{logout}</span>&gt;</span>Logout<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>}
              <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">'text-white text-bold text-right mr-10 text-sm'</span>&gt;</span>
        {currentAddress !== "0x" ? "Connected to" : "Not Connected. Please login to view NFTs"} {currentAddress !== "0x" ? currentAddress : ""}
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Navbar;
</code></pre>
<p>Here, we've created a basic Navbar to help navigate the "Marketplace", "List My NFT", and "Profile" pages. It also includes a dynamic <strong>Connect Wallet Button</strong> that will initiate the <code>connectWithPaperWallet</code> function and <strong>Logout Button</strong> that will trigger the <code>logout</code> function.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680622311549/770982d6-73d4-415b-b9c4-174593daf622.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-single-click-to-buy-and-transfer-the-nft">Single Click to <code>buy</code> and <code>transfer</code> the NFT</h3>
<p>Let's move to the <code>src/components/NFTPage.js</code> file.</p>
<p>Copy and paste the below code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> axios <span class="hljs-keyword">from</span> <span class="hljs-string">"axios"</span>;
<span class="hljs-keyword">import</span> { useParams } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-router-dom'</span>;
<span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { ethers } <span class="hljs-keyword">from</span> <span class="hljs-string">"ethers"</span>;

<span class="hljs-keyword">import</span> Navbar <span class="hljs-keyword">from</span> <span class="hljs-string">"./Navbar.js"</span>;

<span class="hljs-keyword">import</span> { getSigner, getUser } <span class="hljs-keyword">from</span> <span class="hljs-string">"../paper.js"</span>;

<span class="hljs-keyword">import</span> MarketplaceJSON <span class="hljs-keyword">from</span> <span class="hljs-string">"../Marketplace.json"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">NFTPage</span>(<span class="hljs-params">props</span>) </span>{

    <span class="hljs-keyword">const</span> [data, updateData] = useState({});
    <span class="hljs-keyword">const</span> [dataFetched, updateDataFetched] = useState(<span class="hljs-literal">false</span>);
    <span class="hljs-keyword">const</span> [message, updateMessage] = useState(<span class="hljs-string">""</span>);
    <span class="hljs-keyword">const</span> [currAddress, updateCurrAddress] = useState(<span class="hljs-string">"0x"</span>);
    <span class="hljs-keyword">const</span> [recieverAddress, updateRecieverAddress] = useState(<span class="hljs-string">"0x"</span>);

    <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getNFTData</span>(<span class="hljs-params">tokenId</span>) </span>{
        <span class="hljs-keyword">const</span> signer = <span class="hljs-keyword">await</span> getSigner();
        <span class="hljs-keyword">const</span> user = <span class="hljs-keyword">await</span> getUser();

        <span class="hljs-keyword">const</span> addr = <span class="hljs-keyword">await</span> user.walletAddress;
        <span class="hljs-comment">//Pull the deployed contract instance</span>
        <span class="hljs-keyword">let</span> contract = <span class="hljs-keyword">new</span> ethers.Contract(MarketplaceJSON.address, MarketplaceJSON.abi, signer)
        <span class="hljs-comment">//create an NFT Token</span>
        <span class="hljs-keyword">const</span> tokenURI = <span class="hljs-keyword">await</span> contract.tokenURI(tokenId);
        <span class="hljs-keyword">const</span> listedToken = <span class="hljs-keyword">await</span> contract.getListedTokenForId(tokenId);
        <span class="hljs-keyword">let</span> meta = <span class="hljs-keyword">await</span> axios.get(tokenURI);
        meta = meta.data;

        <span class="hljs-keyword">let</span> item = {
            <span class="hljs-attr">price</span>: meta.price,
            <span class="hljs-attr">tokenId</span>: tokenId,
            <span class="hljs-attr">seller</span>: listedToken.seller,
            <span class="hljs-attr">owner</span>: listedToken.owner,
            <span class="hljs-attr">image</span>: meta.image,
            <span class="hljs-attr">name</span>: meta.name,
            <span class="hljs-attr">description</span>: meta.description,
        }
        updateData(item);
        updateDataFetched(<span class="hljs-literal">true</span>);
        updateCurrAddress(addr);
    }

    <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">buyNFT</span>(<span class="hljs-params">tokenId</span>) </span>{
        <span class="hljs-keyword">try</span> {
            <span class="hljs-keyword">const</span> signer = <span class="hljs-keyword">await</span> getSigner();

            updateMessage(<span class="hljs-string">"Buying the NFT... Please Wait (Upto 1 min)"</span>)

            <span class="hljs-keyword">const</span> funcInterface = <span class="hljs-keyword">new</span> ethers.utils.Interface([<span class="hljs-string">"function executeSale(uint256 tokenId) public"</span>]);
            <span class="hljs-keyword">const</span> dataToSend = funcInterface.encodeFunctionData(<span class="hljs-string">"executeSale"</span>, [tokenId]);

            <span class="hljs-keyword">let</span> tx = {
                <span class="hljs-attr">to</span>: MarketplaceJSON.address,
                <span class="hljs-attr">value</span>: ethers.utils.parseEther(data.price),
                <span class="hljs-attr">data</span>: dataToSend
            };
            <span class="hljs-keyword">const</span> txResponse = <span class="hljs-keyword">await</span> signer.sendTransaction(tx);
            <span class="hljs-keyword">const</span> txReceipt = <span class="hljs-keyword">await</span> txResponse.wait();
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Transaction sent:"</span>, txReceipt.transactionHash);

            alert(<span class="hljs-string">'You successfully bought the NFT!'</span>);
            updateMessage(<span class="hljs-string">""</span>);
        }
        <span class="hljs-keyword">catch</span> (e) {
            alert(<span class="hljs-string">"Upload Error"</span> + e)
        }
    }

    <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transferNFT</span>(<span class="hljs-params">tokenId</span>) </span>{
        <span class="hljs-keyword">try</span> {

            <span class="hljs-keyword">const</span> signer = <span class="hljs-keyword">await</span> getSigner();

            <span class="hljs-comment">//Pull the deployed contract instance</span>
            <span class="hljs-keyword">let</span> contract = <span class="hljs-keyword">new</span> ethers.Contract(MarketplaceJSON.address, MarketplaceJSON.abi, signer);

            updateMessage(<span class="hljs-string">"Transferring the NFT... Please Wait (Upto 1 min)"</span>)
            <span class="hljs-comment">//run the executeSale function</span>
            <span class="hljs-keyword">let</span> transaction = <span class="hljs-keyword">await</span> contract.transferNFT(tokenId, recieverAddress);
            <span class="hljs-keyword">await</span> transaction.wait();

            alert(<span class="hljs-string">'You successfully transferred the NFT!'</span>);
            updateMessage(<span class="hljs-string">""</span>);
        }
        <span class="hljs-keyword">catch</span> (e) {
            alert(<span class="hljs-string">"Upload Error"</span> + e)
        }
    }

    <span class="hljs-keyword">const</span> params = useParams();
    <span class="hljs-keyword">const</span> tokenId = params.tokenId;
    <span class="hljs-keyword">if</span> (!dataFetched)
        getNFTData(tokenId);
}
</code></pre>
<p>The NFTPage component is a separate page that includes two functions, one for buying NFTs and one for transferring NFTs. Let's understand how each function works in detail:</p>
<ol>
<li><p><code>getNFTData()</code>: This function fetches the data of a specific NFT using its <code>tokenId</code>.</p>
</li>
<li><p><code>buyNFT()</code>: This function transfers the NFT and price from the seller to the buyer. It uses the signer to make transactions and encodes the data for the contract. <code>sendTransaction()</code> (provided by Paper's <a target="_blank" href="https://docs.withpaper.com/docs/embedded-wallet-service-overview">Embedded Wallet SDK</a>) initiates the transaction, which improves the UX, as users don't need to sign any transactions.</p>
</li>
<li><p><code>transferNFT()</code>: This function transfers the NFT. It brings in the signer and uses ethers.js for initiating transactions. By creating the instance of the contract with the signer and initiating the transaction using the traditional method with the contract, users can transfer NFTs with just a single click! All that is needed is to include Paper's <a target="_blank" href="https://docs.withpaper.com/docs/embedded-wallet-service-overview">Embedded Wallet SDK</a> as a signer in the contract instance.</p>
</li>
</ol>
<p>Next, let's create the component to return:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// ...</span>
<span class="hljs-keyword">if</span> (!dataFetched)
        getNFTData(tokenId);

<span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> "<span class="hljs-attr">min-height</span>"<span class="hljs-attr">:</span> "<span class="hljs-attr">100vh</span>" }}&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">Navbar</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Navbar</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"flex ml-20 mt-20"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">{data.image}</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"w-2/5"</span> /&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-xl ml-20 space-y-8 text-white shadow-2xl rounded-lg border-2 p-5"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                        Name: {data.name}
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                        Description: {data.description}
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                        Price: <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">""</span>&gt;</span>{data.price + " MATIC"}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                        Owner: <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-sm"</span>&gt;</span>{data.owner}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                        Seller: <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-sm"</span>&gt;</span>{data.seller}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                        {currAddress === data.owner || currAddress === data.seller ?
                            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-emerald-700"</span>&gt;</span>
                                You are the owner of this NFT
                                <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">br</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter the address of the buyer"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-gray-800 text-white rounded-lg p-2 mt-2"</span>
                                    <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> updateRecieverAddress(e.target.value)}
                                &gt;<span class="hljs-tag">&lt;/<span class="hljs-name">input</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"enableEthereumButton bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded text-sm"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> transferNFT(tokenId)}&gt;Transfer this NFT
                                <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>


                            :
                            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"enableEthereumButton bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded text-sm"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> buyNFT(tokenId)}&gt;Buy this NFT<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

                        }

                        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-green text-center mt-3"</span>&gt;</span>{message}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    )
}
</code></pre>
<p>The component we return displays the details about the NFT using the specific <code>tokenId</code>. The exciting feature here is that the interface shows the "Transfer" button if the user is the owner or the seller of the NFT; otherwise, it displays the "Buy" button.</p>
<p>And after implementing everything, here's the result you'll get:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680761022857/f9c9e302-ed65-4b9e-a26d-6a742cc5482c.jpeg" alt="user != seller" class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680761181216/442726e5-fa8a-4baf-b4f2-177b001e22e9.jpeg" alt class="image--center mx-auto" /></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://tenor.com/en-GB/view/wow-zedelicious-magaling-grabe-hanep-gif-20047450">https://tenor.com/en-GB/view/wow-zedelicious-magaling-grabe-hanep-gif-20047450</a></div>
<p> </p>
<p>Now, restarting the whole DApp by closing the tab and terminal will work seamlessly with the UX your user wants.</p>
<h2 id="heading-summary">Summary</h2>
<p>Wohoo!!! You just created an NFT marketplace with far better UX than the current ones.</p>
<p>You can check out the complete code here:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://github.com/megabyte0x/NFT-Marketplace-Email_Login">https://github.com/megabyte0x/NFT-Marketplace-Email_Login</a></div>
<p> </p>
<p>Paper Provide several solutions to improve UX, like payment through credit cards.</p>
<p>Learn more about Paper's SDK <a target="_blank" href="https://docs.withpaper.com/docs/introduction">here</a></p>
<hr />
<p>Connect with me on Lens🌿<a target="_blank" href="https://lensfrens.xyz/megabyte0x.lens"><strong>[@megabyte0x.lens]</strong></a> or Twitter<a target="_blank" href="https://www.twitter.com/megabyte0x">[@megabyte0x]</a>.</p>
<p>Also, feel free to share your learnings and reach out to me if you've any doubts or questions.</p>
<p>Happy building! 🛠️</p>
<p><strong>WAGMI🚀</strong></p>
]]></content:encoded></item><item><title><![CDATA[Why is Chain Interoperability Required for Web3???]]></title><description><![CDATA[gm gm gm!!!
In today's post, let's learn about the chain interoperability (CI) requirements in Web3.
There has been a lot of recent fuss about cross-chain applications and protocols coming up with their chain/frameworks/libraries to help the devs bui...]]></description><link>https://blog.megabyte.sh/why-is-chain-interoperability-required-for-web3</link><guid isPermaLink="true">https://blog.megabyte.sh/why-is-chain-interoperability-required-for-web3</guid><category><![CDATA[Blockchain]]></category><category><![CDATA[scalability]]></category><category><![CDATA[Security]]></category><category><![CDATA[decentralization]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Fri, 10 Mar 2023 10:57:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1678445790720/67cf5cc6-ef45-474b-890c-b82d6a003708.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>gm gm gm!!!</p>
<p>In today's post, let's learn about the chain interoperability (CI) requirements in Web3.</p>
<p>There has been a lot of recent fuss about cross-chain applications and protocols coming up with their chain/frameworks/libraries to help the devs build cross-chain applications and leverage the power of CI. But before anything, we should understand the requirements and advantages of CI. I will discuss a few significant areas in which interoperability will directly impact Web3.</p>
<p>Let's learn the fundamentals first 🙌</p>
<h2 id="heading-what-is-chain-interoperability">What is Chain Interoperability?</h2>
<p>CI is the ability of blockchain networks to communicate and share data and resources to form a more extensive unified network.</p>
<p>Imagine a chain with good security and one with widespread decentralization coming together and sharing their properties. We will have a unified network that will be both secure and decentralized. This will encourage builders to build more cross-chain DApps using all the properties within a single network.</p>
<h2 id="heading-benefits-of-chain-interoperability-in-web3">Benefits of Chain Interoperability in Web3</h2>
<p>Let's review the benefits CI can bring.</p>
<h3 id="heading-security">Security</h3>
<p>CI can increase blockchain security as the attacker will not target the security of one network but all the networks in that particular unified network. It also allows for sharing security protocols and best practices between different networks, enabling each network to benefit from the security features of other networks. Additionally, cross-chain communication can improve the verification of transactions and smart contracts, enhancing security by reducing the risk of malicious actors attempting to manipulate or tamper with the system.</p>
<p>For example, the Polkadot network allows interoperability between its parachains, which allows them to have their security mechanisms in addition to the security of the Polkadot network itself. This will benefit the overall network by sharing different security properties, which can increase the overall safety of the unified network.</p>
<h3 id="heading-decentralization">Decentralization</h3>
<p>CI allows different blockchains to operate independently while still being able to communicate and collaborate. This reduces the risk of single-point failure of the network and makes it more reliable for the developers and users. This also promotes that only a single entity or organization has significant control over the network.</p>
<p>For example, the Cosmos network enables interoperability between different blockchain networks through "zones" that can communicate with each other. These zones can be independent blockchains that operate independently, but they can also communicate with other zones through a shared hub called Cosmos Hub. This enables different blockchains to work independently while still being able to collaborate, reducing the risk of centralization.</p>
<h3 id="heading-scalability">Scalability</h3>
<p>CI is vital for scaling blockchain networks. It helps reduce congestion (the number of transactions on a particular chain) and increases the transaction speed using resources and properties of different blockchain networks simultaneously. This is achieved through cross-chain transactions that allow for the execution of transactions across multiple blockchains.</p>
<p>For example, CI can improve the scalability of layer-2 solutions by enabling cross-chain communication. The IBC Protocol allows interoperability between different layer-2 solutions. This means that users on one layer-2 solution can execute transactions with users on another layer-2 solution, even if they are built on different blockchains.</p>
<h2 id="heading-bridges-a-step-towards-interoperability">Bridges: A Step Towards Interoperability</h2>
<p>Let's check out bridges, what they are, and how they help with CI.</p>
<h3 id="heading-what-are-bridges">What are Bridges?</h3>
<p>Bridges in the blockchain mean the same as in the real world. An object connecting two destinations. Bridges facilitate communication between different blockchains through the transfer of information and resources.</p>
<p>For Example, If you want to move your Ether from the Ethereum mainnet to Polygon Mainnet, you can use <a target="_blank" href="https://wallet.polygon.technology/">Polygon Bridge</a></p>
<h3 id="heading-types-of-bridges">Types of Bridges</h3>
<p>There are two types of bridges.</p>
<h4 id="heading-trusted-bridges">Trusted Bridges</h4>
<p>These centralized bridges will have an intermediatory between the user and the blockchain. An intermediary will first receive the user's transaction request before executing the transaction on the blockchain.</p>
<h4 id="heading-trustless-bridges">Trustless Bridges</h4>
<p>These are decentralized bridges, only based on code, nothing in between. The user will have all power over their assets and can execute the transaction themselves. The security of this type of bridge will rely on the smart contract and the consensus of the underlying blockchain network.</p>
<h3 id="heading-risks-associated-with-bridges">Risks Associated with Bridges</h3>
<p>Everything innovation comes with some risks so do bridges. Different types of risks are associated with each type of bridge.</p>
<p>In trusted bridges, there are <strong>censorship and custodial risks</strong>. The intermediaries can collab and pull the funds from the user wallets.</p>
<p>In trustless bridges, the main risk is software bugs because the technology is evolving, and there's a constant need to keep everything up to date.</p>
<blockquote>
<p>Learn more about Bridges from here.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://ethereum.org/en/bridges/">https://ethereum.org/en/bridges/</a></div>
<p> </p>
</blockquote>
<h2 id="heading-protocols-that-make-interoperability-possible">Protocols That Make Interoperability Possible</h2>
<p>There are also protocols that facilitate CI; let's look at the most prominent ones.</p>
<h3 id="heading-router-protocolhttprouterprotocolcom"><a target="_blank" href="http://routerprotocol.com">Router Protocol</a></h3>
<p>Router Protocol has its chain, which works on proof-of-stake. The validators of the chain not only validate the state changes of the router chain and monitor state changes on other chains. Applications on Router can write custom logic to trigger events in response to these external state changes. Additionally, with Router, applications can leverage a trustless network of relayers to update states on external chains.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678205480057/2bdd00d0-9b8a-4abe-810b-b7d1ffb42609.png" alt class="image--center mx-auto" /></p>
<p>You can learn <strong>Building Cross-Chain NFT using Router Protocol</strong> here 👇🏻</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://megabyte0x.hashnode.dev/router-portocol-crosstalk">https://megabyte0x.hashnode.dev/router-portocol-crosstalk</a></div>
<p> </p>
<h3 id="heading-hyperlanehttpswwwhyperlanexyz"><a target="_blank" href="https://www.hyperlane.xyz/">Hyperlane</a></h3>
<p>Hyperlane is a permissionless interoperability solution that anyone can use permissionless on any chain layer 1, layer 2, rollup, etc.</p>
<p>It also provides the developer to build their security model and the ability to choose from a few sets of default security mechanisms.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678205614069/4ac5c041-49ff-410b-abf9-ca76238ed660.webp" alt class="image--center mx-auto" /></p>
<h3 id="heading-inter-blockchain-communication-ibchttpsibcprotocolorg"><a target="_blank" href="https://ibcprotocol.org/">Inter Blockchain Communication (IBC)</a></h3>
<p>IBC is also a permissionless interoperability solution; it uses two layers to go cross-chain. The first is the app layer, in which standards define the application handlers to pass the data packets over the transport layer. The second one, TAO, is the infra layer for transporting, retrieving, and ordering data packets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678205454861/73d07e6b-0002-4169-af86-d16fcb89fa61.png" alt class="image--center mx-auto" /></p>
<hr />
<p>Connect with me on <strong>Lens</strong>🌿[<a class="user-mention" href="https://hashnode.com/@megabyte0x">@megabyte0x</a><strong>.lens] or Twitter[</strong><a class="user-mention" href="https://hashnode.com/@megabyte0x">@megabyte0x</a><strong>].</strong></p>
<p>Also, feel free to share your learnings and reach out to me if you've any doubts or questions.</p>
<p>Happy building! 🛠️</p>
<p><strong>WAGMI🚀</strong></p>
]]></content:encoded></item><item><title><![CDATA[Building Cross-Chain NFT using Router Protocol's CrossTalk Library]]></title><description><![CDATA[gm gm gm!!!
Today we will write an NFT (ERC721) smart contract, allowing sending and receiving an NFT from different chains. To transfer our NFTs between chains, we will use Router Cross-Talk Library.
We will transfer an NFT from Avalanche Fuji Testn...]]></description><link>https://blog.megabyte.sh/router-portocol-crosstalk</link><guid isPermaLink="true">https://blog.megabyte.sh/router-portocol-crosstalk</guid><category><![CDATA[Solidity]]></category><category><![CDATA[Polygon]]></category><category><![CDATA[NFT]]></category><category><![CDATA[Avalanche]]></category><category><![CDATA[hardhat]]></category><dc:creator><![CDATA[megabyte]]></dc:creator><pubDate>Thu, 23 Feb 2023 19:23:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1677178523836/98083569-d0e9-458c-93a6-133a2a0056d6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>gm gm gm!!!</strong></p>
<p>Today we will write an NFT (ERC721) smart contract, allowing sending and receiving an NFT from different chains. To transfer our NFTs between chains, we will use <a target="_blank" href="http://devnet-docs.routerprotocol.com/crosstalk"><strong>Router Cross-Talk Library</strong></a>.</p>
<p>We will transfer an NFT from Avalanche Fuji Testnet to Polygon Mumbai Testnet.</p>
<hr />
<p>If you are more of a video tutorial fan, then this is for you 👇🏻</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/NUb7Nt8lges">https://youtu.be/NUb7Nt8lges</a></div>
<p> </p>
<hr />
<h2 id="heading-understanding-the-fundamentals"><strong>Understanding the Fundamentals</strong></h2>
<p>Before we start, let's look at the basics, so we're all on the same page.</p>
<h3 id="heading-what-is-chain-interoperability">What is Chain-Interoperability?</h3>
<p>Chain interoperability is the capability of different blockchain networks or systems to interact and exchange information and resources. In simpler terms, blockchain systems can work together as a unified network instead of operating in isolation.</p>
<p>For example, we could use one blockchain to store financial transactions and another blockchain to store information about a supply chain. If these two blockchains are interoperable, they can create a new application combining both benefits.</p>
<p>Chain interoperability is a complex aspect of blockchain technology, requiring a deep understanding of cryptography, consensus algorithms, and network protocols.</p>
<p>Implementing interoperability protocols like the Router Protocol and Cosmos Network provides a common language and infrastructure for transferring information and assets between networks, creating a more interoperable and connected blockchain ecosystem.</p>
<p>The continued advancement of interoperability standards and protocols will play a vital role in shaping the future of blockchain technology and its impact on various industries and society as a whole.</p>
<h3 id="heading-what-is-the-crosstalk-library"><strong>What is the CrossTalk Library?</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676274749092/4dd191a2-8ac9-441f-8823-c4accff0cb7d.png?auto=compress,format&amp;format=webp" alt /></p>
<p>Router's CrossTalk library is an extensible cross-chain framework that enables seamless state transitions across multiple chains. In simple terms, this library leverages Router's infrastructure to allow contracts on one chain to communicate with contracts deployed on some other chain.</p>
<p>It consists of 3 essential functions, which help build a cross-chain application together.</p>
<ol>
<li><p><code>requestToDest</code> sends cross-chain requests with a message from the source contract to the gateway contract on the source chain. The message will then be forwarded to the Gateway Contract on the destination chain.</p>
</li>
<li><p><code>handleRequestFromSource</code> is to send the request (with some message) from the source contract (on the source chain) to the destination contract (on the destination chain), where it executes all the functions defined in it and then will return the data(if any).</p>
</li>
<li><p><code>handleCrossTalkAck</code> is to receive the acknowledgment on the source chain from the gateway contract on the destination chain, which is in the boolean value stating whether the functions on the destination chain got executed.</p>
</li>
</ol>
<blockquote>
<p><em>Learn more about Cross Talk Library from</em> <a target="_blank" href="http://devnet-docs.routerprotocol.com/crosstalk"><em>here</em></a><em>.</em></p>
</blockquote>
<p>The following figure shows how we will implement CrossTalk Librabry in our contract.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676283371459/897b1335-3c1d-4443-8768-501cf51dd835.jpeg?auto=compress,format&amp;format=webp" alt /></p>
<h2 id="heading-implementing-the-contract"><strong>Implementing the Contract 👨🏻‍💻</strong></h2>
<p>Now that we have learned the fundamentals let's start developing our contract.</p>
<h3 id="heading-setting-up-the-environment">Setting up the Environment</h3>
<p>Before we can start programming, we need to set up our development environment.</p>
<h4 id="heading-creating-a-project">Creating a Project</h4>
<p>Create a project folder and initialize NPM.</p>
<pre><code class="lang-bash">$ mkdir crossERC721 &amp;&amp; <span class="hljs-built_in">cd</span> crossERC721
$ npm init -y
</code></pre>
<h4 id="heading-installing-dependencies"><strong>Installing Dependencies</strong></h4>
<p>Install dependencies and initialize a Hardhat project.</p>
<blockquote>
<p><strong><em>Drink some water while all the dependencies to install!</em></strong></p>
</blockquote>
<pre><code class="lang-bash">$ npm install --save-dev hardhat ts-node typescript chai @types/node @types/mocha @types/chai dotenv
$ npx hardhat
</code></pre>
<p>Select "TypeScript Project" and then press "Enter" three times. The result should look like the following figure; it will start installing dependencies.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676123939215/0062cb6b-546e-410a-a90e-8d2a81f61739.png?auto=compress,format&amp;format=webp" alt /></p>
<h4 id="heading-configuring-hardhat">Configuring Hardhat</h4>
<p>Open the folder with an IDE (I am using VSCode) to configure Hardhat.</p>
<p>File <code>hardhat.config.ts</code>:</p>
<pre><code class="lang-bash">require(<span class="hljs-string">"@nomicfoundation/hardhat-toolbox"</span>);
require(<span class="hljs-string">"dotenv"</span>).config({ path: <span class="hljs-string">".env"</span> });
require(<span class="hljs-string">"@nomiclabs/hardhat-waffle"</span>);

const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ALCHEMY_POLYGON_URL = process.env.ALCHEMY_POLYGON_URL;
const POLYGON_SCAN_KEY = process.env.POLYGON_SCAN_KEY;
const AVALANCHE_URL = process.env.AVALANCHE_URL;
const AVALANCHE_SNOWTRACE_KEY = process.env.AVALANCHE_SNOWTRACE_KEY;

module.exports = {
  solidity: <span class="hljs-string">"0.8.18"</span>,
  networks: {
    mumbai: {
      url: ALCHEMY_POLYGON_URL,
      accounts: [PRIVATE_KEY],
    },
    fuji: {
      url: AVALANCHE_URL,
      accounts: [PRIVATE_KEY],
      chainId: 43113,
    },
  },
  etherscan: {
    apiKey: {
      polygonMumbai: POLYGON_SCAN_KEY,
      avalancheFujiTestnet: AVALANCHE_SNOWTRACE_KEY,
    },
  },
};
</code></pre>
<h4 id="heading-setting-up-the-environment-variables"><strong>Setting up the Environment Variables</strong></h4>
<p>To set up the env variables in development, add them into the <code>.env</code> file.</p>
<p>File <code>.env</code>:</p>
<pre><code class="lang-bash">ALCHEMY_POLYGON_URL= <span class="hljs-string">"abcabc"</span>
PRIVATE_KEY=abcbcabc
POLYGON_SCAN_KEY= abcabcabc
AVALANCHE_SNOWTRACE_KEY = abcabcabc
AVALANCHE_URL= <span class="hljs-string">"https://api.avax-test.network/ext/bc/C/rpc"</span>
</code></pre>
<p>The missing pieces and where to find them:</p>
<ul>
<li><p><code>ALCHEMY_POLYGON_URL</code> - <a target="_blank" href="http://dashboard.alchemy.com"><strong>dashboard.alchemy.com</strong></a></p>
</li>
<li><p><code>PRIVATE_KEY</code> - your development account in MetaMask.</p>
</li>
<li><p><code>POLYGON_SCAN_KEY</code> - <a target="_blank" href="http://polygonscan.com/myapikey"><strong>polygonscan.com/myapikey</strong></a></p>
</li>
<li><p><code>AVALANCHE_SNOWTRACE_KEY</code> -<a target="_blank" href="http://snowtrace.io/myapikey"><strong>snowtrace.io/myapikey</strong></a></p>
</li>
</ul>
<blockquote>
<p><strong><em>Congrats 🤩🎉 Your set up your environment for development.</em></strong></p>
</blockquote>
<h4 id="heading-installing-the-contract-dependencies">Installing the Contract Dependencies</h4>
<p>Install OpenZeppelin contracts and dependencies for cross-chain functionalities:</p>
<pre><code class="lang-bash">$ npm install @openzeppelin/contracts evm-gateway-contract @routerprotocol/router-crosstalk-utils
</code></pre>
<p>Finallyyy... done with DEPENDENCIESsss...</p>
<h3 id="heading-writing-the-contract-code">Writing the Contract Code 💪🏻</h3>
<p>Create a new Solidity file at <code>contracts/CrossERC721.sol</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676125375803/2023c2dc-8592-4fb6-9290-29d1de68a7c1.png?auto=compress,format&amp;format=webp" alt /></p>
<h4 id="heading-implementing-the-contract-definition">Implementing the Contract Definition</h4>
<p>First, we need to set up our contract definition. The contract will use different dependencies to facilitate the cross chain interaction.</p>
<p>File <code>CrossERC721.sol</code>:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// SPDX-License-Identifier: Unlicensed </span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> 0.8.18;</span>

<span class="hljs-keyword">import</span> <span class="hljs-string">"evm-gateway-contract/contracts/ICrossTalkApplication.sol"</span>; <span class="hljs-keyword">import</span> <span class="hljs-string">"evm-gateway-contract/contracts/Utils.sol"</span>; <span class="hljs-keyword">import</span> <span class="hljs-string">"@routerprotocol/router-crosstalk-utils/contracts/CrossTalkUtils.sol"</span>; <span class="hljs-keyword">import</span> <span class="hljs-string">"@openzeppelin/contracts/token/ERC721/ERC721.sol"</span>;

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">CrossERC721</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span>, <span class="hljs-title">ICrossTalkApplication</span> </span>{}
</code></pre>
<h4 id="heading-declaring-the-state-variables">Declaring the State Variables</h4>
<p>File <code>CrossERC721.sol</code>:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// ...</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">CrossERC721</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span>, <span class="hljs-title">ICrossTalkApplication</span> </span>{
    <span class="hljs-comment">// Address of the Owner of the contract.</span>
    <span class="hljs-keyword">address</span> <span class="hljs-keyword">public</span> admin;

    <span class="hljs-comment">// Address of the gateway contract on the chain will contract deployed. </span>
    <span class="hljs-keyword">address</span> <span class="hljs-keyword">public</span> gatewayContract; 

    <span class="hljs-comment">// Gas limit required to handle cross-chain request on the destination chain</span>
    <span class="hljs-keyword">uint64</span> <span class="hljs-keyword">public</span> destGasLimit;

    <span class="hljs-comment">// chain type + chain id =&gt; address of our contract in bytes</span>
    <span class="hljs-keyword">mapping</span>(<span class="hljs-keyword">uint64</span> <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> <span class="hljs-keyword">mapping</span>(<span class="hljs-keyword">string</span> <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> <span class="hljs-keyword">bytes</span>)) <span class="hljs-keyword">public</span> ourContractOnChains;

    <span class="hljs-comment">// Transfer parameter which include tokenId and the address(in bytes) of the receiver on destination chain.</span>
    <span class="hljs-keyword">struct</span> <span class="hljs-title">TransferParams</span> {
        <span class="hljs-keyword">uint256</span> nftId;
        <span class="hljs-keyword">bytes</span> recipient;
    }
}
</code></pre>
<h4 id="heading-implementing-the-constructor"><strong>Implementing the Constructor</strong></h4>
<p>When we implement the constructor, we set the state variables in the constructor and mint an NFT (ERC721) to the <code>msg.sender</code>.</p>
<p>File <code>CrossERC721.sol</code>:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// ...</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">CrossERC721</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span>, <span class="hljs-title">ICrossTalkApplication</span> </span>{
    <span class="hljs-comment">// ...</span>

    <span class="hljs-comment">/// @notice Constructor to initialize the contract.</span>
    <span class="hljs-comment">/// @param gatewayAddress - Address of the gateway contract on the chain on which we will deploy the contract</span>
    <span class="hljs-comment">/// @param _destGasLimit - Gas limit required to handle cross-chain request on the destination chain.</span>
    <span class="hljs-comment">/// @param tokenId - Token Id of the NFT to be minted for testing.</span>
    <span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">payable</span> gatewayAddress,
        <span class="hljs-keyword">uint64</span> _destGasLimit,
        <span class="hljs-keyword">uint256</span> tokenId
    </span>) <span class="hljs-title">ERC721</span>(<span class="hljs-params"><span class="hljs-string">"CrossERC721"</span>, <span class="hljs-string">"cerc721"</span></span>) </span>{
        gatewayContract <span class="hljs-operator">=</span> gatewayAddress;
        destGasLimit <span class="hljs-operator">=</span> _destGasLimit;
        admin <span class="hljs-operator">=</span> <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>;
        _mint(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>, tokenId);
    }
}
</code></pre>
<h4 id="heading-implementing-the-setcontractonchain-method"><strong>Implementing the setContractOnChain Method</strong></h4>
<p>Implement <code>setContractOnChain</code> to map all the contract addresses of the contract on different chains. The mapping is used to verify the contract with which we will interact.</p>
<p>File <code>CrossERC721.sol</code>:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// ...</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">CrossERC721</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span>, <span class="hljs-title">ICrossTalkApplication</span> </span>{
    <span class="hljs-comment">// ...</span>

    <span class="hljs-comment">/// @notice Constructor to initialize the contract.</span>
    <span class="hljs-comment">/// @param gatewayAddress - Address of the gateway contract on the chain on which we will deploy the contract</span>
    <span class="hljs-comment">/// @param _destGasLimit - Gas limit required to handle cross-chain request on the destination chain.</span>
    <span class="hljs-comment">/// @param tokenId - Token Id of the NFT to be minted for testing.</span>
    <span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">payable</span> gatewayAddress,
        <span class="hljs-keyword">uint64</span> _destGasLimit,
        <span class="hljs-keyword">uint256</span> tokenId
    </span>) <span class="hljs-title">ERC721</span>(<span class="hljs-params"><span class="hljs-string">"CrossERC721"</span>, <span class="hljs-string">"cerc721"</span></span>) </span>{
        gatewayContract <span class="hljs-operator">=</span> gatewayAddress;
        destGasLimit <span class="hljs-operator">=</span> _destGasLimit;
        admin <span class="hljs-operator">=</span> <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>;
        _mint(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>, tokenId);
    }
}
</code></pre>
<h4 id="heading-implementing-the-setcontractonchain-method-1"><strong>Implementing the setContractOnChain Method</strong></h4>
<p>Implement <code>setContractOnChain</code> to map all the contract addresses of the contract on different chains. The mapping is used to verify the contract with which we will interact.</p>
<p>File <code>CrossERC721.sol</code>:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// ...</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">CrossERC721</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span>, <span class="hljs-title">ICrossTalkApplication</span> </span>{
    <span class="hljs-comment">// ...</span>

    <span class="hljs-comment">/// @notice Function to map all the contract addresses on different chains.</span>
    <span class="hljs-comment">/// @param chainType - Type of the chain specified by the Router Protocol on which we will deploy the contract</span>
    <span class="hljs-comment">/// @param chainId - Chain Id of the chain on which the contract is deployed.</span>
    <span class="hljs-comment">/// @param contractAddress - Address of the contract on the chain</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setContractOnChain</span>(<span class="hljs-params">
        <span class="hljs-keyword">uint64</span> chainType,
        <span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> chainId,
        <span class="hljs-keyword">address</span> contractAddress
    </span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> </span>{
        <span class="hljs-built_in">require</span>(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span> <span class="hljs-operator">=</span><span class="hljs-operator">=</span> admin, <span class="hljs-string">"only admin"</span>);

        <span class="hljs-comment">// CrossTalkUtils.toBytes() is a function which converts the address to bytes.</span>
        ourContractOnChains[chainType][chainId] <span class="hljs-operator">=</span> CrossTalkUtils.toBytes(
            contractAddress
        );
    }
}
</code></pre>
<h4 id="heading-implementing-the-transfercrosschain-method"><strong>Implementing the transferCrossChain Method</strong></h4>
<p>Implement <code>transferCrossChain</code>, the core function of our contract. It burns the NFT owned by <code>msg.sender</code> on the source chain and then sends the request of transferring using <code>CrossTalkUtils.singleRequestWithoutAcknowledgement</code>, which sends the request to the gateway contract on the destination chain.</p>
<p>File <code>CrossERC721.sol</code>:</p>
<pre><code class="lang-solidity">        <span class="hljs-comment">// ...</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">CrossERC721</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span>, <span class="hljs-title">ICrossTalkApplication</span> </span>{
    <span class="hljs-comment">// ...</span>

    <span class="hljs-comment">/// @notice Function to transfer the NFT from the source chain to the destination chain.</span>
    <span class="hljs-comment">/// @param chainType - Type of the chain specified by the Router Protocol on which the nft needs to transferred.</span>
    <span class="hljs-comment">/// @param chainId - Chain Id of the destination chain.</span>
    <span class="hljs-comment">/// @param expiryDurationInSeconds - Expiry duration in seconds of the request.</span>
    <span class="hljs-comment">/// @param destGasPrice - Gas price required to handle the cross-chain request on the destination chain.</span>
    <span class="hljs-comment">/// @param _nftId - Token Id of the NFT to be transferred.</span>
    <span class="hljs-comment">/// @param _recepient - Address of the recipient on the destination chain.</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transferCrossChain</span>(<span class="hljs-params">
        <span class="hljs-keyword">uint64</span> chainType,
        <span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> chainId,
        <span class="hljs-keyword">uint64</span> expiryDurationInSeconds,
        <span class="hljs-keyword">uint64</span> destGasPrice,
        <span class="hljs-keyword">uint256</span> _nftId,
        <span class="hljs-keyword">address</span> _recepient
     </span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">payable</span></span> </span>{
         <span class="hljs-built_in">require</span>(
             <span class="hljs-built_in">keccak256</span>(ourContractOnChains[chainType][chainId]) <span class="hljs-operator">!</span><span class="hljs-operator">=</span>
                 <span class="hljs-built_in">keccak256</span>(CrossTalkUtils.toBytes(<span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>))),
             <span class="hljs-string">"ERR:CROSS_CHAIN_CONTRACT_NOT_SET"</span>
         );

         TransferParams <span class="hljs-keyword">memory</span> transferParams <span class="hljs-operator">=</span> TransferParams(
             _nftId,
             CrossTalkUtils.toBytes(_recepient)
         );

         <span class="hljs-built_in">require</span>(_ownerOf(transferParams.nftId) <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>, <span class="hljs-string">"ERR:NOT_OWNER"</span>);

         <span class="hljs-comment">// Burn the NFT of the user on the source chain.</span>
         _burn(transferParams.nftId);

         <span class="hljs-comment">// Encode the transfer parameters to bytes for sending it as payload to the gateway contract.</span>
         <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> payload <span class="hljs-operator">=</span> <span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encode</span>(transferParams);

         <span class="hljs-keyword">uint64</span> expiryTimestamp <span class="hljs-operator">=</span> <span class="hljs-keyword">uint64</span>(<span class="hljs-built_in">block</span>.<span class="hljs-built_in">timestamp</span>) <span class="hljs-operator">+</span>
             expiryDurationInSeconds;

         Utils.DestinationChainParams <span class="hljs-keyword">memory</span> destChainParams <span class="hljs-operator">=</span> Utils
             .DestinationChainParams(
                 destGasLimit,
                 destGasPrice,
                 chainType,
                 chainId
         );

         <span class="hljs-comment">// Call the singleRequestWithoutAcknowledgement() function </span>
         <span class="hljs-comment">// to transfer the NFT from the source chain to the</span>
         <span class="hljs-comment">// destination chain without any acknowledgment.</span>
         CrossTalkUtils.singleRequestWithoutAcknowledgement(
             gatewayContract,
             expiryTimestamp,
             destChainParams,
             ourContractOnChains[chainType][chainId],
             payload
         );
    }
}
</code></pre>
<h4 id="heading-implementing-the-handlerequestfromsource-method"><strong>Implementing the handleRequestFromSource Method</strong></h4>
<p>Implement <code>handleRequestFromSource</code> for the contract on the destination chain. Since we must deploy the contract on every chain we interact with, we must include the receiving function in the same contract. We mint the NFT for the receiver's address on the destination chain in this function.</p>
<p>File <code>CrossERC721.sol</code>:</p>
<pre><code class="lang-solidity"> <span class="hljs-comment">// ...</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">CrossERC721</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span>, <span class="hljs-title">ICrossTalkApplication</span> </span>{
    <span class="hljs-comment">// ...</span>

    <span class="hljs-comment">/// @notice Function to handle the request from the gateway contract on the destination chain. It manages data received and calls the function(s).</span>
    <span class="hljs-comment">/// @param srcContractAddress is the contract address on the source chain.</span>
    <span class="hljs-comment">/// @param payload is the data received from the source chain in bytes.</span>
    <span class="hljs-comment">/// @param srcChainId is the chain id of the source chain.</span>
    <span class="hljs-comment">/// @param srcChainType is the chain type of the source contrac specified by the Router Protocol.</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleRequestFromSource</span>(<span class="hljs-params">
        <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> srcContractAddress,
        <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> payload,
        <span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> srcChainId,
        <span class="hljs-keyword">uint64</span> srcChainType
    </span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span></span>) </span>{
        <span class="hljs-built_in">require</span>(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span> <span class="hljs-operator">=</span><span class="hljs-operator">=</span> gatewayContract, <span class="hljs-string">"ERR:NOT_GATEWAY_CONTRACT"</span>);
        <span class="hljs-built_in">require</span>(
            <span class="hljs-built_in">keccak256</span>(srcContractAddress) <span class="hljs-operator">=</span><span class="hljs-operator">=</span>
                <span class="hljs-built_in">keccak256</span>(ourContractOnChains[srcChainType][srcChainId]),
            <span class="hljs-string">"ERR:CONTRACT_NOT_FOUND"</span>
        );

        TransferParams <span class="hljs-keyword">memory</span> transferParams <span class="hljs-operator">=</span> <span class="hljs-built_in">abi</span>.<span class="hljs-built_in">decode</span>(
            payload,
            (TransferParams)
        );

        <span class="hljs-comment">// Mint the NFT for the recipient address on the destination chain.</span>
        _mint(
            CrossTalkUtils.toAddress(transferParams.recipient),
            transferParams.nftId
        );

        <span class="hljs-comment">// Since we don't want to return any data, we will just return empty string</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">""</span>;
    }
}
</code></pre>
<h4 id="heading-implementing-the-handlecrosstalkack-method"><strong>Implementing the handleCrossTalkAck Method</strong></h4>
<p>Implement <code>handleCrossTalkAck</code>, which handles the acknowledgment by the gateway contract after the transaction on the destination chain executes. Since we are using <code>singleRequestWithoutAcknowledgement</code> type of request, we will leave this function empty.</p>
<p>File <code>CrossERC721.sol</code>:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// ...</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">CrossERC721</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span>, <span class="hljs-title">ICrossTalkApplication</span> </span>{
    <span class="hljs-comment">// ...</span>

    <span class="hljs-comment">/// @notice Function to handle the acknowledgement received by the gateway contract for the functions executed on the destination chain.</span>
    <span class="hljs-comment">/// Since we are not expecting any acknowledgement, we will just keep this function empty.</span>
    <span class="hljs-comment">/// @param eventIdentifier is the event identifier of the request.</span>
    <span class="hljs-comment">/// @param execFlags is the array of boolean values which specifies whether the function executed successfully or not on destination chain.</span>
    <span class="hljs-comment">/// @param execData is the array of bytes which contains the data returned by the function executed on the destination chain.</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleCrossTalkAck</span>(<span class="hljs-params">
        <span class="hljs-keyword">uint64</span> eventIdentifier,
        <span class="hljs-keyword">bool</span>[] <span class="hljs-keyword">memory</span> execFlags,
        <span class="hljs-keyword">bytes</span>[] <span class="hljs-keyword">memory</span> execData
    </span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> </span>{}
}
</code></pre>
<p><strong>CONGRATSSS, you wrote the cross-chain contract 🎉</strong></p>
<blockquote>
<p><em>You can find the complete contract</em> <a target="_blank" href="https://github.com/megabyte0x/CrossERC721/blob/main/contracts/CrossERC721.sol"><em>on GitHub</em></a><em>.</em></p>
</blockquote>
<h2 id="heading-deploying-the-contract"><strong>Deploying the Contract</strong></h2>
<p>We will deploy our contract on <strong>Polygon Mumbai Testnet</strong> and <strong>Avalanche Fuji Testnet</strong>.</p>
<p>For <em>BONUS!!!</em> we will verify it on their respective block explorers, <a target="_blank" href="https://mumbai.polygonscan.com/"><strong>PolygonScan</strong></a> and <a target="_blank" href="https://testnet.snowtrace.io/"><strong>Snowtrace</strong></a></p>
<h3 id="heading-creating-a-deployment-script">Creating a Deployment Script</h3>
<p>Create a file at <code>scripts/deploy.ts</code> with the following content.</p>
<p>File <code>deploy.ts</code>:</p>
<pre><code class="lang-solidity"><span class="hljs-keyword">import</span> { <span class="hljs-title">ethers</span> } <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"hardhat"</span>;

async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>) </span>{
  const network <span class="hljs-operator">=</span> await hre.network;

  const gatewayContract <span class="hljs-operator">=</span>
    network.config.chainId <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-number">43113</span>
      ? <span class="hljs-string">"0x517f256cc48145c25c27cf453f6f5006e5266543"</span>
      : <span class="hljs-string">"0x8EA05371Eb360Eb79c295375CB2cCE9191EFdaD0"</span>;

  const tokenId <span class="hljs-operator">=</span> network.config.chainId <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-number">43113</span> ? <span class="hljs-number">1</span> : <span class="hljs-number">2</span>;

  const CrossERC721 <span class="hljs-operator">=</span> await ethers.getContractFactory(<span class="hljs-string">"CrossERC721"</span>);
  const crossERC721 <span class="hljs-operator">=</span> await CrossERC721.deploy(
    gatewayContract,
    <span class="hljs-number">1000000</span>,
    tokenId
  );

  await crossERC721.deployed();

  console.log(<span class="hljs-string">"CrossERC721 deployed to:"</span>, crossERC721.<span class="hljs-built_in">address</span>);

  console.log(<span class="hljs-string">"Sleeping....."</span>);
  await sleep(<span class="hljs-number">40000</span>);

  await hre.run(<span class="hljs-string">"verify:verify"</span>, {
    <span class="hljs-keyword">address</span>: crossERC721.<span class="hljs-built_in">address</span>,
    constructorArguments: [gatewayContract, <span class="hljs-number">1000000</span>, tokenId],
  });
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sleep</span>(<span class="hljs-params">ms: number</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Promise((resolve) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> setTimeout(resolve, ms));
}

main()
  .then(() <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> process.exit(<span class="hljs-number">0</span>))
  .catch((<span class="hljs-function"><span class="hljs-keyword">error</span>) =&gt; </span>{
    console.error(<span class="hljs-function"><span class="hljs-keyword">error</span>)</span>;
    process.exitCode <span class="hljs-operator">=</span> <span class="hljs-number">1</span>;
  });
</code></pre>
<h3 id="heading-executing-the-deployment-script"><strong>Executing the Deployment Script</strong></h3>
<p>Run the following commands in the terminal in the root directory:</p>
<pre><code class="lang-bash">$ npx hardhat run scripts/deploy.ts --network mumbai
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676272427278/688b7c8b-441a-4f19-ae1e-33fc475d52de.png?auto=compress,format&amp;format=webp" alt /></p>
<blockquote>
<p>SAVE the above👆 address and URL</p>
<p>0xB905345D930707C992ec768Cf748AaBc0D3207Da</p>
<p><a target="_blank" href="https://mumbai.polygonscan.com/address/0xB905345D930707C992ec768Cf748AaBc0D3207Da#code"><strong>https://mumbai.polygonscan.com/address/0xB905345D930707C992ec768Cf748AaBc0D3207Da#code</strong></a></p>
</blockquote>
<pre><code class="lang-bash">  $ npx hardhat run scripts/deploy.ts --network fuji
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676272433212/3946d79e-d8f4-4f0f-91f2-94566389b47f.png?auto=compress,format&amp;format=webp" alt /></p>
<blockquote>
<p>SAVE the above👆 URL</p>
<p>0xC0438dF8A5008Af185B36F4f2C38be410C9ce95d</p>
<p><a target="_blank" href="https://testnet.snowtrace.io/address/0xC0438dF8A5008Af185B36F4f2C38be410C9ce95d#code"><strong>https://testnet.snowtrace.io/address/0xC0438dF8A5008Af185B36F4f2C38be410C9ce95d#code</strong></a></p>
</blockquote>
<p>You deployed and verified your contract on both chains. <strong>Awesome!!! 🎉🎉</strong></p>
<h2 id="heading-interacting-with-the-contract"><strong>Interacting with the Contract</strong></h2>
<p>To interact with our freshly deployed contracts, open the two URLs you saved in different tabs in your browser.</p>
<h3 id="heading-on-the-mumbaiscan-tab">On the MumbaiScan tab</h3>
<ol>
<li><p>click "Write Contract".</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676216219347/5b117804-c4ce-4da1-b85d-f172ea23a1d7.png?auto=compress,format&amp;format=webp" alt /></p>
</li>
<li><p>Click on "Connect to Web3" and connect your MetaMmask wallet with it.</p>
</li>
<li><p>Scroll down to "setContractOnChain".</p>
</li>
<li><p>Enter the values. Here the <code>contractAddress</code> value is the address on the Fuji Network.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676272805613/114c36ea-dcd7-4080-a2ea-71d15fa72c27.png?auto=compress,format&amp;format=webp" alt /></p>
</li>
<li><p>Click "Write" and then "Confirm" the transaction.</p>
</li>
</ol>
<h3 id="heading-on-the-snowtrace-tab">On the SnowTrace tab</h3>
<ol>
<li><p>Click "Write Contract".</p>
</li>
<li><p>Click "Connect to Web3".</p>
</li>
<li><p>Scroll down to <code>setContractOnChain</code></p>
</li>
<li><p>Enter the values.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676272857949/8b6d5ee2-5186-4022-a48f-087625514ff6.png?auto=compress,format&amp;format=webp" alt /></p>
</li>
<li><p>Click "Write" and "Confirm" the transaction.</p>
<blockquote>
<p>We have set the contracts on both the source and destination chains.</p>
</blockquote>
</li>
<li><p>Scroll to the <code>transferCrossChain</code></p>
</li>
<li><p>Enter the values.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676273060103/040ee804-4354-42ed-8f13-387dfdb5510a.png?auto=compress,format&amp;format=webp" alt /></p>
</li>
<li><p>Click "Write" and "Confirm" the transaction.</p>
</li>
<li><p>Copy <code>recepient</code> and paste it into the destination chain (POLYGON MUMBAI) block explorer.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676273200301/8fa1ee68-3197-4059-abb4-c49f8d301d85.png?auto=compress,format&amp;format=webp" alt /></p>
</li>
</ol>
<p><strong>Hoorrayyy!!! 🎉🎉</strong></p>
<p>You just transferred an NFT from Avalanche Fuji Testnet to Polygon Mumbai Testnet. You can do the same with NFTs on Polygon Mumbai Testnet.</p>
<p><strong>PS: You can check out the whole project here👇🏻</strong></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://github.com/megabyte0x/CrossERC721">https://github.com/megabyte0x/CrossERC721</a></div>
<p> </p>
<p>So, we have created an ERC721 with the implementation of Router Protocol's Cross Talk Library which helped us to transfer our NFT from Avalanche to Polygon.</p>
<p>You can do the same with ERC20 and others, and make your application more <strong>SCALABLE, SECURE, and DENCTRALISED</strong>.</p>
<hr />
<p>Connect with me on Lens🌿[<a class="user-mention" href="https://hashnode.com/@megabyte0x">@megabyte0x</a><strong>.lens] or Twitter[</strong><a class="user-mention" href="https://hashnode.com/@megabyte0x">@megabyte0x</a><strong>].</strong></p>
<p>Also, feel free to share your learnings and reach out to me if you've any doubts or questions for me.</p>
<p>Happy building! 🛠️</p>
<p><strong>WAGMI🚀</strong></p>
]]></content:encoded></item></channel></rss>