<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: tqmvt</title>
    <description>The latest articles on DEV Community by tqmvt (@tqmvt).</description>
    <link>https://dev.to/tqmvt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F936047%2F61be9b98-02ca-430e-9033-270df6514d2e.png</url>
      <title>DEV Community: tqmvt</title>
      <link>https://dev.to/tqmvt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tqmvt"/>
    <language>en</language>
    <item>
      <title>Get wallet address for multiple chains in cosmos app chains</title>
      <dc:creator>tqmvt</dc:creator>
      <pubDate>Sat, 08 Jun 2024 02:29:01 +0000</pubDate>
      <link>https://dev.to/tqmvt/get-wallet-address-for-multiple-chains-in-cosmos-app-chains-56pb</link>
      <guid>https://dev.to/tqmvt/get-wallet-address-for-multiple-chains-in-cosmos-app-chains-56pb</guid>
      <description>&lt;p&gt;In the Cosmos ecosystem, each chain has its own specific prefix for Bech32 addresses. When you connect your &lt;a href="https://www.keplr.app/" rel="noopener noreferrer"&gt;Keplr&lt;/a&gt; wallet to a Cosmos SDK-based chain, you receive a wallet address specific to that chain. However, the underlying public key remains the same across these chains, and you can derive the addresses for other chains by converting the address prefix.&lt;/p&gt;

&lt;p&gt;Here's how you can derive the address for multiple chains using JavaScript, assuming you have the wallet address for one chain:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Extract the Public Key: You need the public key associated with the address. This step typically involves interacting with the Keplr wallet to get the public key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Convert the Address Prefix: Use the &lt;a href="https://www.npmjs.com/package/@cosmjs/encoding" rel="noopener noreferrer"&gt;Bech32 encoding library&lt;/a&gt; to convert the address prefix to the desired chain's prefix.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Show me the code
&lt;/h2&gt;

&lt;p&gt;Below is an example using JavaScript and the bech32 library to convert an address from the Osmosis chain to the Stargaze chain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the necessary libraries:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @cosmjs/encoding @cosmjs/crypto
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;JavaScript code to convert the address prefix:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Bech32&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@cosmjs/encoding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Converts a Bech32 address to another Bech32 address with a different prefix.
 * @param {string} address - The original Bech32 address.
 * @param {string} newPrefix - The new prefix for the Bech32 address.
 * @returns {string} - The new Bech32 address with the specified prefix.
 */&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;convertAddressPrefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newPrefix&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Bech32&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Bech32&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newPrefix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Example usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;osmosisAddress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;osmo1n3v7hdf3lj6gr7hyluq7x4hj4snmajsze3fnlq&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stargazePrefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;stars&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stargazeAddress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;convertAddressPrefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;osmosisAddress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stargazePrefix&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Stargaze Address:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stargazeAddress&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will convert an Osmosis address to a Stargaze address by changing the Bech32 prefix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;By extracting the public key from Keplr and using a Bech32 conversion, you can derive addresses for multiple chains in the Cosmos ecosystem. This approach leverages the shared public key across these chains and the flexibility of Bech32 encoding.&lt;/p&gt;

&lt;p&gt;Thanks for your time. Happy coding!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>cosmoschain</category>
      <category>cosmjs</category>
      <category>betch32</category>
    </item>
    <item>
      <title>Delving into Blockchain (1)</title>
      <dc:creator>tqmvt</dc:creator>
      <pubDate>Thu, 23 May 2024 01:48:39 +0000</pubDate>
      <link>https://dev.to/tqmvt/delving-into-blockchain-1-1abf</link>
      <guid>https://dev.to/tqmvt/delving-into-blockchain-1-1abf</guid>
      <description>&lt;h2&gt;
  
  
  What is staking
&lt;/h2&gt;

&lt;p&gt;Staking cryptocurrencies is a process that involves buying and setting aside a certain amount of tokens to become an active validating node for the network. By simply holding these coins, the buyer becomes an important piece in the network’s security infrastructure and is compensated accordingly.&lt;/p&gt;

&lt;p&gt;Staking income is offered in the form of interest paid to the holder, while rates vary from one network to the other depending on several factors including supply and demand dynamics.&lt;/p&gt;

&lt;p&gt;As the number of PoS-based networks continues to grow, new alternatives to stake crypto have emerged including the launch of &lt;code&gt;group staking&lt;/code&gt;, also known as &lt;code&gt;staking pools&lt;/code&gt;, &lt;code&gt;staking providers&lt;/code&gt;, and &lt;code&gt;cold staking&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;These initiatives aim to democratize access to opportunities in the staking space to retail investors who hold a small number of tokens of a certain blockchain.&lt;/p&gt;

&lt;h2&gt;
  
  
  AMM
&lt;/h2&gt;

&lt;p&gt;Automated market makers (AMMs) are part of the decentralized finance (DeFi) ecosystem. They allow digital assets to be traded in a permissionless and automatic way by using liquidity pools rather than a traditional market of buyers and sellers. AMM users supply liquidity pools with crypto tokens, whose prices are determined by a constant mathematical formula. Liquidity pools can be optimized for different purposes, and are proving to be an important instrument in the DeFi ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Liquidity Pools and Liquidity Providers
&lt;/h2&gt;

&lt;p&gt;Liquidity refers to how easily one asset can be converted into another asset, often a fiat currency, without affecting its market price. Before AMMs came into play, liquidity was a challenge for decentralized exchanges (DEXs) on Ethereum. &lt;br&gt;
As a new technology with a complicated interface, the number of buyers and sellers was small, which meant it was difficult to find enough people willing to trade on a regular basis. AMMs fix this problem of limited liquidity by creating liquidity pools and offering liquidity providers the incentive to supply these pools with assets. The more assets in a pool and the more liquidity the pool has, the easier trading becomes on decentralized exchanges.&lt;/p&gt;

&lt;p&gt;On AMM platforms, instead of trading between buyers and sellers, users trade against a pool of tokens — a liquidity pool. At its core, a liquidity pool is a shared pot of tokens. Users supply liquidity pools with tokens and the price of the tokens in the pool is determined by a mathematical formula. By tweaking the formula, liquidity pools can be optimized for different purposes.&lt;/p&gt;

&lt;p&gt;Anyone with an internet connection and in possession of any type of ERC-20 tokens can become a liquidity provider by supplying tokens to an AMM’s liquidity pool. Liquidity providers normally earn a fee for providing tokens to the pool. This fee is paid by traders who interact with the liquidity pool. Recently, liquidity providers have also been able to earn yield in the form of project tokens through what is known as “yield farming.”&lt;/p&gt;

&lt;h2&gt;
  
  
  Vaults
&lt;/h2&gt;

&lt;p&gt;Sometimes your money belongs in different places. This is why we keep some cash on hand, in a checking account, and in a savings account. Similarly, users have the ability to organize funds into different wallets or store their crypto in a vault.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a vault?
&lt;/h3&gt;

&lt;p&gt;A vault can receive cryptocurrency like a normal wallet, but can also prevent stored crypto from being immediately withdrawn by adding optional security steps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Users can also choose to split ownership between multiple users and email accounts, requiring these users to approve of a transaction before it can be completed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Vaults also go through a secure approval withdrawal process after creation. Unapproved vault withdrawals will be canceled in 24 hours&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  DAO
&lt;/h2&gt;

&lt;p&gt;A decentralized autonomous organization (DAO) is an entity with no central leadership. Decisions get made from the bottom-up, governed by a community organized around a specific set of rules enforced on a blockchain.&lt;/p&gt;

&lt;p&gt;DAOs are internet-native organizations collectively owned and managed by their members. They have built-in treasuries that are only accessible with the approval of their members. Decisions are made via proposals the group votes on during a specified period.&lt;/p&gt;

&lt;p&gt;A DAO works without hierarchical management and can have a large number of purposes. Freelancer networks where contracts pool their funds to pay for software subscriptions, charitable organizations where members approve donations and venture capital firms owned by a group are all possible with these organizations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://capital.com/what-is-staking-in-crypto-a-closer-look-at-the-rise-of-pos" rel="noopener noreferrer"&gt;https://capital.com/what-is-staking-in-crypto-a-closer-look-at-the-rise-of-pos&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.gemini.com/cryptopedia/amm-what-are-automated-market-makers" rel="noopener noreferrer"&gt;https://www.gemini.com/cryptopedia/amm-what-are-automated-market-makers&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cointelegraph.com/ethereum-for-beginners/what-is-dao" rel="noopener noreferrer"&gt;https://cointelegraph.com/ethereum-for-beginners/what-is-dao&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>blockchain</category>
      <category>concept</category>
    </item>
    <item>
      <title>How to use Redis with Vercel Edge</title>
      <dc:creator>tqmvt</dc:creator>
      <pubDate>Sun, 23 Apr 2023 13:05:12 +0000</pubDate>
      <link>https://dev.to/tqmvt/how-to-use-redis-with-vercel-edge-363b</link>
      <guid>https://dev.to/tqmvt/how-to-use-redis-with-vercel-edge-363b</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vercel’s Edge Network provides developers with powerful compute capabilities with zero configuration and added latency.&lt;/p&gt;

&lt;p&gt;Edge Functions are JavaScript, TypeScript, or WebAssembly functions that are designed to be more efficient and faster than traditional Serverless compute and they are generally available since December 2022.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redis client for the Edge&lt;/strong&gt;&lt;br&gt;
Under the hood Vercel Edge uses Cloudflare Workers and the Workers cannot create TCP connections.&lt;/p&gt;

&lt;p&gt;Due to this runtime restrictions of Vercel Edge, custom clients are needed to use certain services like Redis.&lt;/p&gt;

&lt;p&gt;To overcome this issue we will need to use a Redis http client and a provider that support this funcionality.&lt;br&gt;
Luckily for us Upstash provides both things for us!&lt;/p&gt;

&lt;p&gt;If you haven’t already create your Next.js app with: “npx create-next-app@latest — typescript”&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @upstash/redis&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create Redis instance&lt;/strong&gt;&lt;br&gt;
Once installed, you can create a Redis instance with Upstash and obtain the connection URL. This connection URL can then be used in your Vercel Edge Functions to access the Redis instance.&lt;/p&gt;

&lt;p&gt;Remember to copy the secrets from Upstash dashboard:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPSTASH_REDIS_REST_URL
UPSTASH_REDIS_REST_TOKEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy these to your .env and upload them on Vercel as secrets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create the Edge Function&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://gist.github.com/gofixgo/67f17cbac15634ea44b950d8a73a820e" rel="noopener noreferrer"&gt;https://gist.github.com/gofixgo/67f17cbac15634ea44b950d8a73a820e&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NextRequest, NextResponse } from "next/server";
import { Redis } from "@upstash/redis";
export const config = {
  runtime: "edge",
};

if (
  !process.env.UPSTASH_REDIS_REST_URL ||
  !process.env.UPSTASH_REDIS_REST_TOKEN
) {
  throw new Error("Missing UPSTASH_REDIS_REST_URL or UPSTASH_REDIS_REST_TOKEN");
}

// Create a Redis client outside of the function
const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL,
  token: process.env.UPSTASH_REDIS_REST_TOKEN,
});

export async function middleware(req: NextRequest) {
  const country = req.geo?.country || "fallback";

  // Increment the country counter
  const sameCountryVisits = await redis.incr(country);
  // Increment the total counter
  const totalVisits = await redis.incr("total");


  return NextResponse.json({
    sameCountryVisits,
    totalVisits,
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Alternatives to Upstash for Edge Functions?&lt;/strong&gt;&lt;br&gt;
As we mentioned before Edge Functions runs on a runtime where common Redis clients won’t work due to V8 engine restrictions on TCP connections.&lt;/p&gt;

&lt;p&gt;This means that you can’t use self hosted Redis or Redislabs unless you use and implement a REST Proxy. Upstash Redis has this REST API built-in by default.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices for Using Redis with Vercel Edge:&lt;/strong&gt;&lt;br&gt;
To ensure that Redis performs optimally with Vercel Edge, it is important to follow some best practices.&lt;/p&gt;

&lt;p&gt;These include keeping Redis keys and values small to reduce memory usage, setting expiration times on cached data to prevent stale data, and monitoring Redis performance to ensure it can handle the workload.&lt;/p&gt;

&lt;p&gt;Additionally, Redis can be used in combination with Vercel Edge cache using: &lt;a href="https://github.com/vercel/examples/tree/main/edge-api-routes/cache-control" rel="noopener noreferrer"&gt;https://github.com/vercel/examples/tree/main/edge-api-routes/cache-control&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Using Upstash Redis with Vercel Edge can provide a significant performance boost for your applications. So why not give Redis a try with Vercel Edge and see how it can benefit your application?&lt;/p&gt;

&lt;p&gt;Upstash Rest API docs: &lt;a href="https://docs.upstash.com/redis/features/restapi" rel="noopener noreferrer"&gt;https://docs.upstash.com/redis/features/restapi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>react</category>
      <category>redis</category>
      <category>nextjs</category>
      <category>vercel</category>
    </item>
  </channel>
</rss>
