<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by nptytn on Medium]]></title>
        <description><![CDATA[Stories by nptytn on Medium]]></description>
        <link>https://medium.com/@nptytng?source=rss-178763a9e484------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xqqrsqbeatKaF-JJVgdr5g.jpeg</url>
            <title>Stories by nptytn on Medium</title>
            <link>https://medium.com/@nptytng?source=rss-178763a9e484------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 04:36:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nptytng/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ทำความรู้จัก Connext Protocol]]></title>
            <link>https://nptytng.medium.com/%E0%B8%97%E0%B8%B3%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81-connext-protocol-1c9e08e14539?source=rss-178763a9e484------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c9e08e14539</guid>
            <category><![CDATA[connext-network]]></category>
            <category><![CDATA[evm]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[crosschain]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[nptytn]]></dc:creator>
            <pubDate>Sun, 12 Dec 2021 03:19:24 GMT</pubDate>
            <atom:updated>2021-12-12T03:32:43.641Z</atom:updated>
            <content:encoded><![CDATA[<p>ก่อนอื่นมาทำความรู้จักกับ crosschain-protocol ที่ดีกันก่อนครับ เริ่มต้นด้วยคุณสมบัติสำคัญ 3 ประการของ cross-chain protocol: <strong>The Interoperability Trilemma</strong></p><h3>The Interoperability Trilemma</h3><p>1. <strong>Trustlessness</strong> — ผู้ใช้งานต้องไม่จำเป็นต้องเชื่อใจใครในระบบว่าจะโกงหรือไม่ ความปลอดภัยต้องเทียบเท่ากับ chain ต้นทางที่เริ่มทำการ crosschain</p><p>2. <strong>Extensibility</strong> — เพิ่ม support chain ใหม่ๆได้ง่าย</p><p>3. <strong>Generalizeability</strong> — สามารถย้ายข้อมูลอะไรก็ได้ ไม่จำเป็นต้องเป็นการ transfer token ข้าม chain เสมอไป</p><p>ถ้าหากเคยรู้จักกับ <a href="https://vitalik.ca/general/2021/04/07/sharding.html">The Scalability Trilemma ของ Vitalik</a> จะทราบดีว่าการที่จะได้คุณสมบัติครบทั้ง 3 ข้อนั้นเป็นไปได้ยากมาก ดังนั้น cross-chain protocol ต่างๆจึงทำได้เพียง 2 ข้อเท่านั้น</p><h3>Connext มีคุณสมบัติอย่างไรบ้าง?</h3><p>เนื่องจากการมีคุณสมบัติครบทั้งสามข้อทำให้เกิดขึ้นจริงได้ยาก ดังนั้น Connext จึงความสำคัญแบบเดียวกับ Ethereum ครับ สิ่งที่ Ethereum ให้ความสำคัญคือ Decentralized และ Security โดยแลกกับ Scalibity ไป เหตุผลคือคุณสมบัติทั้งสองข้อนั้นเป็นจุดที่สำคัญที่สุดในการใช้งาน blockchain ภายหลังจากนั้น Ethereum จึงปล่อยเรื่อง Scalability เป็นหน้าที่ของ L2 solutions ต่างๆ</p><p>ดังนั้น Connext จึงเลือกแนวทางเดียวกับ Ethereum นั่นคือ <strong>Trustlessness</strong> และ <strong>Extensibility</strong> หมายความว่า Connext จะมีความปลอดภัยเทียบเท่ากับ chain ต้นทางและปลายทาง และสามารถต่อยอดไป chain อื่นๆได้ง่าย</p><p><strong>คำถามต่อไปคือแล้ว Generalizeability ล่ะ Connext มองยังไง?</strong></p><p>Connext ใช้แนวทางเดียวกับ Layer 2 ของ Ethereum ในการเพิ่ม plugin ขึ้นมาต่อยอดจากระบบเดิม (จะมองว่าเป็น L2 ของ Connext ก็ได้) เป็นการเปิดประตูให้สามารถอัพเกรดความสามารถได้นั่นเอง</p><h3>การทำงานของ Connext Protocol</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L9kv5DzmPozX_o5_.png" /></figure><p>การ cross-chain transfer บน Connext Protocol จะประกอบด้วยขั้นตอนทั้งหมด 3 ขั้นตอน</p><p>1. <strong>Route Selection</strong>: ผู้ใช้งานเลือก chain ต้นทาง — ปลายทาง และ token ที่ต้องการที่จะ transfer จากนั้นระบบจะทำการประมูลเพื่อหาราคาในการแลกเปลี่ยนที่ดีที่สุดให้เนื่องจาก Connext เปิดให้ใครรัน Router ขึ้นมาก็ได้ และแต่ละ Router มีจำนวน Liquidity ที่ไม่เท่ากัน (ดู liquidity ของแต่ละ router ได้ที่นี่ <a href="https://connextscan.io/routers">https://connextscan.io/routers</a>)</p><p>2. <strong>Prepare</strong>: ผู้ใช้งานส่ง transaction (มีการจ่ายค่า fee) เพื่อ transfer token ไปที่ smart contract ของ connext ที่ chain ต้นทาง เมื่อ connext ตรวจพบว่ามีการโอน token เข้ามาแล้ว connext จะทำการล็อก token ที่ chain ปลายทางให้</p><p>3. <strong>Fulfill</strong>: ผู้ใช้งานส่ง signature (ไม่เสียค่า gas เพราะจ่าย fee ขั้นตอนที่ 2 ไปแล้ว) เพื่อ withdraw เงินที่ chain ปลายทางออกมาเข้า wallet หลังจากนั้น connext จึงโอน token ของเราที่อยู่บน chain ต้นทางไปเก็บไว้ใน liquidity pool ของ router ที่ได้รับเลือกมา เป็นอันจบพิธี</p><p>จะเห็นได้ว่าในทุกๆขั้นตอนจะมีการ submit data ขึ้นไปเก็บไว้ที่ blockchain เสมอ (กล่องสีม่วง) ดังนั้นผู้ใช้งานจึงไม่ต้องห่วงว่าถ้าระบบล่มระหว่างทางจะทำให้เงินหายหรือไม่ เพราะระบบสามารถอ่านค่าจาก blockchain เพื่อ recover มาทำงานต่อได้นั่นเองครับ</p><h3>ทำไม Connext ถึงน่าสนใจ?</h3><p>จากคุณสมบัติของ Connext Protocol ที่กล่าวมาทำให้ Connext มีความปลอดภัยในการใช้งานสูง ดังนั้นเราลองมาดูประโยชน์ทีละข้อกันครับ</p><ul><li>ไม่ต้องกังวลว่าเงินจะหาย — เพราะต่อให้ระบบ connext offline, หรือล่มไปก่อนครบ flow ผู้ใช้งานก็ยังคงสามารถ claim เงินกลับคืนมาได้เสมอ เพราะ connext มีระบบ timeout ซึ่งถ้าการ crosschain ใช้เวลานานกว่าที่กำหนด user ก็สามารถ claim เงินคืนได้ตลอดเวลา</li><li>การต่อยอดทำได้ง่าย — เนื่องจากใครๆก็สามารถรัน router ขึ้นมาเองได้</li><li>มี solution แก้ปัญหาเรื่อง liquidity — Connext มีระบบ Virtual AMM ที่มี incentive ในการ arbitrage ทำกำไรกับ chain ที่มี liquidity ต่ำ เพื่อเพิ่ม liquidity ให้กลับมายังจุดสมดุลได้</li><li>นอกจากนี้ยังมี explorer ให้ดูสถานะต่างๆโดยละเอียด <a href="https://connextscan.io/">https://connextscan.io/</a> สามารถดูได้ว่าตอนนี้รองรับ chain ไหนบ้าง, มีจำนวน liquidity เท่าไหร่, เหรียญอะไรบ้าง และติดตาม transaction ของเราได้ทุกขั้นตอน</li></ul><p>สำหรับใครที่สนใจอยากลองเล่นสามารถลองได้แล้วที่ <a href="https://t.co/pNjLR9iai6">xpollinate.io</a> ครับ</p><h4>ช่องทางติดตาม Connext</h4><p><strong>Discord: </strong><a href="https://discord.gg/connext">https://discord.gg/connext</a><br><strong>Twitter:</strong> <a href="https://twitter.com/ConnextNetwork">https://twitter.com/ConnextNetwork</a><br><strong>Website</strong>: <a href="https://connext.network/">https://connext.network/</a><br><strong>Product:</strong> <a href="https://t.co/pNjLR9iai6">xpollinate.io</a><br><strong>Documentation เวอร์ชั่นไทย:</strong> <a href="https://thai-contribute-community.github.io/connext-documentation/Integration/SystemOverview/howitworks/">https://thai-contribute-community.github.io/connext-documentation/Integration/SystemOverview/howitworks/</a></p><h4>Reference:</h4><ul><li><a href="https://nxtp-docs.connext.network/Integration/SystemOverview/howitworks/">https://nxtp-docs.connext.network/Integration/SystemOverview/howitworks/</a></li><li><a href="https://medium.com/connext/solving-the-liquidity-problem-88bde201501">https://medium.com/connext/solving-the-liquidity-problem-88bde201501</a></li><li><a href="https://medium.com/connext/nxtp-a-simpler-xchain-protocol-88760697ea04">https://medium.com/connext/nxtp-a-simpler-xchain-protocol-88760697ea04</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c9e08e14539" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ทำความรู้จักสถาปัตยกรรมของ Umee]]></title>
            <link>https://nptytng.medium.com/%E0%B8%97%E0%B8%B3%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81%E0%B8%AA%E0%B8%96%E0%B8%B2%E0%B8%9B%E0%B8%B1%E0%B8%95%E0%B8%A2%E0%B8%81%E0%B8%A3%E0%B8%A3%E0%B8%A1%E0%B8%82%E0%B8%AD%E0%B8%87-umee-6d6880ee42bc?source=rss-178763a9e484------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d6880ee42bc</guid>
            <category><![CDATA[umee]]></category>
            <category><![CDATA[crosschain]]></category>
            <category><![CDATA[tendermint]]></category>
            <category><![CDATA[lendingprotocol]]></category>
            <category><![CDATA[cosmos]]></category>
            <dc:creator><![CDATA[nptytn]]></dc:creator>
            <pubDate>Sun, 21 Nov 2021 17:00:41 GMT</pubDate>
            <atom:updated>2021-11-21T17:00:41.167Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับ ก่อนอื่นเรามาทำความรู้จักก่อนว่า <strong>ทำไมถึงต้อง Umee?</strong></p><p>Umee บล็อกเชนเป็นระบบโครงสร้างพื้นฐานของระบบนิเวศของโปรโตคอล DeFi เนื่องจากระบบ Consensus ของ Umee มีการ Finality ที่รวดเร็ว Umee มีพื้นฐานมีจาก <a href="https://docs.umee.cc/umee/umee-technical-overview/untitled/architecture-overview#tendermint-consensus">Proof of Stake ของ Tendermint</a> มีการนำเสนอระบบที่มีความยืดหยุ่น รวดเร็วและมีประสิทธิภาพในการส่ง transaction บนบล็อกเชน ระหว่างที่บล็อกเชนทั่วไปกำลังสร้างสังคม การเมือง และระบบเศรษฐกิจใหม่ ขณะเดียวกัน Umee ก็กำลังสร้างมาตรฐานของ DeFi การปล่อยกู้และยืมระหว่างบล็อกเชน</p><p><strong>Umee นำเสนอการปรับตัวในการสื่อสารข้ามบล็อกเชนแบบใหม่</strong></p><p>Umee ได้ใช้งานระบบ <a href="https://docs.umee.cc/umee/umee-technical-overview/untitled/architecture-overview#ibc">IBC</a> ซึ่งเป็นเอกลักษณ์ที่สำคัญของโปรโตคอล Cosmos ในการสื่อสารระหว่างเชน เพื่อที่จะทำให้การโอน token จากบล็อกเชนหนึ่งไปยังอีกบล็อกเชนหนึ่งมีความรวดเร็ว โดยไม่จำเป็นที่ต้องมีการ confirm บล็อกหลายๆบล็อก หรือต้องมีการรอที่ไม่จำเป็น Umee ที่ใช้งาน <a href="https://docs.umee.cc/umee/umee-technical-overview/untitled/architecture-overview#gravity-bridge">Gravity Bridge</a> สำหรับการเชื่อมต่อบล็อกเชนที่มี consensus finality ที่รวดเร็ว กับ บล็อกเชนที่อาศัยการ finality โดยใช้ความน่าจะเป็น (เรียกว่า <strong>Probabililstic Finality</strong> ยกตัวอย่างเช่น Bitcoin ที่ต้องรอการ confirm หลายๆบล็อก ยิ่งมี confirm หลายบล็อก ยิ่งทำให้ความน่าจะเป็นที่ transaction จะถูก reverted น้อยลง) Transaction ที่เกิดขึ้นบนบล็อกเชนของ Umee จะสามารถมีปฏิสัมพันธ์กับบล็อกเชนอื่นๆได้อย่างเป็นธรรมชาติ (native)</p><p>อ่านถึงตรงนี้เราจะเห็นภาพ Umee คร่าวๆ สามารถสรุปได้ว่าเป็นบล็อกเชนตัวกลางที่สามารถเชื่อมต่อระหว่างบล็อกเชนได้ โดยเน้นไปที่ DeFi แบบกู้ยืมนั่นเองครับ</p><p>เนื่องจากบทความนี้พูดถึงเรื่องสถาปัตยกรรมของ Umee ดังนั้นมาทำความรู้จักกันเชิงลึกกันต่อครับ เอาล่ะเข้าเรื่องกันดีกว่าครับ</p><h3><strong>สถาปัตยกรรมของ Umee</strong></h3><p>มาเริ่มดูกันทีละส่วนนะครับ เริ่มที่ส่วนแรก</p><p><strong>Universal Debt Facility</strong></p><p>ส่วนนี้คือนวัตกรรมสำคัญของ Umee เลยก็ว่าได้ ซึ่งเป็น layer ระดับพื้นฐานที่สุดของโปรโตคอลกู้ยืมโดยใช้ SDK ของ Cosmos ในการเปิดโอกาสให้นักพัฒนาทั่วไปสามารถออกแบบ พัฒนา และนำระบบการจัดการหนี้ขึ้นไปทำงานบน Umee ได้ ทำให้ระบบของ Umee มีความยืดหยุ่นในการต่อยอดพัฒนาให้ตอบโจทย์ในการใช้งานด้านต่างๆมากยิ่งขึ้น</p><p><strong>Asset Coordination Protocol</strong></p><p>Umee ทราบดีว่าทุกวันนี้การโอน debt position ระหว่างเชนจะต้องใช้งานผ่านโปรเจ็ค bridge ต่างๆ ซึ่งมีกระบวนการหลายขั้นตอน ทำให้เกิดความล่าช้า Umee จึงคิดค้นนวัตกรรมใหม่ ที่สามารถให้ผู้ปล่อยกู้ฝากเงินที่เชนนั้นได้เลย และจะได้ <a href="https://docs.umee.cc/umee/umee-technical-overview/collateral-tokens/utokens">uToken</a> กลับมา (uToken คือ interest bearing token แปลว่าเป็นตัวแทนทั้งเงินต้นที่ปล่อยกู้ และดอกเบี้ยที่ได้รับเพิ่มขึ้นเรื่อยๆ) และ uToken สามารถ transfer ระหว่าง Cosmos และ Ethereum ได้เลย</p><p><strong>meToken for Collateralized Liquid Staking Positions</strong></p><p>ระบบการ Stake มีความสำคัญกับบล็อกเชนแบบ Proof of Stake อย่างมาก สำหรับ Umee ก็เช่นกัน แต่สำหรับ Umee มีขั้นตอนพิเศษที่เพิ่มเข้ามาใน core feature ของการออกแบบระบบกู้ยืม นั่นคือ <strong>meToken (</strong>อ่านถึงตรงนี้เข้าใจเลยว่าทำไมชื่อ Umee)</p><p><strong>meToken </strong>เป็นเหรียญตัวแทนของการ Stake บนระบบ Proof of Stake ของ Umee นั่นเอง ซึ่งเราสามารถใช้ meToken นี้ในการกู้ยืมเงินบนบล็อกเชนอื่นๆได้ด้วย! (ในขณะที่โปรโตคอลอื่นเรา Stake แล้ว เราสูญเสียสภาพคล่องของเงินก้อนนั้นไปเลย) ทำให้นอกจากเราจะได้ yield จากการ Stake แล้ว เรายังสามารถกู้ยืมเงินไปทำกำไรในด้านอื่นๆอีกด้วย ด้วยกลไกนี้จึงทำให้ยืมเงินของ Umee มี Capital Efficiency ที่สูง และทำให้ระบบของ Umee มีความปลอดภัยมากขึ้นไปด้วย</p><p><strong>Yield Curves and Staking Curves</strong></p><p>เนื่องจาก Umee เป็นโปรโตคอลระดับพื้นฐานของระบบหนี้ Umee จึงต้องสร้าง yield curve สำหรับคริปโต คล้ายกับ <a href="https://www.investopedia.com/terms/t/timevalueofmoney.asp#:~:text=The%20time%20value%20of%20money%20(TVM)%20is%20the%20concept%20that,be%20paid%20in%20the%20future.">Time Value of Money</a> ใน TradFi (แปลง่ายๆว่าเงินจะเพิ่มขึ้นเมื่อเวลาผ่านไป) แต่ของ Umee จะใช้เป็น <strong>Time Value of Crypto </strong>แทน ระบบ Proof of Stake ของ Umee จะคำนวณไปถึงการเพิ่ม yield เพื่อชดเชยค่าเสียโอกาสบน Crypto ด้วย เมื่อรวมทั้ง Proof of Stake yield, DeFi yield และระบบหนี้เบื้องต้น Umee บล็อกเชน จึงมีความสามารถสร้างโครงสร้างพื้นฐานที่สำคัญในการดึงดูดตลาดหนี้ระดับโลก (Global Debt Market) เข้ามาในโลกของคริปโตได้</p><p><strong>Tendermint Consensus</strong></p><p>Tendermint เป็นหนึ่งในเครื่องมือที่ทรงพลังที่สุดในระบบ p2p และยังเป็นระบบแรกที่ใช้กลไก consensus แบบ BFT (Byzantine Fault Tolerant) Tendermint ประกอบไปด้วยระบบ consensus และแอพพลิเคชั่นพื้นฐานที่เรียกว่า ABCI (Application Blockchain Interface) ทำให้สามารถประมวลผล transaction ได้ไม่ว่าจะถูกเขียนด้วยภาษาใดก็ตาม</p><p>จบไปแล้วครับสำหรับการรีวิวสถาปัตยกรรมของ Umee คร่าวๆ หวังว่าจะเป็นประโยชน์กับผู้อ่านทุกท่าน ถ้าหากสนใจ Umee อยากศึกษาต่อสามารถติดตาม Umee ได้หลายช่องทางต่อไปนี้ครับ</p><p><strong>Twitter</strong>: <a href="https://twitter.com/Umee_CrossChain">https://twitter.com/Umee_CrossChain</a><br><strong>Discord: </strong><a href="https://t.co/Uymz0DkIuK?amp=1">http://bit.ly/3Aiotqe</a><br><strong>Telegram</strong>: <a href="https://t.co/3qQtEuMpmf?amp=1">http://t.me/umeecrosschain</a><br><strong>Medium: </strong><a href="https://t.co/8MZxRDFZ3U?amp=1">medium.com/umeeblog</a><br><strong>Website: </strong><a href="https://umee.cc/">https://umee.cc/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d6880ee42bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding the biggest swap of 1inch v3 on Ethereum and Binance Smart Chain using Web3.js]]></title>
            <link>https://medium.com/covalent-hq/finding-the-biggest-swap-of-1inch-v3-on-ethereum-and-binance-smart-chain-using-web3-js-d3b3df7188a6?source=rss-178763a9e484------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3b3df7188a6</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[covalent]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[1inch]]></category>
            <category><![CDATA[cryptoenglish]]></category>
            <dc:creator><![CDATA[nptytn]]></dc:creator>
            <pubDate>Fri, 21 May 2021 12:56:59 GMT</pubDate>
            <atom:updated>2021-05-25T15:38:11.648Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wonder how to find the event in the smart contract and how to read them?</p><p>In this article, I will present a step-by-step of finding biggest swap in USD on 1inch.</p><blockquote>If you haven’t heard about 1inch, 1inch is a distributed network for decentralized protocols enabling the most lucrative, fastest and protected operations in DeFi.<br>Read more <a href="https://blog.1inch.io/">here</a> and <a href="https://app.1inch.io/">https://app.1inch.io/</a></blockquote><p>Before we can figure it out, Some datas must be prepared beforehand as listed below:</p><ul><li>1Inch router contract address and its ABI</li><li>Swap event name</li><li>Start block of the swap</li><li>Stablecoins token address</li></ul><h3>Prepare data</h3><ol><li><strong>1Inch router contract address and ABI</strong></li></ol><p>I’ve got the 1inch router contract address by trying to make a trade on 1inch, then copy the destination address on Metamask. So I find that 1inch’s router contract address is: 0x11111112542D85B3EF69AE05771c2dCCff4fAa26 .</p><p>the contract ABI can be found at <a href="https://etherscan.io/address/0x11111112542D85B3EF69AE05771c2dCCff4fAa26#code">Etherscan</a></p><p>2. <strong>Swap event name</strong></p><p>We need the name of the swap event for filtering events fired from the 1inch’s router contract. So I go to read their contract using <a href="https://etherscan.io/address/0x11111112542D85B3EF69AE05771c2dCCff4fAa26#code">Etherscan</a>, then search for the swap event which can be found as screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZefE9ir1MrlZfxBOWu5IAw.png" /><figcaption>Swapped event in the AggregationRouterV3 contract</figcaption></figure><p>As you can see, the event name is Swapped .</p><p>3. <strong>Start block of the `Swapped` event</strong></p><p>The first block that Swapped event happens must be known because we don’t want to miss any single event. I’m finding it by google for the 1Inch article published on <a href="https://blog.1inch.io/introducing-the-1inch-aggregation-protocol-v3-b02890986547">Medium</a> . The published date is on Mar 16, 2021. Thus, we can assume that there’s no significant Swapped event happened before that.</p><p>The next problem is how to find block number on Mar 16, 2021?<br>Good news, we can easily find it by utilize the Covalent API! The API for this case is <a href="https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/block_v2/{block_height}/">Get block heights</a> API. Let’s try to use it with curl</p><pre>curl -X GET &quot;<a href="https://api.covalenthq.com/v1/1/block_v2/2021-03-16/2021-05-20/?page-size=1&amp;key=ckey_75720a8fd64c4f6f9c6acbabaf9">https://api.covalenthq.com/v1/1/block_v2/2021-03-16/2021-05-20/?page-size=1&amp;key=ckey_75720a8fd64c4f6f9c6acbabaf9</a>&quot; \<br> -H &quot;Accept: application/json&quot;</pre><p>The response is</p><pre>1 {<br>2   &quot;data&quot;: {<br>3     &quot;updated_at&quot;: &quot;2021-05-19T18:21:35.275391530Z&quot;,<br>4     &quot;items&quot;: [<br>5       {<br>6         &quot;signed_at&quot;: &quot;2021-03-16T00:00:09Z&quot;,<br>7         &quot;height&quot;: 12046295<br>8       }<br>9     ],<br>10     &quot;pagination&quot;: {<br>11       &quot;has_more&quot;: true,<br>12       &quot;page_number&quot;: 0,<br>13       &quot;page_size&quot;: 1,<br>14       &quot;total_count&quot;: 420106<br>15     }<br>16   },<br>17   &quot;error&quot;: false,<br>18   &quot;error_message&quot;: null,<br>19   &quot;error_code&quot;: null<br>20 }</pre><p>The block height on Mar 16, 2021 is 12046295 . Great! Thanks to awesome Covalent API.</p><p>4. <strong>Stablecoins contract address</strong></p><p>In this article, I’m going to focus only on the Stablecoins swap because I can omit the price feed services which is more complicate to measure the swap value. To keep things simple, let focus on Stablecoins swap.</p><p>Tokens contract address is easy to find. It can be found from the block explorer or any crypto data aggregator services e.g. Coingecko, Coinmarketcap, etc. So the Stablecoins we’re going to use are:</p><p><strong>Ethereum Chain</strong></p><pre>USDT = 0xdac17f958d2ee523a2206206994597c13d831ec7<br>USDC = 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48<br>DAI = 0x6b175474e89094c44da98b954eedeac495271d0f</pre><p><strong>Binance Smart Chain</strong></p><pre>USDT = 0x55d398326f99059ff775485246999027b3197955<br>USDC = 0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d<br>DAI = 0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3<br>BUSD = 0xe9e7cea3dedca5984780bafc599bd69add087d56</pre><p>Now, I have all required data. Next, let’s see how can I find the biggest swap on 1inch v3.</p><h3>Find the biggest swap on 1Inch v3</h3><ol><li><strong>Setup Node.js project</strong></li></ol><p>First, I created a new Node.js project with npm initin the empty folder with web3.js as a dependency.</p><p>2. <strong>Prepare required datas</strong></p><p>Once I have my project ready, I create a new file called index.js . Next, keep all datas we collected in previous section in variables. Finally, create web3 and contract of 1inch’s aggregator v3.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c72bdcc7d37ab3b542d0a54e36907eef/href">https://medium.com/media/c72bdcc7d37ab3b542d0a54e36907eef/href</a></iframe><p>3. <strong>Read contract past events</strong></p><p>This step is the reason why I want to use web3. Web3 can read all events for given contract address and event name. So my code is now looks like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e2039b062182fc59cd514d28b626ba8/href">https://medium.com/media/8e2039b062182fc59cd514d28b626ba8/href</a></iframe><p>Past events can be read like line 17 — 19 . Unfortunately, Geth RPC service won’t allow client to query events more than 10k events per call. So we need to reduce the returned events per call and keep gradually push them into an array. See line 22 — 33</p><p>If you wonder how event object that returned from getPastEvents looks like, see below:</p><pre>{<br>  address: &#39;0x11111112542D85B3EF69AE05771c2dCCff4fAa26&#39;,<br>  blockNumber: 5746136,<br>  transactionHash: &#39;0x3d838039c450b1af55ba1c57d667bf800177d69936d412e0c698e80b83099007&#39;,<br>  transactionIndex: 48,<br>  blockHash: &#39;0x0928fdc5f83087bcdc97b4ae7bc769b4f91550e42e220722168f9e59c640508e&#39;,<br>  logIndex: 233,<br>  removed: false,<br>  id: &#39;log_40e4073c&#39;,<br>  returnValues: Result {<br>    &#39;0&#39;: &#39;0x0D080A3c3290C98E755d8123908498BcE2C5620d&#39;,<br>    &#39;1&#39;: &#39;0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56&#39;,<br>    &#39;2&#39;: &#39;0x55d398326f99059fF775485246999027B3197955&#39;,<br>    &#39;3&#39;: &#39;0x0D080A3c3290C98E755d8123908498BcE2C5620d&#39;,<br>    &#39;4&#39;: &#39;2000200000000000000000000&#39;,<br>    &#39;5&#39;: &#39;2000031648518588335779396&#39;,<br>    sender: &#39;0x0D080A3c3290C98E755d8123908498BcE2C5620d&#39;,<br>    srcToken: &#39;0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56&#39;,<br>    dstToken: &#39;0x55d398326f99059fF775485246999027B3197955&#39;,<br>    dstReceiver: &#39;0x0D080A3c3290C98E755d8123908498BcE2C5620d&#39;,<br>    spentAmount: &#39;2000200000000000000000000&#39;,<br>    returnAmount: &#39;2000031648518588335779396&#39;<br>  },<br>  event: &#39;Swapped&#39;,<br>  signature: &#39;0xd6d4f5681c246c9f42c203e287975af1601f8df8035a9251f79aab5c8f09e2f8&#39;,<br>  raw: {<br>    data: &#39;0x0000000000000000000000000d080a3c3290c98e755d8123908498bce2c5620d000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d5600000000000000000000000055d398326f99059ff775485246999027b31979550000000000000000000000000d080a3c3290c98e755d8123908498bce2c5620d00000000000000000000000000000000000000000001a78f0f2c56360820000000000000000000000000000000000000000000000001a785eed3b9d4df19ee44&#39;,<br>    topics: [<br>      &#39;0xd6d4f5681c246c9f42c203e287975af1601f8df8035a9251f79aab5c8f09e2f8&#39;<br>    ]<br>  }<br>}</pre><p>4. <strong>Filter </strong><strong>Swapped event for Stablecoins<br></strong>Since we only focus on swap event that has Stablecoins at least one side, we need to filter non-stablecoins swap out.</p><p>How can we get the token contract address from the response? Luckily, it is already included in the event object like above. So you can see dstToken and srcToken which mean:</p><ul><li>dstToken contract address of the token that sender will get after swap.</li><li>srcToken contract address of the token that sender uses for swap.</li></ul><p>We’re already had Stablecoins contract address, so my code evolves to this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3a0092799cc6b339def284a5d7414dd/href">https://medium.com/media/b3a0092799cc6b339def284a5d7414dd/href</a></iframe><p>Let’s take a look at the additional code from previous step.</p><p><strong>Line 34 to 42<br>- </strong>Check if the event is Stablecoins swap<br>- If it is Stablecoins swap, then assign bigger swap event to biggestSwap variable</p><p><strong>Line 45 to 46<br>- </strong>Increment blocks for querying past events.</p><p><strong>Line 49</strong><br>- Print the biggest swap</p><p><strong>Line 52–58<br>- </strong>Return true if the given token contract address is one of <strong>USDT</strong>, <strong>USDC</strong> or <strong>DAI</strong></p><p>And the final line prints the biggest swap transaction.</p><p>The result is below:</p><pre>{<br>  address: &#39;0x11111112542D85B3EF69AE05771c2dCCff4fAa26&#39;,<br>  blockHash: &#39;0x7936392cd01131f7e21bdd353a4b5a7b96f8fd3bba0d02fa9e2afada1365c74e&#39;,<br>  blockNumber: 12446903,<br>  logIndex: 69,<br>  removed: false,<br>  transactionHash: &#39;0x6b1594e1a7aa3f2dfa3b00f8913745d961579d7e7e97950364cce11c02459d56&#39;,<br>  transactionIndex: 5,<br>  id: &#39;log_bc980976&#39;,<br>  returnValues: Result {<br>    &#39;0&#39;: &#39;0xB66f8015E916e0d6590761Ed299BF4B3BDF40006&#39;,<br>    &#39;1&#39;: &#39;0x6B175474E89094C44Da98b954EedeAC495271d0F&#39;,<br>    &#39;2&#39;: &#39;0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&#39;,<br>    &#39;3&#39;: &#39;0xB66f8015E916e0d6590761Ed299BF4B3BDF40006&#39;,<br>    &#39;4&#39;: &#39;31407288037329481247334373&#39;,<br>    &#39;5&#39;: &#39;8607683887337745631338&#39;,<br>    sender: &#39;0xB66f8015E916e0d6590761Ed299BF4B3BDF40006&#39;,<br>    srcToken: &#39;0x6B175474E89094C44Da98b954EedeAC495271d0F&#39;,<br>    dstToken: &#39;0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&#39;,<br>    dstReceiver: &#39;0xB66f8015E916e0d6590761Ed299BF4B3BDF40006&#39;,<br>    spentAmount: &#39;31407288037329481247334373&#39;,<br>    returnAmount: &#39;8607683887337745631338&#39;<br>  },<br>  event: &#39;Swapped&#39;,<br>  signature: &#39;0xd6d4f5681c246c9f42c203e287975af1601f8df8035a9251f79aab5c8f09e2f8&#39;,<br>  raw: {<br>    data: &#39;0x000000000000000000000000b66f8015e916e0d6590761ed299bf4b3bdf400060000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000b66f8015e916e0d6590761ed299bf4b3bdf4000600000000000000000000000000000000000000000019fac07f003f6ee5459fe50000000000000000000000000000000000000000000001d29f9c4a11e3d3486a&#39;,<br>    topics: [<br>      &#39;0xd6d4f5681c246c9f42c203e287975af1601f8df8035a9251f79aab5c8f09e2f8&#39;<br>    ]<br>  }<br>}</pre><p>You can see the details of this transaction <a href="https://etherscan.io/tx/0x6b1594e1a7aa3f2dfa3b00f8913745d961579d7e7e97950364cce11c02459d56">here</a>. It’s worth about $31M and paid 0.91 ETH for gas fee.</p><p>For Binance Smart Chain, it will be a little different. For example, the BSC node won’t allow query that returns more than 5000 results and the Geth rpc node is down quite often. So you might consider reduce eventsPerRound and wrap the getPastEvent call with retry logic. If you are curious the result in the BSC. The result is below (the latest block is 7601227 when the script runs)</p><pre>{<br>  address: &#39;0x11111112542D85B3EF69AE05771c2dCCff4fAa26&#39;,<br>  blockNumber: 7360052,<br>  transactionHash: &#39;0xd58b583ccc04c2502828bd1d20a7d31f61806a839108cdad6ff2b19ca9a36fd9&#39;,<br>  transactionIndex: 116,<br>  blockHash: &#39;0xee0c3a305ed738ea0d7629af6d93e0fccd291fb80f1732f22c4dd329dbe07aec&#39;,<br>  logIndex: 142,<br>  removed: false,<br>  id: &#39;log_bf221914&#39;,<br>  returnValues: Result {<br>    &#39;0&#39;: &#39;0x0426266CF573388100183343b6e26b8bf5e4FDBb&#39;,<br>    &#39;1&#39;: &#39;0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82&#39;,<br>    &#39;2&#39;: &#39;0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56&#39;,<br>    &#39;3&#39;: &#39;0x0426266CF573388100183343b6e26b8bf5e4FDBb&#39;,<br>    &#39;4&#39;: &#39;420189781342653493372938&#39;,<br>    &#39;5&#39;: &#39;11524614549462974075302973&#39;,<br>    sender: &#39;0x0426266CF573388100183343b6e26b8bf5e4FDBb&#39;,<br>    srcToken: &#39;0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82&#39;,<br>    dstToken: &#39;0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56&#39;,<br>    dstReceiver: &#39;0x0426266CF573388100183343b6e26b8bf5e4FDBb&#39;,<br>    spentAmount: &#39;420189781342653493372938&#39;,<br>    returnAmount: &#39;11524614549462974075302973&#39;<br>  },<br>  event: &#39;Swapped&#39;,<br>  signature: &#39;0xd6d4f5681c246c9f42c203e287975af1601f8df8035a9251f79aab5c8f09e2f8&#39;,<br>  raw: {<br>    data: &#39;0x0000000000000000000000000426266cf573388100183343b6e26b8bf5e4fdbb0000000000000000000000000e09fabb73bd3ade0a17ecc321fd13a19e81ce82000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d560000000000000000000000000426266cf573388100183343b6e26b8bf5e4fdbb0000000000000000000000000000000000000000000058fa889fde44c0a9680a00000000000000000000000000000000000000000009886e9b48c7c6ff54f43d&#39;,<br>    topics: [<br>      &#39;0xd6d4f5681c246c9f42c203e287975af1601f8df8035a9251f79aab5c8f09e2f8&#39;<br>    ]<br>  }<br>}</pre><p>The details of the transaction can be read <a href="https://bscscan.com/tx/0xd58b583ccc04c2502828bd1d20a7d31f61806a839108cdad6ff2b19ca9a36fd9">here</a>. It’s about 420k $CAKE swapped to $11.5M $BUSD. It’s smaller swap than the transaction on Ethereum. So the biggest swap with Stablecoins since 1inch v3 officially started is <a href="https://etherscan.io/tx/0x6b1594e1a7aa3f2dfa3b00f8913745d961579d7e7e97950364cce11c02459d56">https://etherscan.io/tx/0x6b1594e1a7aa3f2dfa3b00f8913745d961579d7e7e97950364cce11c02459d56</a> (Tested on May 20, 2021)</p><h3>Conclusion</h3><p>The steps to achieve this data is quite complicated. Fortunately, the use-case like this will become much easier with the <a href="https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/events/topics/{topic}/">Covalent API</a>. It supports 1 million blocks per call. Note that it is still in beta, if you found any bug, you can report to them in their <a href="https://discord.gg/6nj9ncny">Discord</a> ,#feedback-and-support channel. So we can get even better API to use. Hope this article help you to understand about to read contract event in blockchain easier. Cheers.</p><p>Full code is hosted here: <a href="https://github.com/npty/data-dungeon">https://github.com/npty/data-dungeon</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3b3df7188a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/covalent-hq/finding-the-biggest-swap-of-1inch-v3-on-ethereum-and-binance-smart-chain-using-web3-js-d3b3df7188a6">Finding the biggest swap of 1inch v3 on Ethereum and Binance Smart Chain using Web3.js</a> was originally published in <a href="https://medium.com/covalent-hq">Covalent</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Tutorial] Query Swap Transactions บน EVM-compatible chain ด้วย Covalent API]]></title>
            <link>https://medium.com/covalent-hq/tutorial-query-swap-transactions-%E0%B8%9A%E0%B8%99-bsc-%E0%B9%81%E0%B8%A5%E0%B8%B0-eth-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-covalent-api-1159bca92858?source=rss-178763a9e484------2</link>
            <guid isPermaLink="false">https://medium.com/p/1159bca92858</guid>
            <category><![CDATA[covalent]]></category>
            <category><![CDATA[covalentalchemist]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[cryptothai]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[nptytn]]></dc:creator>
            <pubDate>Sun, 16 May 2021 10:15:04 GMT</pubDate>
            <atom:updated>2021-05-16T10:28:36.968Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับ Blockchain Developer ถ้าหากใครเคยใช้ Web3 จะพบว่าการดึงข้อมูลจาก Ethereum Blockchain เป็นเรื่องที่วุ่นวายพอสมควร ลองมาดูทีละ use-case กันครับ</p><h3><strong>การดึงข้อมูลที่เกี่ยวกับ Token</strong></h3><p>การใช้ Web3 จะไม่สามารถดึงข้อมูลที่ต้องการให้ครบถ้วนได้ภายใน Query เดียว</p><ul><li>ดึงราคาเหรียญจาก Exchange โดยผ่าน <strong>API Request</strong> (แต่ละ exchange ก็มีวิธีในการดึงต่างกันไป)</li><li>ดึงรูปเหรียญจาก <a href="https://github.com/trustwallet/tokens">Trustwallet Github</a> หรือจากแหล่งอื่นๆ โดยผ่าน <strong>API Request</strong></li><li>ดึง symbol, name และ decimals ของเหรียญจาก smart contract โดยผ่าน<strong> Web3</strong></li></ul><p>ในบทความนี้จะพูดถึงเรื่องการอ่าน Transaction history ย้อนหลังกัน เพราะงั้นเรามาดูกันว่าการอ่าน transactions ในแต่ละ wallet address ด้วย web3 ว่าทำอย่างไร (แบบคร่าวๆ)</p><h3>การดึงข้อมูล Transactions ของ Wallet Address</h3><ol><li>หา transaction ที่เป็นของ wallet address ที่ต้องการ</li><li>เก็บ transaction ไว้ใน array</li><li>วนจากข้อ 1 ใหม่โดยลด block number ไปเรื่อยๆ จนกว่า block นั้นจะมีอายุเกินกว่าที่เราต้องการ</li></ol><p>จะเห็นได้ว่าวิธีปรกติในการดึงข้อมูลของ use-cases ทั้งสองที่กล่าวมา นอกจากจะซับซ้อนแล้ว ยังทำให้ client ทำงานอย่างหนักในการดึงข้อมูลทั้งหมดออกมา</p><p><strong>Reference</strong>: <a href="https://web3js.readthedocs.io/en/v1.2.0/web3-eth.html#getblock">https://web3js.readthedocs.io/en/v1.2.0</a></p><p>สังเกตได้ว่าวิธีในการดึงข้อมูลของทั้งสอง use-cases ที่กล่าวมา นอกจากจะซับซ้อนแล้ว ยังทำให้ client ทำงานหนักอีกด้วย</p><h3>Introducing Covalent API</h3><p>ลองจินตนาการดูครับว่า การเขียนโค้ดจะง่ายขึ้นขนาดไหน ถ้ามี API ที่ทำแต่ละ use case ที่กล่าวมาได้ใน 1 <strong>API Request</strong></p><p>ดังนั้นในบทความนี้ มาลองสร้าง function ที่ดึง Transactions ที่มีการ Swap ทั้งหมดกันครับ โดยมี requirements ดังนี้:</p><ol><li>รองรับเชน <strong>Bsc, Eth, Polygon, Avalanche และ Fantom Opera </strong>ตามที่ <strong>Covalent API</strong> รองรับดังรูป</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*h5VQ0vQtHbE3o_h6oupPdQ.png" /><figcaption>Covalent API supported networks</figcaption></figure><p>2. รองรับ <strong>AMM </strong>ที่ <strong>fork</strong> <strong>Uniswap ทุกชนิด</strong></p><p>3. รับ arguments 2 ตัวคือ: <strong>chain id </strong>และ <strong>wallet address</strong></p><p>4. แสดงผลข้อมูลดังนี้</p><pre>Swapped 6544.308855 USDC -&gt; 312.6264229227168 RAD (tx_hash)</pre><p>ก่อนอื่น มาทำความรู้จักกับ API ที่เราต้องใช้ในบทความกันเลย</p><ol><li><strong>Get token balances for address</strong></li></ol><p>API นี้เราจะใช้สำหรับดึงข้อมูลว่า address และ chain ที่กำหนดถือ token อะไรไว้ใน wallet บ้าง เพื่อใช้สำหรับข้อมูลเหรียญ เช่น contract address, token symbol, token decimal เป็นต้น</p><p><strong>Endpoint</strong>: <a href="https://api.covalenthq.com/v1/%7Bchain_id%7D/address/%7Baddress%7D/balances_v2/">https://api.covalenthq.com/v1/{chain_id}/address/{address}/balances_v2/</a></p><p><strong>Docs: </strong><a href="https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/address/{address}/balances_v2/">https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/address/{address}/balances_v2/</a></p><p><strong>2. Get transactions</strong></p><p>API นี้เราจะใช้สำหรับดึง transactions ย้อนหลังสำหรับ address และ chain ที่กำหนด โดยสามารถระบุได้ว่าต้องการดึงกี่ transactions ย้อนหลัง ซึ่งในส่วนของ response ที่ return มา เราจะสามารถดึง event ที่เป็นการ swap มาได้ด้วย</p><p><strong>Endpoint:</strong> <a href="https://api.covalenthq.com/v1/">https://api.covalenthq.com/v1/</a>{chain_id}/address/{address}/transactions_v2/</p><p><strong>Docs:</strong> <a href="https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/address/{address}/transactions_v2/">https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/address/{address}/transactions_v2/</a></p><h3>เริ่มพัฒนา Application</h3><p>ในตัวอย่างนี้จะเลือกพัฒนาด้วย Node.js นะครับ เพราะน่าจะที่คุ้นเคยกันดีมากที่สุด <br>สำหรับการยิง Request ไปยัง Rest API จะเลือกใช้เป็น <a href="https://github.com/axios/axios">Axios</a> นะครับ</p><ol><li><strong>Cache ข้อมูลของ tokens ใน wallet address ที่กำหนดเอาไว้</strong></li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4637daeef5c1629ec1d824f4ad0132a9/href">https://medium.com/media/4637daeef5c1629ec1d824f4ad0132a9/href</a></iframe><p>ในขั้นตอนนี้จะยิง GET Request เพื่อดึงข้อมูลเหรียญใน wallet address และนำมา map กับ contract address ของ token นั้นๆ เก็บไว้ก่อน เพื่อนำมาเรียกใช้ทีหลังครับ</p><p>และกำหนด symbol ของ Native Token เอาไว้ตามแต่ละ chain</p><p>2. <strong>ดึงข้อมูล transactions ย้อนหลัง</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51dd242f515395073de868c531de1667/href">https://medium.com/media/51dd242f515395073de868c531de1667/href</a></iframe><p>ขั้นตอนนี้เป็นการยิง GET Request เพื่อดึงข้อมูล Transactions ย้อนหลัง โดย API จะ รองรับ Pagination ด้วย สามารถกำหนด parameters ต่างๆได้เช่น</p><ul><li>block-signed-at-asc (boolean): เรียงลำดับ transactions จากเก่าไปใหม่ หรือใหม่ไปเก่า โดย default แล้วจะถูก set เป็น false ผลที่ได้คือจะเรียงลำดับ transactions จากใหม่ไปเก่า ครับ</li><li>no-logs (boolean): ถ้า set เป็น true API จะไม่ return event logs ของ transaction มาด้วย ทำให้ query ได้ไวขึ้น</li><li>page-size (number): กำหนดว่าให้ return กี่ transactions ต่อ API call</li></ul><p>สำหรับ parameters อื่นๆ สามารถดูได้ <a href="https://www.covalenthq.com/docs/api/index.html#get-/v1/{chain_id}/address/{address}/transactions_v2/">ที่นี่</a></p><p>3. <strong>Filter transactions เฉพาะ swap event เท่านั้น</strong></p><p>สิ่งหนึ่งที่ต้องรู้ก่อนเกี่ยวกับ Transaction บน EVM คือแต่ละ Transaction ที่มีการส่ง Transaction ไปยัง Smart Contract ถ้ามีการ Emit Event เกิดขึ้น Event นั้นจะถูกบันทึกไว้ใน Transaction Log ด้วย</p><p>สำหรับ AMM อย่าง Uniswap หรือ PancakeSwap นั้น ทุกครั้งที่มีการส่ง Transaction เพื่อ Swap เหรียญ จะมี Event Swap เกิดขึ้นเสมอ ดังนั้นจึงต้องมีการแยกเอาเฉพาะ Transactions ที่มี Event Swap เกิดขึ้นเท่านั้น</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd758bbe95af19de59caab146d11bdab/href">https://medium.com/media/cd758bbe95af19de59caab146d11bdab/href</a></iframe><p>นอกเหนือจากนั้น จะสังเกตเห็นได้ว่าในบรรทัดที่ 13 มีการแยก Transactions ที่มี Event Mintออกไปด้วย สาเหตุเพราะว่าการ Add Liquidity ทำให้เกิด Event Swap เช่นเดียวกัน แต่สิ่งที่แตกต่างคือจะมี Event Mint เพิ่มขึ้นมาด้วย เพราะ Smart Contract มีการสร้าง LP token ส่งคืนมาให้เรานั่นเอง</p><p>ในส่วนสุดท้ายจะเป็นการเช็ค Event Transfer โดย parameters ของ Event Transfer จะรับทั้งหมด 3 params คือ from to และ amount ตามลำดับ ซึ่งจะแยกเช็คเป็น 2 กรณีคือ</p><ul><li><strong>Transaction value เป็นศูนย์<br></strong>หมายความว่าใน Transaction นี้ไม่มีการส่ง Native Token (เหรียญที่ใช้จ่าย gas) ไป Swapดังนั้นจะต้องมีการ Request ไปยัง ERC20 Contract เพื่อส่งเหรียญ ERC20 ไป Swapถ้าหา Event Transfer ที่มี address ที่กำหนดเป็นผู้ส่งไม่เจอ แสดงว่า transaction นี้ไม่ใช่การ Swap</li><li><strong>Transaction value ไม่ใช่ศูนย์<br></strong>หมายความว่า Transaction นี้ส่ง Native Token ไป Swap ดังนั้นจึงไม่มี Event Transfer เกิดขึ้นโดยที่มี address ที่กำหนดเป็นผู้ส่ง เพราะการส่ง Native Token ไม่จำเป็นต้องเรียกใช้ Smart Contract แต่จะต้องมี Event Transfer ของ ERC20 ที่ address ที่กำหนดเป็นผู้รับ ถ้าไม่มีแปลว่า Transaction นี้ไม่ใช่การ Swap</li></ul><p><strong>4. รวบรวมข้อมูลและแสดงผล Swap Transactions</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afa59f592553d718b5e03f3f49089220/href">https://medium.com/media/afa59f592553d718b5e03f3f49089220/href</a></iframe><p>ในขั้นตอนสุดท้าย logic ส่วนหลักๆจะอยู่ที่ function getTransferEventParams<br> ทำหน้าที่แยกประเภทของ Transaction ออกเป็น 3 กรณี ดังนี้:</p><ul><li>Swap ERC20เป็น ERC20</li><li>Swap ERC20 เป็น Native Token</li><li>Swap ETH เป็น ERC20</li></ul><p>จากนั้นดึงข้อมูลเหรียญที่ต้องใช้ออกมา ซึ่ง API Get Transactions นี้จะไม่มี details ของ token ที่ใช้ transfers ให้นอกจาก token contract address ทำให้ต้อง cache token details ในขั้นตอนแรกเอาไว้ก่อน แล้วจึงนำ token contract address มาดึงจาก cache ทีหลังครับ</p><p>สุดท้ายบรรทัด 82 — 98 คือการเก็บ string ข้อความ output ของ swapTransactions ทั้งหมดไว้ แล้ว log ออกมาทีละ transaction</p><h3>ผลลัพธ์</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3786699979ba705a723f74891dcf9e8/href">https://medium.com/media/f3786699979ba705a723f74891dcf9e8/href</a></iframe><p>ถ้าใครกำลังทำโปรเจ็คคริปโตเกี่ยวกับ Portfolio แนะนำให้ลองดู Covalent API เลยครับ ช่วยลดความยุ่งยากไปได้เยอะมากๆ เพราะในตอนนี้ API รองรับทั้งหมด 5 chains แล้ว และ API มีความหลากหลายมากๆ แนะนำให้ลองเล่นกันดูก่อนครับ</p><p>สำหรับใครที่อยากอ่านโค้ดแบบเต็มๆ สามารถดูได้ที่ <a href="https://github.com/npty/swap-transactions">https://github.com/npty/swap-transactions</a></p><p>หากมีจุดไหนบกพร่องหรือแก้ไขสามารถ comment มาได้เลย หรือถ้า code ผิดก็ contribute มาที่ repository ด้านบนได้เลยครับ 🙏🏻</p><h3>References</h3><ul><li><a href="https://www.covalenthq.com/docs/api">https://www.covalenthq.com/docs/api</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1159bca92858" width="1" height="1" alt=""><hr><p><a href="https://medium.com/covalent-hq/tutorial-query-swap-transactions-%E0%B8%9A%E0%B8%99-bsc-%E0%B9%81%E0%B8%A5%E0%B8%B0-eth-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-covalent-api-1159bca92858">[Tutorial] Query Swap Transactions บน EVM-compatible chain ด้วย Covalent API</a> was originally published in <a href="https://medium.com/covalent-hq">Covalent</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[นักสร้าง Dapp บน Moonbase Alpha Testnet สามารถใช้ Biconomy’s Plug-n-Play…]]></title>
            <link>https://nptytng.medium.com/%E0%B8%99%E0%B8%B1%E0%B8%81%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-dapp-%E0%B8%9A%E0%B8%99-moonbase-alpha-testnet-%E0%B8%AA%E0%B8%B2%E0%B8%A1%E0%B8%B2%E0%B8%A3%E0%B8%96%E0%B9%83%E0%B8%8A%E0%B9%89-biconomys-plug-n-play-7b33cc99a109?source=rss-178763a9e484------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b33cc99a109</guid>
            <dc:creator><![CDATA[nptytn]]></dc:creator>
            <pubDate>Thu, 08 Apr 2021 07:01:45 GMT</pubDate>
            <atom:updated>2021-04-08T07:08:49.407Z</atom:updated>
            <content:encoded><![CDATA[<h3>Biconomy เชื่อมต่อระบบกับ Moonbeam เพิ่มการพัฒนา DApp บนระบบนิเวศของ Polkadot</h3><p>แปลเอกสาร Original from <a href="https://moonbeam.network/announcements/moonbeam-biconomy-integration/">Biconomy Integrates with Moonbeam to Boost DApp Development in the Polkadot Ecosystem | Moonbeam Network | Apr, 2021</a></p><p>วันที่ 7 เมษายน <a href="https://moonbeam.network/">Moonbeam</a> แพลทฟอร์ม smart contract ที่สามารถใช้งานร่วมกันกับ Ethereum ผ่านเครือข่าย Polkadot ได้ประกาศเชื่อมต่อระบบกับ <a href="https://biconomy.io/">Biconomy</a> ที่เป็น Platform ในการส่งธุรกรรม (transaction) ข้ามหลายบล็อกเชนได้ ทำให้โปรเจ็ค Web3 ต่างๆสามารถทำงานได้ง่ายขึ้น การเชื่อมต่อระบบครั้งนี้เป็นเรื่องที่ดีมากสำหรับนักพัฒนา DApp (decentralized application) ที่กำลังพัฒนาบน Moonbeam ซึ่งจะช่วยให้สามารถใช้งาน API ของ Biconomy เพื่อทำให้ส่งธุรกรรมแบบไร้ค่าธรรมเนียม (Gasless transaction) ได้ ดังนั้นผู้ใช้งานของโปรเจ็ค DApp เหล่านี้ สามารถใช้งานได้โดยไม่จำเป็นต้องมีเหรียญที่ต้องใช้จ่ายค่าธรรมเนียมของ Moonbeam</p><p>API ที่มีประสิทธิภาพของ Biconomy ลดความซับซ้อนของ web3 application ลงด้วยการทำให้ส่งธุรกรรมแบบไร้ค่าธรรมเนียมได้ แปลว่าผู้ใช้งานสามารถสร้างธุรกรรมและใช้งาน DApp โดยไม่ต้องกังวลเกี่ยวกับค่าธรรมเนียม หรือสามารถจ่ายค่าธรรมเนียมโดยใช้เหรียญอื่นนอกจากเหรียญของ Moonbeam ได้ ฟีเจอร์เหล่านี้ทำให้ประสบการณ์ของผู้ใช้ดีขึ้นมาก มีความสำคัญอย่างยิ่งสำหรับผู้ใช้งานที่เพิ่งเริ่มต้นใช้งาน blockchain</p><p>Moonbeam ได้พิสูจน์ตัวเองในการเป็นศูนย์กลางที่น่าดึงดูดสำหรับนักพัฒนาที่ต้องการจะขยายโปรเจ็คเข้ามาใน Polkadot ซึ่ง Moonbeam มีการเชื่อมต่อระบบกับ<a href="https://moonbeam.network/community/projects/">โปรเจ็คอื่นๆมากมาย</a> และยังมี community ที่ใกล้ชิดกับนักพัฒนาอีกด้วย API ที่มีความเสถียรเป็นส่วนเสริมที่ยอดเยี่ยมสำหรับเครือข่ายเพราะมันช่วยแก้ปัญหาเรื่องการยอมรับของผู้ใช้งาน เพราะไม่ต้องสอนผู้ใช้งานเกี่ยวกับหลักการทำงานของค่าธรรมเนียมและเหรียญที่ใช้จ่ายค่าธรรมเนียม การเชื่อมต่อกันครั้งนี้จะทำให้นักพัฒนาขยายฐานผู้ใช้งานบน Moonbeam ได้อย่างรวดเร็ว</p><p>Nate Hamillton ผู้กำกับการพัฒนาธุรกิจของ Moonbeam กล่าวว่า “ทีม Moonbeam และ ทีม Biconomy มีเป้าหมายเดียวกันในการขยายฐานผู้ใช้งานของ DApp ให้มากขึ้น เป้าหมายของเราคือการพัฒนาประสบการณ์การใช้งานของผู้ใช้ เป็นความสัมพันธ์แบบอยู่ร่วมกันที่มีเอกลักษณ์ และ ทีม Biconomy มีวิธีการแก้ปัญหาที่เข้ากันได้อย่างลงตัวกับ แพลทฟอร์ม Moonbeam ที่มีความสามารถในการปรับขนาดและการปรับตัวเข้าหาแพลทฟอร์มอื่นๆ”</p><p>ทีม Biconomy เลือก Moonbeam เป็นจุดขยายการใช้งานเพราะฟีเจอร์ที่หาที่ไหนไม่ได้ และการเชื่อมต่อระบบกับนักพัฒนาที่หลากหลาย Moonbeam มีความเข้ากันได้กับ Ethereum ทั้ง EVM, Web3 RPC และบัญชีผู้ใช้ หมายความว่ามีความเปลี่ยนแปลงที่น้อยมากที่จำเป็นต่อการนำระบบของ Biconomy ที่มีอยู่แล้วบน Ethereum ไปเชื่อมต่อกับ Polkadon นอกเหนือจากนี้การใช้ Moonbeam ยังเปิดประตูให้ Biconomy เข้าถึงฐานนักพัฒนาและผู้ใช้งานที่เติบโตอย่างรวดเร็วบน Polkadot</p><p>Aniket Jindal, หัวหน้าฝ่ายปฏิบัติการณ์ และ ผู้ร่วมก่อตั้งของ Biconomy กล่าวว่า “เรามีความภูมิใจเป็นอย่างยิ่งที่ได้ทำงานร่วมกับทีมของ Moonbeam ในการแก้ไขปัญหาความติดขัดของนักพัฒนาที่เผชิญอยู่เกี่ยวกับค่าธรรมเนียมที่สูง การเชื่อมต่อระบบในครั้งนี้จะทำให้นักพัฒนา DApp มีเครื่องมือที่เหมาะสมในการมอบประสบการณ์ที่ดีที่สุดกับผู้ใช้ เราเชื่อว่า Moonbeam เป็นประตูที่ยอดเยี่ยมที่อนุญาตให้เราเข้าถึงนักพัฒนากลุ่มใหม่ๆในระบบนิเวศของ Polkadot”</p><p>เรียนรู้เกี่ยวกับวิธีเริ่มต้นใช้งาน Moonbeam และ API ของ Biconomy บน Moonbeam Testnet และ Moonbeam Alpha ในลิ้งค์ <a href="https://docs.moonbeam.network/networks/testnet/?utm_source=external&amp;utm_medium=website&amp;utm_campaign=announcement&amp;utm_content=airgap">เอกสารของโปรเจ็คอย่างเป็นทางการ</a> หรือเข้าร่วม <a href="https://discord.gg/9RYqehSWRv">Discord server</a> ของเรา</p><h3>เกี่ยวกับ Moonbeam Network</h3><p>Moonbeam เป็นแพลทฟอร์ม Smart Contract ที่เข้ากันได้กับ Ethereum บน Polkadot ที่ช่วยให้การพัฒนาแอพพลิเคชั่นที่มีความสามารถในการปรับตัวเข้า blockchain ต่างๆ เป็นเรื่องง่าย ความเข้ากันได้กับ Ethereum นั้นทำให้นักพัฒนาสามารถนำ smart contract และเว็บไซท์ที่มีอยู่แล้วไปใช้งานบน Moonbeam ได้โดยมีการเปลี่ยนแปลงที่น้อยที่สุด นอกจากนั้น Moonbeam ยังได้ประโยชน์จาก Parachain ของ Polkadot ที่ช่วยเสริมความปลอดภัยของทั้ง Relay chain และ chain อื่นๆ ที่เชื่อมต่อกับ Polkadot ปัจจุบัน Moonbean กำลังถูกพัฒนาโดย PureStake Moonbeam คาดหวังว่าจะเปิดตัว Mainnet ในช่วงกลางปี 2021 นี้ สามารถศึกษาเพิ่มเติมได้ที <a href="https://www.purestake.com/?utm_source=website&amp;utm_medium=news&amp;utm_campaign=announcement&amp;utm_content=subscan">https://www.purestake.com/</a>.</p><h3>เกี่ยวกับ Biconomy</h3><p><a href="https://biconomy.io/">Biconomy</a> เป็นบริษัทเทคโนโลยีที่สร้างโครงสร้างพื้นฐานของธุรกรรมแบบหลายเครือข่ายสำหรับยุคถัดไปของ web3 application ผ่านทาง API ที่ทรงพลังและใช้งานง่าย นักพัฒนาสามารถช่วยให้ผู้ใช้งานใช้งานได้โดยไม่ต้องกังวลถึงความซับซ้อนของ blockchain โดยการแก้ไขปัญหาที่ระดับธุรกรรมของคริปโต Biconomy กำลังอยู่ในภารกิจที่จะช่วยให้ประสบการณ์การใช้งาน Web3 application ง่ายขึ้น เพื่อนำไปสู่การเติบโตสู่ตลาดอย่างแพร่หลาย <a href="https://t.me/biconomy">Telegram</a> | <a href="https://medium.com/biconomy">Blog</a> | <a href="https://twitter.com/biconomy">Twitter</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b33cc99a109" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>