<?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: Volnov Peter</title>
    <description>The latest articles on DEV Community by Volnov Peter (@pvolnov).</description>
    <link>https://dev.to/pvolnov</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%2F1085381%2Ff6ff6e9d-141a-4326-b601-93a5cd6631da.png</url>
      <title>DEV Community: Volnov Peter</title>
      <link>https://dev.to/pvolnov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pvolnov"/>
    <language>en</language>
    <item>
      <title>Tutorial: pay for users' gas on NEAR Protocol</title>
      <dc:creator>Volnov Peter</dc:creator>
      <pubDate>Tue, 04 Jul 2023 02:38:59 +0000</pubDate>
      <link>https://dev.to/pvolnov/tutorial-pay-for-users-gas-on-near-protocol-19pn</link>
      <guid>https://dev.to/pvolnov/tutorial-pay-for-users-gas-on-near-protocol-19pn</guid>
      <description>&lt;p&gt;NEAR Protocol has introduced an exceptional feature since its version 0.17.0: Delegate Transactions. With this feature, you can create and sign a transaction from one account and send it on behalf of another account. Essentially, you pay for the gas for a third-party account.&lt;/p&gt;

&lt;p&gt;This tutorial will guide you through creating and executing Delegate Transactions on NEAR Protocol using Python.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Familiarity with Python&lt;/li&gt;
&lt;li&gt;A NEAR Protocol account&lt;/li&gt;
&lt;li&gt;Python NEAR library (&lt;code&gt;py_near&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step-by-Step Guide
&lt;/h3&gt;

&lt;p&gt;Delegate Transactions are performed in three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Alice creates a &lt;code&gt;delegate_action&lt;/code&gt; specifying all the actions, public key, and recipient.&lt;/li&gt;
&lt;li&gt;Alice signs &lt;code&gt;delegate_action&lt;/code&gt; with her private key and passes it to Bob.&lt;/li&gt;
&lt;li&gt;Bob forms a normal transaction from one action - &lt;code&gt;delegate_action&lt;/code&gt;, signs it, and sends it to the blockchain. Essentially, Alice's transaction is executed, but Bob pays for the gas.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Creating and Signing a Delegate Transaction
&lt;/h3&gt;

&lt;p&gt;The following Python function creates and signs a delegate transaction. Follow the steps below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the &lt;code&gt;py_near&lt;/code&gt; Python library. You can install it via pip:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;py_near
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Run the following Python code:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;py_near.account&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;py_near_primitives&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;TransferAction&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;ed25519&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_and_sign_delegate&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"alice.near"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"ed25519::..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"https://nrpc.herewallet.app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_delegate_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;actions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;TransferAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt; &lt;span class="n"&gt;receiver_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"bob.near"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;sign&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sign_delegate_transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;account_to_execute&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s"&gt;"bob.near"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"ed25519:..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"https://nrpc.herewallet.app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;account_to_execute&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;call_delegate_transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;delegate_action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;signature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;

&lt;span class="n"&gt;create_and_sign_delegate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we transfer 1 yNEAR from &lt;code&gt;alice.near&lt;/code&gt; to &lt;code&gt;bob.near&lt;/code&gt; and pay for gas from &lt;code&gt;bob.near&lt;/code&gt; balance.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Replace ed25519 public and private keys in the Account objects with your actual account keys. You also need to replace the receiver_id value in the &lt;code&gt;create_delegate_action&lt;/code&gt; method with the actual NEAR Protocol account ID where you want to send the transaction.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Not all RPC support delegate transactions. You can use &lt;a href="https://nrpc.herewallet.app"&gt;https://nrpc.herewallet.app&lt;/a&gt; for testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Executing the Delegate Transaction
&lt;/h3&gt;

&lt;p&gt;To execute the delegate transaction, use the &lt;code&gt;call_delegate_transaction&lt;/code&gt; method as in the Python code above. This method requires two parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;delegate_action:&lt;/code&gt; The DelegateActionModel object you created in the previous step.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;signature:&lt;/code&gt; The signature of the delegate transaction that you created in the previous step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can execute this transaction from any NEAR Protocol account. In the example above, the transaction is executed from the &lt;code&gt;bob.near&lt;/code&gt; account.&lt;/p&gt;

&lt;p&gt;And that's it! You have successfully created and executed a Delegate Transaction on NEAR Protocol, covering the gas costs on behalf of another user.&lt;/p&gt;

</description>
      <category>web3</category>
      <category>nearprotocol</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>Setup IPFS images cache server in 5 min</title>
      <dc:creator>Volnov Peter</dc:creator>
      <pubDate>Fri, 19 May 2023 08:34:36 +0000</pubDate>
      <link>https://dev.to/pvolnov/setup-ipfs-images-cache-server-in-5-min-4n8f</link>
      <guid>https://dev.to/pvolnov/setup-ipfs-images-cache-server-in-5-min-4n8f</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we will explore the importance of caching images from IPFS (InterPlanetary File System) and demonstrate how to set up a basic IPFS image caching service using the repository called ipfs-cache-server (&lt;a href="https://github.com/pvolnov/ipfs-cache-server"&gt;https://github.com/pvolnov/ipfs-cache-server&lt;/a&gt;). Caching images from IPFS can greatly improve performance and reduce bandwidth usage, especially in scenarios where the same images are frequently accessed&lt;/p&gt;

&lt;h2&gt;
  
  
  Why we need to cache IPFS images?
&lt;/h2&gt;

&lt;p&gt;IPFS is a distributed file system that allows storing and sharing content using cryptographic hashes. While IPFS provides a decentralized and resilient way to store and retrieve files, accessing files directly from IPFS can sometimes introduce performance challenges, especially when dealing with large files or high-demand scenarios. By caching IPFS images, we can alleviate some of these challenges by storing the frequently accessed images closer to the users, reducing the need for repeated network requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lets go
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Create a folder for image caching:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; /var/www/cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Configure image share via nginx:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install and configure Nginx to serve the cached images. Add the following Nginx configuration to the appropriate server block in your Nginx configuration file (e.g., &lt;code&gt;/etc/nginx/sites-available/default&lt;/code&gt; or &lt;code&gt;/etc/nginx/conf.d/default.conf&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;location /ipfs/ {
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:7001;
}

location /cache/ {
    alias /var/www/cache/;
    expires 30d;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this configuration, requests to /ipfs/ will be proxied to the ipfs-cache-server running on 127.0.0.1:9090, while requests to /cache/ will serve the cached images directly from the /var/www/cache/ directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Setup cache server&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/pvolnov/ipfs-cache-server
&lt;span class="nb"&gt;cd &lt;/span&gt;ipfs-cache-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the &lt;code&gt;config.yml&lt;/code&gt; file and update the following configuration parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;folder_size&lt;/code&gt;: The maximum cache size in MB.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cache_folder&lt;/code&gt;: The path to the cache folder (default is ./cache).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;image_server_prefix&lt;/code&gt;: web link to ngnix server to share images from cache folder&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;max_size&lt;/code&gt;: The maximum number of images in the cache folder. Set cache folder path in docker-compose.yml:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Add cache folder path&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open the docker-compose.yml file and update the volume mapping to your desired cache folder path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;volumes:
  - /var/www/here-storage/cache:/workdir/cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Run&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to use
&lt;/h2&gt;

&lt;p&gt;Make all requests via cache server, create url &lt;code&gt;https://&amp;lt;image server&amp;gt;/url?sz=XXX&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;server-url&lt;/code&gt;: &lt;a href="https://image.herewallet.app"&gt;https://image.herewallet.app&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ipfs url&lt;/code&gt;: &lt;a href="https://nftstorage.link/ipfs/bafybeieboqph4qqf2n7lasq4ehn6snke2nhdqzde4i4hlywwd3dd7mcjma/U1307.png"&gt;https://nftstorage.link/ipfs/bafybeieboqph4qqf2n7lasq4ehn6snke2nhdqzde4i4hlywwd3dd7mcjma/U1307.png&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ipfs id&lt;/code&gt;: nftstorage.link/ipfs/bafybeieboqph4qqf2n7lasq4ehn6snke2nhdqzde4i4hlywwd3dd7mcjma/U1307.png&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;size&lt;/code&gt;: 512*512&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://image.herewallet.app/nftstorage.link/ipfs/bafybeieboqph4qqf2n7lasq4ehn6snke2nhdqzde4i4hlywwd3dd7mcjma/U1307.png?sz=512"&gt;https://image.herewallet.app/nftstorage.link/ipfs/bafybeieboqph4qqf2n7lasq4ehn6snke2nhdqzde4i4hlywwd3dd7mcjma/U1307.png?sz=512&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Caching IPFS images can significantly enhance performance and reduce network overhead when serving frequently accessed images. In this tutorial, we explored the importance of image caching from IPFS and demonstrated how to set. &lt;/p&gt;

&lt;p&gt;P.S. Add ⭐️ for &lt;a href="https://github.com/pvolnov/ipfs-cache-server"&gt;https://github.com/pvolnov/ipfs-cache-server&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nft</category>
      <category>ipfs</category>
      <category>web3</category>
      <category>python</category>
    </item>
  </channel>
</rss>
