<?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 Manaan Ansari on Medium]]></title>
        <description><![CDATA[Stories by Manaan Ansari on Medium]]></description>
        <link>https://medium.com/@manaanansari?source=rss-c5a7e9d457f3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2t7lhepHZXI9O3lgsVZ4qQ.jpeg</url>
            <title>Stories by Manaan Ansari on Medium</title>
            <link>https://medium.com/@manaanansari?source=rss-c5a7e9d457f3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 00:55:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manaanansari/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[AI Today — Chinese AI Just Broke the Price of Intelligence]]></title>
            <link>https://manaanansari.medium.com/ai-today-chinese-ai-just-broke-the-price-of-intelligence-e94f6e4413ff?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e94f6e4413ff</guid>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 02:10:06 GMT</pubDate>
            <atom:updated>2026-06-03T02:10:06.710Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SpUE-eeeH_VIDqBhAcNnGg.png" /></figure><h3>🔥 The Big Story</h3><p><strong>Step 3.7 Flash is completely free inside Hermes Agent. Unlimited. No API key needed.</strong></p><p>This is the kind of crossover episode you dream about. Stepfun just dropped their new 196B parameter MoE model (11B active, 256K context) under Apache 2.0 — and it’s already available through Hermes Agent’s Portal with zero limits. 🤯</p><p>The benchmarks are legit for a flash-class model: SweBench Pro 56.3 (beats Deepseek V4 Flash at 55.6 and Gemini 3.5 Flash at 55.1), TerminalBench 59.3, and Claude Eval 1.1 at 67.1 where Stepfun claims #1. Inside Hermes Agent specifically, it hits <strong>67.5%</strong> — up from 60% for Step 3.5 Flash. That’s the metric that actually matters: real agent performance across different harnesses, not cherry-picked leaderboard runs.</p><p>The architecture is smart. <strong>196B total but only 11B active</strong> — so you get strong agentic behavior (coding, vision, web search, tool use) without paying full freight every time. Fully open weight under Apache 2.0, runs locally on high-memory Macs (128GB+). But the real story: open terminal, run hermes model, select Hermes Portal, authenticate — and it&#39;s there. Free. No visible rate limit. Right now, anyway.</p><p>For anyone building on Hermes — this lands differently. Your platform is the free on-ramp to the most interesting flash-class model for agentic coding since Deepseek V4. And on Stepfun’s own sweep benchmark across multiple harnesses — Hermes, OpenClaw, Claude Code, OpenCode — Hermes came out ahead. The inference routing matters. The tool schemas matter. And Hermes is winning that compatibility game. 🔥</p><h3>🧠 The Pattern: The Chinese Pricing Avalanche</h3><p>Step 3.7 Flash being free isn’t an isolated event. Look at what’s happening in parallel:</p><p><strong>Xiaomi Mimo V2.5 Pro</strong> just permanently slashed API pricing by up to 99%. You can now get a <strong>1-trillion-parameter model for $6/month</strong> (4 billion credits on the Light plan). MIT-licensed open weights, 1M token context window, enterprise-grade agent performance at “lunch money” pricing. The Pro plan at $50/month gives you 38 billion credits. 🤑</p><p><strong>Alibaba Qwen 3.7 Max</strong> priced itself at roughly <strong>6x cheaper than Claude Opus</strong> for comparable benchmarks. Here’s the wild part: Alibaba gave this model an unfamiliar AI chip it had never seen, left it alone for 35 hours, and it made over 1,000 tool calls, built a custom computing kernel from scratch, and outperformed the manufacturer’s official version by 10x. That’s not a benchmark — that’s a flex. 💀</p><p><strong>Step 3.7 Flash</strong> — free in Hermes Agent, Apache 2.0 open weights, agentic coding focus.</p><p>The pattern is unmistakable. Chinese AI labs are playing a different game. They’re flooding the market with models that are 80–90% of frontier capability at 10–20% of the cost. And since they own the full stack (Alibaba on cloud, Xiaomi on hardware, Stepfun on model architecture), they can sustain this indefinitely.</p><p>For anyone building agent infrastructure — routing layers, connectors, multi-agent orchestration — this pricing collapse is the most important architectural variable right now. When the marginal cost of agent reasoning approaches zero, the constraints on your system shift. The question stops being “how to minimize API calls” and becomes “how to maximize value from unlimited cheap intelligence.” Your routing layer just got way more interesting. ⚡</p><h3>📡 Worth Your Radar</h3><p><strong>Andrej Karpathy joins Anthropic’s pre-training team.</strong> The guy who co-founded OpenAI’s applied research, led Tesla’s AI vision, and spent a year doing independent AI education just signed up for Claude’s next-gen pre-training. His mandate: use Claude to accelerate building the next Claude. AI training AI — not as a demo, as the production workflow for frontier model development. This is Anthropic’s bet that the scaling playbook is no longer “buy more GPUs” but “make your own AI improve your AI.” 🤖</p><p><strong>Apple registered gen.ai.apple.com</strong> two weeks before WWDC 2026. iOS 27’s rebuilt Siri runs on a custom model based on Gemini, with on-screen awareness and personal context. After a year of radio silence on generative AI, this is the signal that WWDC is going to be Apple’s biggest AI coming-out party yet. 🍎</p><p><strong>Perplexity open-sourced Bumblebee</strong> — their internal security tool that detects software supply chain attacks on developer machines. It’s read-only (scans metadata without executing packages), free, and on GitHub. If you’re running multi-agent pipelines that dynamically install packages, this is worth a look. 🐝</p><p><strong>Google Pomelli</strong> launched as a free all-in-one brand marketing suite. Drop in a URL, it builds your business DNA (colors, fonts, tone), then generates campaign posters, product photo shoots with hyperrealistic models, brand books, and full websites — then pushes everything into Google Ads. Entire creative teams’ worth of output from one link.</p><h3>🐘 The Elephant</h3><p>Everyone’s been asking when open models would “catch up to frontier.” Wrong question.</p><p><strong>The real moment is when models get so cheap that intelligence stops being a constraint on system design.</strong></p><p>Step 3.7 Flash is free in Hermes Agent. Mimo V2.5 Pro is $6/month. Qwen 3.7 Max is 6x cheaper than Claude. These aren’t toys — they’re legitimately good at agentic coding, tool use, and multimodal reasoning. Not frontier-best at everything, but good enough that the cost calculus collapses.</p><p>For agent infrastructure builders, this changes everything. When you can spin up unlimited parallel sub-agents at near-zero cost, the architecture shifts from “keep context small, minimize calls” to “maximize exploration and verification.” Run 10 agents in parallel, compare approaches, cross-validate results. That’s what Claude Code’s dynamic workflows do on the high end — but now you can approximate that at a fraction of the cost with open models and your own orchestration layer.</p><p>The next six months are going to be wild. The open model ecosystem is accelerating faster than most people realize, and the pricing curve is going exponential in the wrong direction for the incumbents. 🎯</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e94f6e4413ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Today — The Week Anthropic Broke the Scale]]></title>
            <link>https://manaanansari.medium.com/ai-today-the-week-anthropic-broke-the-scale-87fc1c9fbe66?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/87fc1c9fbe66</guid>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Sat, 30 May 2026 13:11:48 GMT</pubDate>
            <atom:updated>2026-05-30T13:11:48.429Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Do3JYrRhVBXyUPBXTHnRQ.png" /></figure><h3>The Week Anthropic Broke the Scale</h3><p>A $65B raise, a trillion-dollar valuation, and a Pope walk into a bar. Here’s what happened in AI this week.</p><h3>The Big Story</h3><p><strong>Anthropic had the week that most startups dream about in their wildest Pitch Deck PowerPoints.</strong></p><p>They closed a <strong>$65B Series H</strong> at a <strong>$900B+ valuation</strong> — making them the most valuable private company in history. Not “AI startup.” Not “tech startup.” Any startup. OpenAI is now playing catch-up in the valuation race, a sentence nobody saw coming two years ago.</p><p>Alongside the funding fireworks, they shipped <strong>Claude Opus 4.8</strong>. It’s a modest upgrade — slightly better at coding, reasoning, and computer use. The genuinely interesting improvement is honesty: the model now flags its own uncertainties instead of confidently bullshitting you. Pricing unchanged.</p><p>But the product that actually matters is what they’re doing with <strong>Claude Code</strong>. Dynamic workflows where subagents plan, fork into parallel workstreams, cross-check each other’s results, and converge on answers. This is Anthropic putting multi-agent orchestration into a shipping product — not a demo, not a research paper. Production.</p><p>Meanwhile, Sam Altman quietly started walking back the “AI destroys all jobs” narrative. Funny how the tune changes when the company across the street just raised $65B.</p><h3>The Pattern That Actually Matters</h3><p><strong>Multi-agent orchestration is having its moment.</strong> And it’s not just Anthropic.</p><p><strong>Claude Code’s dynamic workflows</strong> spin off subagents that work independently, then cross-validate each other before folding results back in. Agents attack problems from different angles; other agents try to refute what they found. The system iterates until answers converge.</p><p><strong>Verdant</strong> (an agentic coding workspace) gives each agent its own isolated Git worktree — backend, frontend, tests, and review all run in their own sandbox so nobody steps on anyone’s code. Plan-first workflow: the agent discusses the approach, gets your approval, then writes code.</p><p><strong>Higgsfield MCP</strong> turns AI agents from planning tools into production pipelines. Paste a product brief, Claude plans the creative, Higgsfield generates the video ad inside the same chat, a virality predictor scores engagement, and you iterate without ever leaving the conversation.</p><p>Three different products. Same pattern: plan → fork → execute in parallel → verify → converge.</p><p>If you’re building anything in the agent orchestration space, this is the direction. The MCP connector pattern that Higgsfield is using? That’s the same infrastructure layer that makes tools like InstaMCP possible.</p><h3>Worth Your Radar</h3><p><strong>Microsoft MAI Image 2.5</strong> jumped to #3 on the image generation leaderboard behind GPT Image 2 and Gemini 3.1 Flash (aka Nano Banana). Strong text rendering and branding concepts.</p><p><strong>ElevenLabs Music V2</strong> arrived trained entirely on licensed data. Also launched Dubbing V2 that preserves voice, emotion, and facial expressions across languages.</p><p><strong>Perplexity Computer</strong> is now baked into Microsoft 365 (Word, Excel, PowerPoint, Outlook). Tells you exactly how much Microsoft trusts their own Copilot.</p><p><strong>Gemini Omni</strong> had its moment: upload a Google Maps screenshot, draw a route, get a first-person driving video along that exact path. Drone POV from a sketch.</p><p><strong>The Batch</strong> covered the resurgence of Forward Deployed Engineers — a role Palantir pioneered 20 years ago. Andrew Ng’s take: AI Engineer roles will dwarf FDEs.</p><h3>The Elephant</h3><p><strong>The Pope gave a presentation on AI.</strong> Accompanied by an Anthropic co-founder. His line: “AI needs to be disarmed.” He compared it to nuclear weapons.</p><p>The co-founder admitted publicly that every AI lab faces commercial pressure that conflicts with doing the right thing. His proposed solution: “We desperately need outside critics with no skin in the game.”</p><p><strong>Stratechery’s Ben Thompson</strong> looked at the Ferrari Luce EV backlash (Jony Ive-designed, universally hated) and drew a line to why people feel alienated by modern technology. Ferrari’s whole identity is performance and craft. The Luce is optimized for efficiency. His thesis: when tech prioritizes efficiency over everything else, it leaves people cold — and AI might bring craft back.</p><p>Also worth noting: Thompson interviewed Eric Seufert about monetizing AI answers through ads. His controversial take: believing in ads makes you more optimistic about AI’s future — if answers can be monetized, the incentive alignment works out.</p><h3>Sources</h3><ul><li><a href="https://www.youtube.com/watch?v=7TG78vIYI-Q">Claude Opus 4.8 Launch + Dynamic Workflows</a></li><li><a href="https://www.youtube.com/watch?v=QcDtTU0y02g">Opus 4.8 Free Trials via Verdant and Kiro</a></li><li><a href="https://www.youtube.com/watch?v=-hzFOgepd6c">Higgsfield MCP — Agentic Media Generation</a></li><li><a href="https://www.deeplearning.ai/the-batch/issue-355/">The Batch Issue 355</a></li><li><a href="https://stratechery.com/2026/luceing-their-mind/">Stratechery — Luceing Their Mind</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87fc1c9fbe66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Invariant Testing Explained: Stateless and Stateful Fuzzing in Foundry]]></title>
            <link>https://awstip.com/invariant-testing-explained-stateless-and-stateful-fuzzing-in-foundry-529292b7e112?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/529292b7e112</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[foundry]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Sat, 25 May 2024 00:47:08 GMT</pubDate>
            <atom:updated>2024-05-25T17:47:04.202Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be4vHyiXFl7HBVSnM17QTg.png" /></figure><p>Hey! In this blog, we will explore fuzz testing in Foundry. I assume you are already familiar with Solidity. You can find the code for this tutorial in <a href="https://github.com/ManaanAnsari/solidity-invariant-tests">this repository</a><br>We’ll be using the WETH contract as our example.</p><h3>Fuzzing</h3><p>Fuzzing is a method of testing that uses random input parameters. This can help identify edge cases and unexpected behaviors in your smart contract.</p><h4>Stateless Fuzzing</h4><p>Stateless fuzzing can be better explained using an example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*ugkoeJMdyLXjY4mnp9Z93A.png" /><figcaption>WETH deposit function</figcaption></figure><p>The <strong><em>deposit</em></strong> function in WETH should work for all amounts greater than 0. Here is how we write a fuzz test:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*yZ2TlP7da14NW_zixzTZkw.png" /><figcaption>Fuzz Test</figcaption></figure><p>In this test, the <strong><em>amount</em></strong> parameter will be provided by Foundry (randomly). The <strong><em>assume</em></strong> statement will skip the iteration if <strong><em>amount</em></strong> is 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*zZOUf1GeP5Lj47JjpNP0XQ.png" /><figcaption>Output</figcaption></figure><p>μ: Mean gas<br>~: Median gas<br>You can change the number of runs and find more info <a href="https://book.getfoundry.sh/forge/fuzz-testing">here</a></p><p><strong>Advantages:<br></strong>- Detects edge cases by using a wide range of inputs.<br>- Uncovers potential vulnerabilities or bugs that could be missed with manual testing.</p><h4>Stateful Fuzzing</h4><p>Stateful fuzzing, also known as invariant testing, extends the idea of stateless fuzzing by maintaining the state between test runs.</p><p>In the previous mechanism, every time the test was run with a random amount, the state was not saved. Let’s take an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*2I8WodO8mj3j8Z2e99vxBA.png" /></figure><p>Here, if we perform stateless fuzz testing, it will never revert because every test creates a new instance. However, in invariant testing, the previous state is saved (depending on the depth settings), hence the name stateful fuzzing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*qHitMVSxhncClzjgXM2GqQ.png" /><figcaption>Open Invariant</figcaption></figure><p>The test should start with the <strong><em>invariant</em></strong> keyword.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WbAx5c7fcZWdp-0g02wk4A.png" /><figcaption>Output</figcaption></figure><p>This method is called open invariant testing. All the functions of all the contracts are called randomly in a random order hence, the test failed.</p><h4>What is an Invariant?</h4><p>An invariant is a property that should hold true under any circumstances. For example, in WETH, the total supply of WETH and its ETH balance should always be equal.<br>Let’s run the open invariant test on WETH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*E5rSf4Zl42Knv9vN1WSPLA.png" /><figcaption>WETH Open Invariant</figcaption></figure><p>We can use the <strong><em>targetContract</em></strong> method to target a specific contract, and Foundry will call all the functions randomly in that contract to check if the invariants hold true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*AXq-yr8u4juP_GiyCtCXNw.png" /><figcaption>Output</figcaption></figure><p>As you can see, there are a lot of reverts, which was expected.</p><h4>Fine-Tuning Invariant Testing</h4><p>The next method is <strong>handler-based testing</strong>. You can think of a handler as a scenario. You code a handler contract that interacts with your main contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RK1KfVquOZW9Qm7Ntr0jNw.png" /></figure><p>Handler contract</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*rnH1PiRSrmiU2l1yZlgooA.png" /><figcaption>Handler Contract</figcaption></figure><p><strong><em>bound</em></strong> function will make sure amount is always in that specific range</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*j0XSOL8R2PibpSSkGbD8xg.png" /><figcaption>Test Contract</figcaption></figure><p>Our invariant test contract uses the handler as a target and calls its functions randomly. We can fine-tune further by choosing which functions to target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*uKD46dbTYOt-_4HIg4e2XA.png" /><figcaption>output</figcaption></figure><p>As you can see, we have 0 reverts now.</p><h4>Actor Manager Method</h4><p>The next method of invariant testing is called “actor manager.” Let’s assume there are multiple scenarios you would like to test, i.e., multiple handler contracts. For this, you can create an actor manager contract that interacts with the multiple handlers, and your main invariant test contract interacts with the manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xxhdc7V_D4inBGZPIp11Ug.png" /><figcaption>Actor Manager</figcaption></figure><h4>Conclusion</h4><p>In this blog, we’ve covered invariant testing in Foundry, focusing on both stateless and stateful fuzzing techniques. Stateless fuzzing uses random inputs to find potential issues, while stateful fuzzing checks that certain conditions (invariants) always hold true by keeping the contract’s state between tests. Methods like open invariant testing, handler-based testing, and the actor manager method help ensure your smart contracts work correctly. Using these techniques together improves the security and reliability of your contracts. For more information and code examples, visit <a href="https://github.com/ManaanAnsari/solidity-invariant-tests">GitHub repository</a>. Happy testing!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJtzBi67hgLI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJtzBi67hgLI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJtzBi67hgLI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b44ca1868a8743602eaeefd4c14e07d7/href">https://medium.com/media/b44ca1868a8743602eaeefd4c14e07d7/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjuyY-CTolac%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjuyY-CTolac&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjuyY-CTolac%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/84240f431118f97cef303383af60a369/href">https://medium.com/media/84240f431118f97cef303383af60a369/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=529292b7e112" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/invariant-testing-explained-stateless-and-stateful-fuzzing-in-foundry-529292b7e112">Invariant Testing Explained: Stateless and Stateful Fuzzing in Foundry</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Solidity’s create & create2 with Tornado Cash $1M Hack]]></title>
            <link>https://coinsbench.com/understanding-soliditys-create-create2-with-tornado-cash-1m-hack-01f8c147e5c7?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/01f8c147e5c7</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Thu, 02 May 2024 21:13:01 GMT</pubDate>
            <atom:updated>2024-05-06T14:55:13.509Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FmMfE4ySlRONNYleK5G%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExM3l5OHc2cHN3bzUxMzNudnRpcWVqZnZieXJ4eDc5NGE5ZjI3dm45diZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FmMfE4ySlRONNYleK5G%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExM2FyaGp6ZW5sbzdxZTJoNmd3YjQ2dnZ5YW5zc3Q5cTMzOGdxZ3pjMyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FmMfE4ySlRONNYleK5G%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="246" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa6c5ec9097bd9f6896c1b52fb19bf20/href">https://medium.com/media/fa6c5ec9097bd9f6896c1b52fb19bf20/href</a></iframe><p>Can we compute a smart contract address before deployment? <br>Go ahead, take a guess.<br>If you said yes, give yourself a pat on the back — because you’re right!</p><p>I used to believe smart contract addresses were generated randomly. Silly me!<br>In reality, <strong>smart contract addresses are deterministic</strong>. This means that given the deployer’s address and nonce, we can determine what the contract address will be.</p><p>In this Blog, I’ll explain this concept without diving too deeply into assembly language. <br>However, if you’re interested in delving deeper, I’ll share relevant resources for further exploration.</p><h3>Create</h3><p>The ‘<strong>create</strong>’ opcode is the most commonly used contract creation opcode. When contracts are deployed from scripts or other development environments, the create opcode is the low-level instruction executed by the EVM to deploy and generate a contract address</p><pre>contract deployer {<br> function deploy() public {<br>  address deployed_contract_address = address(new A());<br>  // some logic ...<br> }<br>}</pre><p>The contract address is computed by the EVM using the following logic:</p><pre>contract_address = keccak256(deployer_address, nonce); // with RLP encoding of [sender, nonce]</pre><p>We can replicate the same logic in Solidity using the following function:</p><pre>function computeAddress(address _origin, uint _nonce) public pure returns (address) {<br><br>   bytes memory data;<br>   <br>   if (_nonce == 0x00) data = abi.encodePacked(bytes1(0xd6), bytes1(0x94), _origin, bytes1(0x80));<br>   <br>   else if (_nonce &lt;= 0x7f) data = abi.encodePacked(bytes1(0xd6), bytes1(0x94), _origin, uint8(_nonce));<br>   <br>   else if (_nonce &lt;= 0xff) data = abi.encodePacked(bytes1(0xd7), bytes1(0x94), _origin, bytes1(0x81), uint8(_nonce));<br>   <br>   else if (_nonce &lt;= 0xffff) data = abi.encodePacked(bytes1(0xd8), bytes1(0x94), _origin, bytes1(0x82), uint16(_nonce));<br>   <br>   else if (_nonce &lt;= 0xffffff) data = abi.encodePacked(bytes1(0xd9), bytes1(0x94), _origin, bytes1(0x83), uint24(_nonce));<br>   <br>   else data = abi.encodePacked(bytes1(0xda), bytes1(0x94), _origin, bytes1(0x84), uint32(_nonce));<br>   <br>   return address(uint160(uint256(keccak256(data))));<br>  <br>}</pre><h3>Create 2</h3><p>1. A fixed prefix, which is always ‘0xFF’.<br>2. The sender’s address ensures the contract is tied to a specific creator.<br>3. A chosen salt value adds uniqueness to the contract address.<br>4. The bytecode contains the code of the new contract to be deployed.</p><p>By combining these parameters, <strong>CREATE2</strong> computes a deterministic address for the new contract, which remains the same even as the blockchain evolves</p><pre>contract deployer {<br>   function deploy(uint256 salt) public {<br>    address deployed_contract_address = address(new A{salt: bytes32(salt)}());<br>    // some logic ...<br>   }<br>}</pre><p>The contract address is computed by the EVM using the following logic:</p><pre>deployed_contract_address = keccak256(0xFF, deployer_address, salt, contract_bytecode); </pre><p>We can replicate the same logic in Solidity using the following function:</p><pre>function predictAddress(uint salt) public view returns( address){<br><br>   return address(uint160(uint(keccak256(abi.encodePacked(<br>   <br>    bytes1(0xff),<br>    <br>    address(this),<br>    <br>    bytes32(salt),<br>    <br>    keccak256(abi.encodePacked(<br>    <br>    type(SimpleContract).creationCode,<br>    <br>    abi.encode()<br>    <br>    ))<br>    <br>   )))));<br><br>}</pre><blockquote>Note: You will find all the code in this <a href="https://github.com/ManaanAnsari/solidity-metamorphic-contracts-example">repository</a></blockquote><blockquote>Deterministic smart contracts can be both a blessing and a curse.</blockquote><h3>Metamorphic Smart Contracts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*6RSFu_oDIXtY_tMevHJIHQ.png" /></figure><p>with the same bytecode and salt, result in the same address in each iteration.</p><h4>Tornado Cash Hack</h4><p>The Tornado Cash hack exploited the use of metamorphic smart contracts. Here’s how the attack unfolded:</p><p><strong>Step 1<br></strong>1. Create a deployer contract.<br>2. Use `CREATE2` to deploy a buffer contract.<br>3. The buffer contract then deploys a proposal contract using `CREATE` (nonce=1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nz2Ch2UpIil41mqJ_PDebg.png" /><figcaption>Step 1</figcaption></figure><p><strong>Step 2<br></strong>1. Once the proposal gets approved by the governance.<br>2. Self-destruct both the buffer and proposal contracts to reset the nonce.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0xBcsoJbWtPlcr6opgxSRQ.png" /><figcaption>Step 2</figcaption></figure><p><strong>Step 3 <br></strong>1. Deploy the buffer contract again using `CREATE2` (same as step 1).<br>2. The buffer contract now deploys malicious code (as the nonce is 1). The malicious code is deployed on the same address as the proposal contract, which was approved by the DAO governance contract.<br>3. the governance contract executes the logic in the malicious contract</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zQrPWgjnmO9viuGDskqeQ.png" /><figcaption>Step3</figcaption></figure><p>The code for this attack can be found in my <a href="https://github.com/ManaanAnsari/solidity-metamorphic-contracts-example">GitHub repository</a> if you would like to replicate it.<br>Using the same steps above, the hacker managed to withdraw <strong>100,000 TORN tokens worth nearly $1M</strong>.</p><p>There have been numerous hacks using `<strong>CREATE2</strong>`. Relevant information is attached below if you are interested.</p><h3>Sources</h3><ul><li><a href="https://www.coindesk.com/business/2023/11/13/ethereum-wallet-drainer-steals-60m-in-six-months/">Ethereum Wallet Drainer Steals $60M in Six Months</a></li><li><a href="https://medium.com/coinmonks/tornado-cash-governance-hack-ec77ebb3aa68">Tornado Cash governance hack</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FwhjRc4H-rAc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DwhjRc4H-rAc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FwhjRc4H-rAc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5027c576a58d8d88f489471389a3a66b/href">https://medium.com/media/5027c576a58d8d88f489471389a3a66b/href</a></iframe><p><a href="https://mixbytes.io/blog/metamorphic-smart-contracts-is-evm-code-truly-immutable">Metamorphic Smart Contracts: Is EVM Code Truly Immutable?</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01f8c147e5c7" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/understanding-soliditys-create-create2-with-tornado-cash-1m-hack-01f8c147e5c7">Understanding Solidity’s create &amp; create2 with Tornado Cash $1M Hack</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CCXT Python: Exploring Cryptocurrency Trading on Binance, Kucoin, and Bitmex]]></title>
            <link>https://awstip.com/ccxt-python-exploring-cryptocurrency-trading-on-binance-kucoin-and-bitmex-b2bae06ce79c?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2bae06ce79c</guid>
            <category><![CDATA[crypto-trading]]></category>
            <category><![CDATA[kucoin]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[binance]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Sat, 27 May 2023 09:30:27 GMT</pubDate>
            <atom:updated>2023-05-30T19:01:59.684Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PYPJb74t2G5024DP.jpg" /></figure><p>CCXT is a popular open-source Python library that provides a unified API to interact with numerous cryptocurrency exchanges. It simplifies the process of accessing market data, executing trades, and managing accounts across multiple exchanges, making it easier for developers to build cryptocurrency trading applications.</p><p>CCXT supports a wide range of exchanges, including major platforms like Binance, Kucoin, and Bitmex. In this article, we will focus on these three exchanges, providing coding examples to replicate major functionalities needed by a trading bot.</p><h3>Article Highlights:</h3><ol><li>Setting Margin and Leverage</li><li>Handling Quantity Precision</li><li>Taking Long and Short Trades</li><li>Setting Take Profit and Stop Loss Orders</li><li>Closing Positions and Open Orders</li><li>Conclusion</li></ol><h3>Setting Margin and Leverage</h3><p>Setting margin and leverage differs across exchanges. For Binance and Bitmex, you can use the following code:</p><pre>exchange.set_margin_mode(symbol=symbol, marginMode=&quot;isolated&quot;, params={&quot;type&quot;: &quot;future&quot;})<br>exchange.set_leverage(symbol=symbol, leverage=3, params={&quot;type&quot;: &quot;future&quot;})</pre><p>For Kucoin, margin and leverage are specified directly while creating the order.</p><h3>Handling Quantity Precision</h3><p>Quantity precision varies among exchanges, so it’s essential to manage it accordingly. Here’s an example:</p><pre>balance = exchange.fetch_balance({&quot;type&quot;: &quot;future&quot;, &quot;marginType&quot;: &quot;isolated&quot;})<br>to_risk_balance = round(balance * 0.1, 2)  # Risking 10% of your balance<br>quantity = (to_risk_balance * leverage) / close<br>market = exchange.market(symbol)<br>quantity = int(quantity * float(market[&quot;info&quot;].get(&quot;underlyingToPositionMultiplier&quot;, 1)))<br>quantity = exchange.amount_to_precision(symbol, quantity)</pre><h3>Taking Long and Short Trades</h3><p>To take long or short trades, it’s recommended to use the create_order function with the appropriate arguments. Here are the examples:</p><p>Binance:</p><pre>long = exchange.create_order(symbol, &#39;market&#39;, &#39;buy&#39;, quantity, None)</pre><p>Kucoin:</p><pre>long = exchange.create_order(symbol, &#39;market&#39;, &#39;buy&#39;, quantity, None, {&quot;marginMode&quot;: &quot;isolated&quot;, &quot;leverage&quot;: leverage})</pre><p>Bitmex:</p><pre>long = exchange.create_order(symbol, &#39;market&#39;, &#39;buy&#39;, quantity, None, {&quot;leverage&quot;: leverage})</pre><p>Note: For short positions, replace &#39;buy&#39; with &#39;sell&#39;, and adjust the quantity and prices accordingly.</p><h3>Setting Take Profit and Stop Loss Orders</h3><p>Setting take profit (TP) and stop loss (SL) orders also varies across exchanges. Here are the examples:</p><p>Binance (TP):</p><pre>tp = exchange.create_order(symbol, &#39;TAKE_PROFIT_MARKET&#39;, &#39;sell&#39;, quantity, None, {&quot;stopPrice&quot;: tp_price, &quot;reduceOnly&quot;: True})</pre><p>Kucoin (TP):</p><pre>tp = exchange.create_order(symbol, &#39;market&#39;, &#39;sell&#39;, quantity, None, {&quot;stopPrice&quot;: tp_price, &quot;stop&quot;: &quot;up&quot;, &quot;reduceOnly&quot;: True})</pre><p>Bitmex (TP):</p><pre>tp = exchange.create_order(symbol, &#39;MarketIfTouched&#39;, &#39;sell&#39;, quantity, tp_price, {&quot;stopPx&quot;: tp_price, &quot;execInst&quot;: &quot;ReduceOnly&quot;})</pre><p>Similar examples can be used for setting stop loss (SL) orders.</p><h3>Closing Positions and Open Orders</h3><p>Closing open orders is straightforward. Fetch open orders and cancel the desired order:</p><pre>open_orders =exchange.fetch_open_orders(symbol)<br>for open_order in open_orders:<br>    # Condition to check which order to cancel<br>    exchange.cancel_order(open_order[&quot;id&quot;], open_order[&quot;symbol&quot;])</pre><h3>Conclusion</h3><p>CCXT Python is a powerful library that simplifies cryptocurrency trading by providing a unified API for multiple exchanges. By leveraging its features and the coding examples provided, you can develop your own cryptocurrency trading strategies across different platforms.</p><p>Explore the possibilities of CCXT Python, delve into the exciting world of cryptocurrency trading, and unlock endless opportunities for building advanced trading applications.</p><p>Check out the CCXT Base Wrapper, a CCXT wrapper specifically designed for Binance, Kucoin, and Bitmex exchanges, on GitHub: <a href="https://github.com/ManaanAnsari/ccxt-base-wrapper">CCXT Base Wrapper</a>.</p><p>Happy trading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2bae06ce79c" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/ccxt-python-exploring-cryptocurrency-trading-on-binance-kucoin-and-bitmex-b2bae06ce79c">CCXT Python: Exploring Cryptocurrency Trading on Binance, Kucoin, and Bitmex</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Algorand as a Solidity Developer]]></title>
            <link>https://manaanansari.medium.com/understanding-algorand-after-working-on-solidity-evm-49a16f872433?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/49a16f872433</guid>
            <category><![CDATA[algorand]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[algorand-blockchain]]></category>
            <category><![CDATA[ethereum-blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Sun, 02 Oct 2022 18:32:02 GMT</pubDate>
            <atom:updated>2022-10-03T17:47:59.284Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZiMwHMzrTpqlcX77g6DjWQ.jpeg" /></figure><p>I have been working on EVM chains for about two years and I recently started exploring Algorand. in this article, we will deep dive into the accounts architecture of the Algorand blockchain.</p><p>In Ethereum, we have a public-private key combination as an account <br>but in Algorand, accounts are different (they store data in themselves).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*nlsWLHdthOzVJtcGy35YaA.png" /></figure><p>at the high level except for the address, the account contains 2 main parts <strong>Assets</strong> and <strong>Apps.</strong></p><h4>Let&#39;s first learn about assets</h4><p>The Algorand protocol supports the creation of on-chain assets that benefit from the same security, compatibility, speed, and ease of use as the Algo. creating an asset and deploying a smart contract are two different things in Algorand <a href="https://developer.algorand.org/docs/get-details/asa/?from_query=assets#assets-overview"><em>more info</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNwVRN91CsfFk7-u3Ez4cQ.png" /></figure><p>assets can be further divided into 2 types <strong>Created and Held.</strong></p><p><strong>Created</strong>: creating an asset is pretty simple you just set a few parameters and make an asset-create transaction.<br>once the transaction is successful you will get the asset id.<br>an asset id is just a unique number and it is needed to interact with the created asset.</p><p><strong>held: </strong>the assets that you hold are stored in key-value pairs with asset id as key and asset balance as value.</p><p><strong>opting into an asset <br></strong>before receiving any asset you need to first opt in to that asset.<br>it is just a fancy way of saying you need to add an asset id(key) with balance 0 (value) into your account.<br>this means nobody can send you an asset that you are not opted into.</p><h4>Apps</h4><p>in Algorand smart contracts are called apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xJuVY_EJsQg0R0iNabBpdw.png" /></figure><p>Algorand uses <strong>teal</strong> as its smart contract language. writing a smart contract in teal is a bit complex that’s why we use a python wrapper called <strong>Pyteal</strong> to make our job easy. <strong>Pyteal code is compiled and converted to teal</strong> and then deployed on the Algorand blockchain. once the app deployment is successful <strong>app id</strong> and <strong>app address</strong> is returned. this app id can be used to interact with the created app and the app address is used to receive algo/assets <a href="https://developer.algorand.org/docs/get-details/dapps/pyteal/?from_query=pyteal#create-publication-overlay"><em>more info</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-hSABen93lwlEblM0mTowA.png" /></figure><p><strong>basic info about the smart contract</strong></p><ul><li>the teal smart contract contains an <strong>approval</strong> program and a <strong>clear</strong> program.</li><li>there are only two data types supported by teal <strong>int</strong> and <strong>bytes.</strong></li><li>there are two types of storage available for the app<br> <strong>local state</strong>: data stored inside the specific user’s account <br> <strong>global states</strong>: data stored inside the app</li></ul><p>while deploying you need to specify the state schema (the number of variables your app is using at each state).</p><p><strong>Interacting with the App</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3EjDobc2mPVAvCPj1JtQJQ.png" /></figure><p>same as assets you first need to make an <strong>opt-in</strong> transaction before interacting with the app.</p><p>all the local data is stored in the <strong>key-value</strong> format.<br>you can <strong>opt-out</strong> by sending close out transaction on that app and all the local data of that app will be <strong>deleted.</strong></p><p><strong>development tools</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*N0g-tgyFi2w6bxgv9Q_Omw.png" /></figure><h4>Closing thoughts</h4><p>now you can go through the <a href="https://developer.algorand.org/docs/">Algorand docs</a> and hopefully, you will understand concepts a lot better.<br>there are a lot of things I didn’t cover and are worth taking a look</p><ul><li><a href="https://developer.algorand.org/docs/get-details/transactions/signatures/?from_query=multisig#multisignatures">Multisig wallet</a>: without a smart contract</li><li><a href="https://developer.algorand.org/docs/get-details/atomic_transfers/">atomic transfer</a>: you can build an entire dex using this</li><li><a href="https://developer.algorand.org/docs/get-details/dapps/smart-contracts/smartsigs/">smart signature</a>: you can set up a subscription</li><li><a href="https://developer.algorand.org/docs/get-details/dapps/smart-contracts/apps/">updating App</a>: upgradable smart contracts without proxies</li><li>and <a href="https://developer.algorand.org/docs/">much more</a>...</li></ul><p>Thank you for reading I hope this helped</p><p>feel free to drop questions/suggestions will be happy to help :)</p><p><strong>helpful links</strong></p><p><a href="https://drive.google.com/file/d/1WKV4TyMrkdJPzxFN7FC3KvFuy4C3Hz95/view?usp=sharing">download the account architecture image</a></p><p><a href="https://kctheservant.medium.com/first-attempt-on-algorand-bf56104c4b91">https://kctheservant.medium.com/first-attempt-on-algorand-bf56104c4b91</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFXXeYU1-sCQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFXXeYU1-sCQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFXXeYU1-sCQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f68a6455ec2238b678073c5f17df954/href">https://medium.com/media/7f68a6455ec2238b678073c5f17df954/href</a></iframe><p><a href="https://developer.algorand.org/solutions/whats-the-best-way-to-learn-about-algorand/">https://developer.algorand.org/solutions/whats-the-best-way-to-learn-about-algorand/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49a16f872433" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Login with MetaMask using Python (Django)]]></title>
            <link>https://awstip.com/login-with-metamask-using-python-django-340110ae2020?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/340110ae2020</guid>
            <category><![CDATA[metamask]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[blockchain-technology]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Mon, 11 Jul 2022 14:59:20 GMT</pubDate>
            <atom:updated>2022-07-18T09:22:01.089Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QEnl_efbZwdd1oT3zJMDeg.png" /><figcaption>MetaMask</figcaption></figure><p>This article will provide a basic understanding of how the web3 login works <br>we will use python (Django) and React</p><p>if you want to follow along please clone this <a href="https://github.com/ManaanAnsari/MetaMask-Login-Python">GitHub repo</a></p><p><strong><em>Web2 System</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZ4MAO_sPg7r8U7eml10Ow.png" /><figcaption>web2 login system</figcaption></figure><p>in a basic web2 system we send a username and password to the backend API if the credentials are valid API returns the access token. this token is then used to interact with the other protected API endpoints</p><p><strong>What is MetaMask?</strong></p><p>MetaMask is a hot wallet it stores your private key and public key</p><blockquote><em>note: </em>the <strong>private key</strong> is like your password so don&#39;t share it with anyone (kinda like an ATM pin)<em><br></em>the <strong>public key</strong> is your account address and you can share this (kinda like a bank account number)</blockquote><p><strong>How does it work?</strong></p><p>if I give you a secret message <br>and you sign it with your private key and pass me the signature</p><p>using your signature and the secret message, I can derive the public key <br>if the derived public key matches with your public key I can log you in. I will not go into much detail about the cryptography part u can read more about it <a href="https://www.toptal.com/ethereum/one-click-login-flows-a-metamask-tutorial">here</a></p><p><strong>Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EeT2LmQ26Q7T1MPFYWoZbA.png" /><figcaption>MetaMask Login Architecture</figcaption></figure><p><strong>Backend</strong></p><p>run the following commands inside the <a href="https://github.com/ManaanAnsari/MetaMask-Login-Python">cloned repo</a></p><pre>cd backend/</pre><pre>pip install -r requirements.txt</pre><pre>python manage.py runserver</pre><p>this will start the Django server on <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a> you will see there are 3 API endpoints created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BeUh4SJzDsdoif82P1bdYA.png" /></figure><p><strong>get_captcha: </strong>it accepts a public key and returns a random string (captcha)</p><p><strong>web3_login: </strong>it accepts a public key and signature and returns an access token if authentication is successful</p><p><strong>me</strong>: it returns the logged-in user object</p><p><strong>backend/user_management/views.py: </strong>all the API logic is written here</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a11cfc73f39b4c32422a24535410afd5/href">https://medium.com/media/a11cfc73f39b4c32422a24535410afd5/href</a></iframe><blockquote>to know more about serializers/validators please read <a href="https://www.django-rest-framework.org/">Django rest framework docs</a></blockquote><p><strong>Frontend</strong></p><p>I have also packed in a basic UI to interact with the backend APIs and Metamask</p><p>open a new terminal</p><pre>cd frontend/</pre><pre>yarn install</pre><pre>yarn start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N-7KjHncy5qyaXRE9tBjaA.png" /><figcaption>Login</figcaption></figure><blockquote>note: if you are geting CORS origin error please use this <a href="https://chrome.google.com/webstore/detail/moesif-origin-cors-change/digfbfaphojjndkpccljibejjbppifbc">extension</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1W5ca8d5Jp-LrO9up6GgJg.png" /><figcaption>After Login</figcaption></figure><p>Thank you for reading I hope this helped</p><p>fell free to drop questions/suggestions will be happy to help :)</p><p><strong>helpful links</strong></p><ul><li><a href="https://www.toptal.com/ethereum/one-click-login-flows-a-metamask-tutorial">One-click Login with Blockchain: A MetaMask Tutorial</a></li><li><a href="https://www.preveil.com/blog/public-and-private-key/">Public and private encryption keys | PreVeil</a></li><li><a href="https://moralis.io/blog/">Blog Archives &quot; Moralis &quot; The Ultimate Web3 Development Platform</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=340110ae2020" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/login-with-metamask-using-python-django-340110ae2020">Login with MetaMask using Python (Django)</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Email Open Rate Using Python and Django]]></title>
            <link>https://manaanansari.medium.com/email-open-rate-using-python-and-django-39995cec1d3?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/39995cec1d3</guid>
            <category><![CDATA[email-marketing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Fri, 15 Jan 2021 13:14:48 GMT</pubDate>
            <atom:updated>2021-01-16T06:45:18.577Z</atom:updated>
            <content:encoded><![CDATA[<p>Most of the marketing tools now a day allows you to monitor your email open rate kinda like<strong> WhatsApp’s blue tick</strong> in this article we will learn how to do the same using python</p><p><strong>Prerequisites</strong></p><p><a href="https://docs.djangoproject.com/en/3.1/"><strong>Django</strong></a> — it&#39;s a web development framework we will be using for our API</p><p><strong>Core Logic in layman’s terms</strong></p><p>As we already know we can add images to our emails these images can be added using local files or a URL. If we add an image using a URL when the email is opened by the email client (Gmail, etc.…) it makes a GET request to the image URL</p><p>We can capture this using our code and using a unique URL for every email sent we can see which mail was opened</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*dG2dr-kPwmOD4dXeRxztkg.png" /></figure><h3><strong>Let’s start coding</strong></h3><p>you can clone the <a href="https://github.com/ManaanAnsari/email-openrate-python"><em>repo</em></a> from my <a href="https://github.com/ManaanAnsari/email-openrate-python"><em>GitHub</em></a> to follow along</p><p>install all the dependencies ( I recommend doing this in a virtual environment )</p><pre>pip install -r requirements.txt</pre><p><strong>Code-Explanation (</strong><a href="https://www.djangoproject.com/"><strong>Django</strong></a><strong>)</strong></p><blockquote><a href="https://github.com/ManaanAnsari/email-openrate-python/blob/master/api/app/models.py">api/app/models.py</a></blockquote><p>it contains our database schema. you can learn more about models <a href="https://docs.djangoproject.com/en/3.1/topics/db/models/">here</a></p><p>our Django app contains a table named ImageHash with i_hash, status as columns</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bacdeca93a7a0fd40e9a73cfa3532c1a/href">https://medium.com/media/bacdeca93a7a0fd40e9a73cfa3532c1a/href</a></iframe><blockquote><a href="https://github.com/ManaanAnsari/email-openrate-python/blob/master/api/app/views.py">api/app/views.py</a></blockquote><p>views contain the main logic of loading the image and updating the status</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/295e4081d9006372ab31291762c6e2b2/href">https://medium.com/media/295e4081d9006372ab31291762c6e2b2/href</a></iframe><blockquote><a href="https://github.com/ManaanAnsari/email-openrate-python/blob/master/api/app/urls.py">api/app/urls.py</a></blockquote><p>here each URL is mapped to its specific view</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0c09ac96908e16c0d8caf00fe80295a/href">https://medium.com/media/b0c09ac96908e16c0d8caf00fe80295a/href</a></iframe><p>run the Django server</p><pre>cd api/<br>python manage.py runserver</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*K7fPpdiTN09_2B3kKjLAWg.png" /></figure><p>as we are running this on a local machine the generated URL will contain localhost which won&#39;t be accessible by Gmail or any other email client</p><p>so to get the public URL we can either host the API or (for testing purpose) we can just tunnel our local port</p><p>we will use <a href="https://ngrok.com/"><strong>Ngrok</strong></a> to tunnel our port 8000</p><pre>./ngrok http 8000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*wCbU23eFUgWqlK-cIjbGpQ.png" /></figure><p><a href="https://94be8bde6237.ngrok.io/">https://94be8bde6237.ngrok.io</a> is the public URL for local port 8000</p><blockquote><a href="https://github.com/ManaanAnsari/email-openrate-python/blob/master/api_wrapper.py">api_wrapper</a>.py</blockquote><p>we have an API wrapper as well to make our API interaction much easier</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f0a840f31d026ec118a5eb7b15c4d27/href">https://medium.com/media/3f0a840f31d026ec118a5eb7b15c4d27/href</a></iframe><blockquote><a href="https://github.com/ManaanAnsari/email-openrate-python/blob/master/script.py">script.py</a></blockquote><p>let&#39;s use our API.</p><p>create a <strong>MailStatus</strong> object with our <strong>Ngrok URL</strong></p><pre>from api_wrapper import MailStatus <br># create email status object<br>ms = MailStatus(url=&quot;https://94be8bde6237.ngrok.io&quot;)</pre><p>get the unique hash and make a URL this URL can be sent over email in an image tag</p><pre># get unique hash <br>i_hash = ms.getHash()<br># combine that hash and make a url <br>img = ms.getImgURL(i_hash=i_hash)<br><br># this &#39;ll print false if hash is not used<br>print(&quot;status:&quot;,ms.hashStatus(i_hash))</pre><p>send an email with this image tag</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb91bea675c3585b87f35e59afea2fb8/href">https://medium.com/media/bb91bea675c3585b87f35e59afea2fb8/href</a></iframe><p>check your inbox and open the email</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WzX-OvRt9FJvZ8hZ0VkhRQ.png" /></figure><p>check the email status in your script and it should print True</p><pre>print(&quot;status:&quot;,ms.hashStatus(i_hash))</pre><h3>Conclusion</h3><p>congrats we have successfully tested our open rate logic using Django and python</p><blockquote>If you have any query feel free to comment or <a href="https://www.linkedin.com/in/manaanansari/">connect</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39995cec1d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started With RASA-ChatBot And Telegram (Part 1)]]></title>
            <link>https://manaanansari.medium.com/getting-started-with-rasa-chatbot-and-telegram-part-1-d289977e24ac?source=rss-c5a7e9d457f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d289977e24ac</guid>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[rasa-nlu]]></category>
            <category><![CDATA[rasa-core]]></category>
            <category><![CDATA[rasa]]></category>
            <dc:creator><![CDATA[Manaan Ansari]]></dc:creator>
            <pubDate>Sat, 06 Apr 2019 13:15:30 GMT</pubDate>
            <atom:updated>2019-04-07T10:00:45.136Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Started With RASA-ChatBot And Telegram</h3><p>This article gives a basic introduction to RASA &amp; shows how all the pieces of the puzzle fit together from training to testing to using it on 3rd party channels (In this case Telegram ). If you are new to RASA I highly recommend checking out their <a href="https://rasa.com/docs/get_started_step1/">docs</a> first it’s quite easy to follow.</p><h3>Why RASA?</h3><p>I chose RASA as it is open source and I can install it in my own local machine or cloud server. The main advantage of RASA over similar offerings like <a href="https://dialogflow.com/">google dialogflow</a>, <a href="https://docs.aws.amazon.com/lex/index.html">amazon lex</a>, etc.. is that your data remains private to you.</p><h3>Why Telegram?</h3><p>Because of its simple setup. you can use any other channel you like the process of integration remains the same.</p><p><strong><em>let’s dive into RASA</em></strong>, RASA stack contains<em> </em><a href="https://rasa.com/docs/nlu/"><em>rasa_nlu</em></a> (To understand message intent) <a href="https://rasa.com/docs/core/"><em>rasa_core</em></a><em> </em>(To take action based on intent) both the libraries are independent. you can find detailed docs <a href="https://rasa.com/docs/get_started_step1/">here</a>.</p><h3>Steps</h3><ol><li>Clone the Repo from my <a href="https://github.com/ManaanAnsari/rasa_telegram">Github</a> the code is similar to that of RASA <a href="https://rasa.com/docs/get_started_step2/">docs</a>. If you are familiar with entity extraction you can use the <a href="https://github.com/RasaHQ/starter-pack-rasa-stack">rasa starter pack</a>.</li><li>Unzip and install the packages listed in requirements and also install spaCy English language model using following commands</li></ol><pre>pip install -r requirements.txt</pre><pre>python -m spacy download en</pre><h3>Explanation of files</h3><p>I assume you have downloaded code from my <a href="https://github.com/ManaanAnsari/rasa_telegram">GitHub</a> and installed all the dependencies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*xo5jT4BjpoBqweBVHMPv6Q.png" /><figcaption><strong>File Structure</strong></figcaption></figure><p>In rasa_telegram/nlu you will see two files that are used to train rasa_nlu</p><p><a href="https://github.com/ManaanAnsari/rasa_telegram/blob/master/nlu/nlu_config.yml"><em>nlu_config.yml</em></a><em> </em>— It basically defines how the model will be trained and how features will be extracted. We will use the predefined spacy_sklearn pipeline since we have very few training examples. <a href="https://rasa.com/docs/nlu/choosing_pipeline/">more info here</a></p><p><a href="https://github.com/ManaanAnsari/rasa_telegram/blob/master/nlu/nlu_data.md"><em>nlu_data.md</em> </a>— It contains nlu training data you can feed data using .md or .json format we will be using .md for simplicity.</p><p>In rasa_telegram/core you will see two files that are used to train rasa_core</p><p><a href="https://github.com/ManaanAnsari/rasa_telegram/blob/master/core/domain.yml"><em>domain.yml </em></a>— The domain defines the universe your bot lives in — what user inputs it should expect to get, what actions it should be able to predict, how to respond and what information to store. (<a href="https://rasa.com/docs/get_started_step2/">source</a>)</p><p><a href="https://github.com/ManaanAnsari/rasa_telegram/blob/master/core/stories.md"><em>stories.md </em></a>— Rasa Core models learn from real conversational data in the form of training “stories”. A story is a real conversation between a user and a bot where user inputs are expressed as intents and the responses of the bot are expressed as action names. (<a href="https://rasa.com/docs/get_started_step2/">source</a>)</p><p>rest of the files will be explained as we move on</p><h3>Training And Testing rasa_nlu</h3><pre>python -m rasa_nlu.train -c nlu/nlu_config.yml --data nlu/nlu_data.md -o models --fixed_model_name nlu --project current --verbose</pre><p>this command trains the rasa_nlu using a config file specified by “-c” and data specified by “-data” and stores the model at the directory specified by “-o”</p><p>to test model you can run python3 test_nlu_model.py</p><h3>Actions</h3><p>If you see the domain.yml file you will find various actions that can be performed by the bot. the actions starting withutter_ just sends a message to the user. however, you can write custom actions that run any arbitrary code. we have specified a custom action named action_callapi the code that your custom action executes need to be hosted on the server and the endpoints have to be provided using endpoints.yml. You can create an action server in node.js, Java, or any other language and define your actions there. if you choose python rasa does provide <a href="https://rasa.com/docs/core/customactions/">rasa_core_sdk</a> to simplify your work. we will use the same. make sure to install it using “<em>pip install rasa_core_sdk</em>”(<a href="https://rasa.com/docs/core/customactions/">more info</a>)</p><p>Our custom actions are written in actions.py and endpoints have been specified in endpoints.yml</p><h3>Training And Testing rasa_core</h3><pre>python -m rasa_core.train -d core/domain.yml -s core/stories.md -o models/current/dialogue</pre><p>this command trains the rasa_core using a domain file specified by “-d” and stories by “-s” and stores the model at the directory specified by “-o”</p><p>to test model start the action server</p><pre>python -m rasa_core_sdk.endpoint --actions actions</pre><p>then run the following command to start chat with the bot using terminal</p><pre>python3 -m rasa_core.run -d models/current/dialogue -u models/current/nlu --endpoints endpoints.yml</pre><p>congrats you have successfully built a chatbot using RASA Stack now let&#39;s deploy it on the telegram.</p><h3>Setting Up Telegram</h3><p><strong><em>step 1.</em></strong> create a bot using botfather and get the access token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*g5MMIFiWkRU360T_IUH_PA.png" /></figure><p><strong><em>step 2.</em></strong> setup a webhook using this URL</p><pre><a href="https://api.telegram.org/bot%7Btoken%7D/setWebhook?url=https://eb3aa0c2.ngrok.io">https://api.telegram.org/bot{token}/setWebhook?url={w</a>ebhook url}</pre><p>webhook URL needs to be https if you are following along on local machine you can use <a href="https://ngrok.com/">ngrok</a> or any other similar service to create a tunnel. we will be using <a href="http://flask.pocoo.org/docs/1.0/">flask</a> and <a href="https://ngrok.com/">ngrok</a> (since it&#39;s easy to get started)</p><pre>pip3 install flask</pre><p>by default, flask runs on port 5000</p><pre>ngrok http 5000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*Fp20APP3q8BVCgSN2d2j8w.png" /><figcaption>ngrok running</figcaption></figure><p>you can test everything out by running the <a href="https://github.com/ManaanAnsari/rasa_telegram/blob/master/main.py">main.py</a>. don&#39;t forget to paste your bot token and make sure your <strong><em>action server</em></strong> is also running.</p><h3>main.py</h3><p>import all the dependencies</p><pre>import requests <br>import json<br>from flask import Flask <br>from flask import request<br>from flask import Response<br>from rasa_core.agent import Agent<br>from rasa_core.interpreter import RasaNLUInterpreter<br>from rasa_core.utils import EndpointConfig</pre><pre>token = &#39;yourbottoken&#39;<br>app = Flask(__name__)</pre><p>load trained <strong>nlu</strong> model</p><pre>interpreter = RasaNLUInterpreter(‘./models/current/nlu’)</pre><p>while loading the agent don&#39;t forget to pass the action_endpoint</p><pre>agent = Agent.load(‘./models/current/dialogue’, interpreter=interpreter,<br>action_endpoint=EndpointConfig(url=”<a href="http://localhost:5055/webhook">http://localhost:5055/webhook</a>&quot;))</pre><p>the function to interact with our model</p><pre>def applyAi(message):<br>    responses = agent.handle_message(message)<br>    text = []<br>    if responses:<br>        for response in responses:<br>            text.append(response[&quot;text&quot;])<br>    return text</pre><p>few helper functions</p><pre>def parse_msg(message):<br>    chat_id = message[&#39;message&#39;][&#39;chat&#39;][&#39;id&#39;]<br>    txt = message[&#39;message&#39;][&#39;text&#39;]<br>    return chat_id,txt</pre><pre>def send_message(chat_id,messages=[]):<br>    url = &#39;<a href="https://api.telegram.org/bot&#39;+token+&#39;/sendMessage&#39;">https://api.telegram.org/bot&#39;+token+&#39;/sendMessage&#39;</a> <br>    if messages:<br>        for message in messages:<br>            payload = {&#39;chat_id&#39; : chat_id,&#39;text&#39; : message}<br>            requests.post(url,json=payload)<br>    return True</pre><p>function to handle post request from the telegram</p><pre><a href="http://twitter.com/app">@app</a>.route(&#39;/&#39;,methods=[&#39;POST&#39;,&#39;GET&#39;])<br>def index():<br>    if(request.method == &#39;POST&#39;):<br>        msg = request.get_json()<br>        chat_id , message = parse_msg(msg)<br>        response_messages = applyAi(message)<br>        send_message(chat_id,response_messages)<br>        return Response(&#39;ok&#39;,status=200)<br>    else:<br>        return &#39;&lt;h1&gt;HELLO&lt;/h1&gt;&#39;</pre><p>let&#39;s run the code and check</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*_aj-yDDA059OWRJO53I7pQ.jpeg" /></figure><h3>Conclusion</h3><p>congrats we have successfully created and deployed our bot. In this article, we learned what is RASA, how to set it up, the difference between rasa_nlu and rasa_core, how to set up custom actions, how to train and test rasa_nlu and rasa_core models. and finally how to use it via 3rd party channels like Telegram.</p><blockquote>If you face any issue or have any query ping me on telegram “@ManaanAnsari”.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d289977e24ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>