<?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: Andrei Shen</title>
    <description>The latest articles on DEV Community by Andrei Shen (@andreishen).</description>
    <link>https://dev.to/andreishen</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%2F800357%2Ff96a3b36-f73d-4216-bb96-41fa3734eac4.png</url>
      <title>DEV Community: Andrei Shen</title>
      <link>https://dev.to/andreishen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andreishen"/>
    <language>en</language>
    <item>
      <title>HOW TO BUILD A CRYPTO EXCHANGE FROM SCRATCH?</title>
      <dc:creator>Andrei Shen</dc:creator>
      <pubDate>Tue, 25 Jan 2022 08:33:41 +0000</pubDate>
      <link>https://dev.to/andreishen/how-to-build-a-crypto-exchange-from-scratch-4d4f</link>
      <guid>https://dev.to/andreishen/how-to-build-a-crypto-exchange-from-scratch-4d4f</guid>
      <description>&lt;p&gt;A cryptocurrency exchange is a platform that allows users to buy / sell a variety of tokens. It's like a stock exchange, but instead of stocks, you buy or sell cryptocurrencies. In this article, we will show you how to build such a cryptocurrency exchange from scratch.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cryptocurrency exchange type
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s2OPcQCJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0ihrxi3umwstagtfxri.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s2OPcQCJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0ihrxi3umwstagtfxri.jpg" alt="Image description" width="686" height="419"&gt;&lt;/a&gt;&lt;br&gt;
The first step in starting your own cryptocurrency exchange is choosing the type of trading platform you plan to build. This is important, since the mechanism for exchanging cryptocurrencies, the way they are stored, liquidity management, the ability to trade fiat and other functions depend on the choice of the platform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Centralized exchanges (CEX).&lt;/strong&gt;  The most common type of trading platforms, the main feature of which is the presence of a centralized operator responsible for the security, updates and functionality of the exchange. The main advantages of centralized platforms are the speed of crypto transactions and the absence of liquidity problems. The main weak point is security, since centralized exchanges store user funds in their wallets, which, as practice shows, are often hacked.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aMWiiiyR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7dmbl996n5e8h6fv1ui.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aMWiiiyR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h7dmbl996n5e8h6fv1ui.jpg" alt="Image description" width="694" height="225"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Decentralized exchanges (DEX).&lt;/strong&gt; Such platforms bring sellers and buyers of cryptocurrency together, giving them the ability to automatically exchange assets without the participation of intermediaries to validate the transaction. The role of the guarantor of the transaction is assumed by the platform's smart contracts, which operate on the basis of open source software. This mechanism allows you to save on commissions (no need to pay intermediaries) and increase the level of security (the exchange does not have access to money and private keys of users). However, you should keep in mind that on such exchanges, the lack of third-party moderation shifts all responsibility for errors to the users themselves.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dNz8WEv6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y3wyv4a2m6byhqofga44.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dNz8WEv6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y3wyv4a2m6byhqofga44.jpg" alt="Image description" width="656" height="236"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Peer-to-peer exchanges (P2P).&lt;/strong&gt; These are essentially online message boards for buying / selling cryptocurrency. Users enter the platform, look for a counterparty with a supply offer (denomination, amount, rate, transfer method) and contact him to agree on an exchange. You can buy a crypt in this way using fiat, gold or ordinary goods - as the parties agree. In this case, the transaction can be carried out both online and in person.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C6_2Tmy4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ou5mee0703q58ar1lbn1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C6_2Tmy4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ou5mee0703q58ar1lbn1.jpg" alt="Image description" width="691" height="243"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Instant exchangers.&lt;/strong&gt;  Platforms that act as a regular exchange point are very easy to use. All the user needs to do is open a trade order and it will be instantly executed. This is possible because such sites act as a broker that provides access to the liquidity of many exchanges. Fee foe speed is an increase in the number of intermediaries, which leads to higher commissions and a decrease in the level of security.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8XBIwvAS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/scyjbsxak567z7xz5l18.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8XBIwvAS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/scyjbsxak567z7xz5l18.jpg" alt="Image description" width="684" height="154"&gt;&lt;/a&gt;&lt;br&gt;
Also on the market, you can find hybrid platforms that combine the properties of centralized and decentralized exchanges. For example, a service can be operated by third-party operators and give traders more control over their funds. Orders and transactions on such crypto-exchanges are encrypted, fixed in time and stored on the blockchain, and order approval is performed outside the blockchain on a third-party node.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QxcHKEbq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qjqqbku4o016c3x4tcw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QxcHKEbq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qjqqbku4o016c3x4tcw.jpg" alt="Image description" width="689" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic and advanced functions
&lt;/h3&gt;

&lt;p&gt;In the next step, you need to decide what functionality should be implemented in your crypto exchange. It is usually divided into such modules:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization and verification.&lt;/strong&gt; The path of an ordinary user to trading on the exchange begins with registration via email or accounts on social networks and Google. But registration itself is usually not enough to start trading. This requires personal identification - verification. This verification is necessary to ensure transparency of transactions and minimize the possibility of fraud, and also because it is required by regulators.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Platform trading engine.&lt;/strong&gt; It is responsible for the basic functionality of the trading platform. For example, a trading engine checks the balance in a user's wallet to make sure that they have enough funds to make a transaction. It also compares trade orders and rates in real time, carries out transactions, processes information about prices and commissions, creates charts, etc.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6tsAmUnG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1w08llrhzd4c0oo0w422.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6tsAmUnG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1w08llrhzd4c0oo0w422.jpg" alt="Basic trading interface of Binance cryptocurrency exchange" width="694" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User interface.&lt;/strong&gt; Depending on the target audience, the user interface can be simple and intuitive or relatively complex due to the many indicators, trading signals, customizable charts and other tools of an experienced trader. In any case, the user should be able to place buy and sell orders, view the current order book, past transactions, balances, statistics, etc. You should also be able to customize all this for yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exchange admin panel.&lt;/strong&gt; Includes a panel for tracking the current state of the exchange (traffic, trading volume, number of transactions, income from commissions), traders, wallets, transactions and content. In addition, tools should be implemented to verify users, change and remove content, ban and remove users, change commissions, manage marketing and affiliate programs.&lt;br&gt;
It will also be convenient if you have a system for automatically checking users for "strange" actions, like on Binance: if a trader does something compromising (strange, unusual, clearly unauthorized), the system will notify the administrator and may even temporarily freeze operations on the compromised account and / or undo the last action.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cryptocurrency wallet.&lt;/strong&gt;  If you are developing a centralized platform, then you need the functionality of an internal wallet. It is needed for faster access to money, which speeds up the process and makes it easier, as well as to ensure the liquidity of the exchange. In the case of decentralized and peer-to-peer cryptocurrency exchanges, there is usually no need to create an internal wallet.&lt;br&gt;
Think about how users will be able to replenish their wallets and withdraw funds from them to a card or their cryptocurrency account. For example, Coinbase allows traders to connect their bank account and transfer dollars to or from a wallet easily. This possibility can be realized both with the help of manual withdrawal of funds, and through automated algorithms / smart contracts.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VKjXE2g3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qe7zie8krjxjuoyq6nmn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VKjXE2g3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qe7zie8krjxjuoyq6nmn.jpg" alt="Order book on Coinbase cryptocurrency exchange" width="641" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Order book and transaction history.&lt;/strong&gt;  This is another important element that you must implement when launching your own cryptocurrency exchange. An order book is a list of open orders to buy or sell a cryptocurrency. The exchange creates it automatically, grouping orders for the purchase and sale of cryptoassets into separate lists and compares them. When an order finds an offer that matches its conditions, the system automatically exchanges and closes the order. A closed order disappears from the order book and goes into the transaction history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analytical tools for traders.&lt;/strong&gt; This functionality will help attract experienced traders to the platform. Analytical tools allow you to receive additional information about the current state of the market, predict its movement, analyze trends, create and test trading strategies. When starting a crypto exchange, you have to decide what indicators you want to see on your platform. The most popular (required) options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Relative Strength Index (RSI)&lt;/strong&gt;, which shows the strength of the trend and the likelihood of its change. It works simply: the system measures the magnitude of recent price changes and displays the rate of price change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Moving Average (MA)&lt;/strong&gt;. Another important indicator that helps identify trends by showing the average price for a selected period.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Moving Average Convergence / Divergence (MACD)&lt;/strong&gt;. Used to assess and predict price fluctuations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Push notifications and alerts.&lt;/strong&gt; Allows you to keep in touch with users, informing them about important events on the exchange: stocks, news, special applications, updates, etc. In addition, alerts can also be integrated into trading to show traders notifications about changes in the rate of selected trading pairs, trend changes, notifying an important indicator or closing a trade. But there is one point. Don't forget to allow users to choose which notifications they want to turn on. Alerts should be helpful and customizable, not mandatory and annoying.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security features.&lt;/strong&gt; One of the main problems of the cryptocurrency market is the low security of cryptocurrency exchanges. Not a year goes by without news of another hack of any exchange. The loudest are: Mt. Gox - $ 450 million, Bitfinex - $ 65 million, Bithumb - $ 58 million, Binance - $ 40.5 million.&lt;/p&gt;

&lt;p&gt;Therefore, when creating your own trading platform, you need to do everything to protect the data and money of your users, especially if you want to create a centralized cryptocurrency exchange. Here's what will help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Protection against denial of service (DoS).&lt;/li&gt;
&lt;li&gt;Protection of HTTP parameters from pollution.&lt;/li&gt;
&lt;li&gt;Protection against distributed denial of service (DDoS).&lt;/li&gt;
&lt;li&gt;Protection against server side request forgery (SSRF).&lt;/li&gt;
&lt;li&gt;Protection against cross-site request forgery (CSRF).&lt;/li&gt;
&lt;li&gt;Two-factor and HTTPS authentication.&lt;/li&gt;
&lt;li&gt;Biometric authentication.&lt;/li&gt;
&lt;li&gt;Data encryption.&lt;/li&gt;
&lt;li&gt;SQL injection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;KYC, KYT, AML compliance.&lt;/strong&gt; If you want to work in the American, European and other markets, where exchanges are subject to increased requirements for combating money laundering and terrorist financing, then you need to implement the following procedures and standards into your trading platform:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;KYC — Know your customer.&lt;/strong&gt; Each user will have to go through a personal identification of the person. Of course, you can independently collect user documents and carry out identification procedures using databases (PEP, sanction lists, etc.). But why bother when you can use out-of-the-box services that make it easy and cost-effective to implement verification processes such as &lt;a href="https://sumsub.com/"&gt;Sumsub&lt;/a&gt;, &lt;a href="https://www.trulioo.com/"&gt;Trulioo&lt;/a&gt; or &lt;a href="https://www.veriff.com/"&gt;Veriff&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;KYT — Know your transaction.&lt;/strong&gt; Prescribes to crypto exchanges the obligation to verify from which sources user tokens are taken and to block transactions from suspicious sources. Here you can also not reinvent the wheel, but use an external service, for example, &lt;a href="https://traceer.co/"&gt;Traceer&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compliance with AML.&lt;/strong&gt; According to US law, the state of the crypto exchange must have a certified anti-money laundering officer who is responsible for tracking suspicious transactions and sending SAR (Suspicious Activity Reports) to the financial monitoring authorities. This employee must have a degree in finance and a certificate that is issued by the &lt;a href="https://www.int-comp.org/"&gt;ICA&lt;/a&gt; or &lt;a href="https://www.acams.org/en"&gt;ACAMS&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Liquidity management.&lt;/strong&gt; Traders need an exchange that allows them to easily exchange one asset for another in no time. This is only possible if the site has enough liquidity: orders to buy or sell crypto to complete the transaction at a reasonable price. You can provide liquidity by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Third party market maker.&lt;/strong&gt; Involves an agreement with liquidity providers who typically trade simultaneously in many different locations and can provide the liquidity needed for one cryptocurrency exchange by entering into trades on other trading platforms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Creation of an inter-exchange market.&lt;/strong&gt; This strategy also implies cooperation with a market maker, but in this case, you enter into an agreement directly with the operator of an external exchange, and not a third party.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Liquidity mining.&lt;/strong&gt; This method is most associated with decentralized communities as it rewards users for helping to secure liquidity. The simplest option: the user deposits money into the exchange account and once a month or a year receives a reward in the form of a percentage of his contribution.  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Architecture, technology stack and API
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Exchange architecture.&lt;/strong&gt; This concept usually means the structure of the platform, which helps to logically and visually define the relationship and the way of interaction between all the components of the exchange: the login screen, the trading engine, the user interface, security functions, API, databases, etc. Here is an example of such an architecture:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MmQsk4fP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xty3gs41f9s0r8x3zbj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MmQsk4fP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xty3gs41f9s0r8x3zbj.jpg" alt="Architecture of Qurrex hybrid cryptocurrency exchange" width="665" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technology stack.&lt;/strong&gt; It is a set of development tools such as programming languages, libraries, frameworks, database management systems, compilers, APIs, etc., for creating the backend and frontend of the platform. In the case of creating a cryptocurrency exchange, it may look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CxwDHkV2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltjslk7raxrkh1vr70lz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CxwDHkV2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ltjslk7raxrkh1vr70lz.jpg" alt="Image description" width="597" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ul4JQbNP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ap5e9viyzqofarpnmehd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ul4JQbNP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ap5e9viyzqofarpnmehd.jpg" alt="Image description" width="660" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Development of cryptocurrency exchange
&lt;/h3&gt;

&lt;p&gt;A cryptocurrency exchange should be launched only through custom development, since only in this way can you ensure the proper quality and security of the software. There are ready-made solutions (scripts), but they, as a rule, are created by amateurs and / or carry risks that there will be many security holes in the code, created on purpose or through oversight. Considering the situation with such frequent hacks of cryptocurrency exchanges, it is not worth the risk.&lt;/p&gt;

&lt;p&gt;And then, the process of creating a cryptocurrency trading platform will be as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Signing a contract. You and the developer company discuss the general concept of the cryptocurrency exchange, on the basis of which the technical description of the project is created. After that, you agree on the timing, cost, KPI, communication channels and sign a cooperation agreement.&lt;/li&gt;
&lt;li&gt;Platform prototyping. At the next stage, the designer, business analyst and / or the customer create a framework for the design of the cryptocurrency exchange, which is then discussed and brought to an ideal state.&lt;/li&gt;
&lt;li&gt;Creation of interface design. Further, based on the wireframe, designers develop a layout and / or prototype of the platform interface, which show how it will look for traders and admins.&lt;/li&gt;
&lt;li&gt;Direct encoding. After creating the design, it and the technical description are given to the programmers who implement all this in the code. Front-end, back-end, blockchain and mobile developers are responsible for this.&lt;/li&gt;
&lt;li&gt;Product testing. Almost immediately after the start of coding, QA engineers get down to business, who check the fresh code for errors, and so on until the software is written. Other tests are carried out in parallel.&lt;/li&gt;
&lt;li&gt;Deployment and support. After the cryptocurrency exchange software is ready to launch, a marketing campaign is launched to attract traders. The platform is added to business listings and social networks.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The cost of creating a crypto exchange
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xioOVKkr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/go20iwf3roun19cdl3bs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xioOVKkr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/go20iwf3roun19cdl3bs.jpg" alt="Image description" width="657" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cryptocurrency</category>
      <category>blockchain</category>
      <category>dex</category>
      <category>programming</category>
    </item>
    <item>
      <title>Exploring the NFT Royalty Standard (EIP-2981)</title>
      <dc:creator>Andrei Shen</dc:creator>
      <pubDate>Mon, 24 Jan 2022 13:01:32 +0000</pubDate>
      <link>https://dev.to/andreishen/exploring-the-nft-royalty-standard-eip-2981-5157</link>
      <guid>https://dev.to/andreishen/exploring-the-nft-royalty-standard-eip-2981-5157</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1AyxGM0---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/plfc2odh74uemn55ia1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1AyxGM0---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/plfc2odh74uemn55ia1t.png" alt="Image description" width="880" height="494"&gt;&lt;/a&gt;&lt;br&gt;
Over the last 12 months, the non-fungible token (NFT) market has soared. We’ve seen our very own Nifty Gateway achieve explosive growth. With all this excitement, we’re eager to explore where the space is headed with a particular focus on what value an open royalty standard can bring to NFT creators.&lt;/p&gt;

&lt;p&gt;If you ask participants in the NFT ecosystem what they’re most excited about, you’ll likely hear various different responses, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Investing in a new asset class&lt;/li&gt;
&lt;li&gt;Being part of a community&lt;/li&gt;
&lt;li&gt;Opportunity to resell for profit&lt;/li&gt;
&lt;li&gt;The positive long term impact of NFT technology&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, a lingering promise since the inception of NFTs, is the idea that there is now &lt;em&gt;a new medium for creators to monetize their work&lt;/em&gt;. More specifically, royalty payments can now be seamlessly facilitated through blockchain infrastructure.&lt;/p&gt;

&lt;p&gt;Creators have already been making use of the existing royalty payment solutions, and many have already been able to realize a newfound passive income stream. So, what’s the problem?&lt;/p&gt;
&lt;h3&gt;
  
  
  The NFT Royalty Landscape Today
&lt;/h3&gt;

&lt;p&gt;NFT standards (&lt;a href="https://eips.ethereum.org/EIPS/eip-721"&gt;ERC-721&lt;/a&gt;/&lt;a href="https://eips.ethereum.org/EIPS/eip-1155"&gt;ERC-1155&lt;/a&gt;) are built on &lt;a href="https://ethereum.org/"&gt;Ethereum&lt;/a&gt;. Broadly speaking, marketplaces transfer ownership of NFTs between collectors upon a sale. These transfer mechanisms are made easy because of the open standards that exist. These standards have facilitated the proliferation of many NFTs we see today, of course with the exception of some that predated their creation e.g. &lt;a href="https://www.larvalabs.com/cryptopunks"&gt;CryptoPunks&lt;/a&gt;, &lt;a href="https://www.cryptokitties.co/"&gt;CryptoKitties&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the time of this writing, an open royalty payment standard is not ubiquitous in the Ethereum ecosystem. Royalty information is siloed to marketplaces and generally not shared. This means that if an NFT is moved off a platform and then sold, the creator won’t receive the royalties that they’re entitled to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://eips.ethereum.org/EIPS/eip-2981"&gt;EIP-2981&lt;/a&gt; is a standard that focuses on signaling to market participants the royalty payment information for a given NFT or set of NFTs. It allows for attaching royalty information to the token itself, thereby making use of a common data store and computation layer that all participants can access — the Ethereum blockchain.&lt;/p&gt;

&lt;p&gt;After nearly one year of &lt;a href="https://github.com/ethereum/EIPs/issues/2907"&gt;discussions&lt;/a&gt;, EIP-2981 was finalized on July 24, 2021.&lt;/p&gt;
&lt;h3&gt;
  
  
  How Does it Work?
&lt;/h3&gt;

&lt;p&gt;It’s pretty simple. The crux of the problem can be solved by overriding a single &lt;a href="https://docs.soliditylang.org/"&gt;Solidity&lt;/a&gt; function in your smart contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// @notice Called with the sale price to determine how much royalty is owed and to whom.
/// @param _tokenId - the NFT asset queried for royalty information
/// @param _salePrice - the sale price of the NFT asset specified by _tokenId
/// @return receiver - address of who should be sent the royalty payment
/// @return royaltyAmount - the royalty payment amount for _salePrice

function royaltyInfo( 
    uint256 _tokenId,
    uint256 _salePrice
) external view returns (
    address receiver,
    uint256 royaltyAmount
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The general goal of EIP-2981 contributors is to provide a gas-efficient solution while avoiding restrictions on future royalty payment improvements. The simplicity of its design is intentional, with the aim to make adoption simple. As with any standard, adoption is key to its utility.&lt;/p&gt;

&lt;p&gt;In the usual case, for a given NFT _&lt;em&gt;tokenId&lt;/em&gt; and _&lt;em&gt;salePrice&lt;/em&gt;, the &lt;em&gt;royaltyInfo&lt;/em&gt; function will perform a percentage calculation to produce the necessary (and undisputed) information to craft a royalty payment transaction.&lt;/p&gt;

&lt;p&gt;Notice how the function does not concern itself with currency. The existing standards for NFTs (ERC-721/1155) are currency agnostic. In fact, if we zoom out a little, NFT smart contracts aren't even aware of the concept of a "sale". When it comes to more abstract concepts like sales, it is the marketplaces that facilitate them.&lt;br&gt;
 As a reminder, two key actions occur when a sale takes place:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A transfer of funds from the buyer to the seller&lt;/li&gt;
&lt;li&gt;A transfer of the NFT from the seller to the buyer&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As far as the NFT smart contract is concerned, it can’t tell if an invocation of &lt;a href="https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md#specification"&gt;safeTransferFrom&lt;/a&gt; was a simple transfer of the NFT to another address or an actual sale event. This alone makes enforcing royalty payments on-chain challenging. Specifically when you’re conforming to existing standards that aren’t built with this in mind.&lt;/p&gt;

&lt;p&gt;It’s important for marketplaces supporting EIP-2981 to consider the currency that the NFT sale was denominated in. The royalty calculation should be in the same denomination. So, if an NFT was sold for 45×1018 Wei (45 Ether), then the &lt;em&gt;royaltyAmount&lt;/em&gt; returned from the function would be in the expected denomination (Wei).&lt;/p&gt;

&lt;p&gt;With that in mind, let’s jog our memory on the fact that math in Solidity does not support fractions and suggest one possible workaround:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;2.5% of the _&lt;em&gt;salePrice&lt;/em&gt; should be sent to the receiver, we know that 2.5% of 45 Ether is 1.125 Ether. However, Solidity will compute 1 Ether:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;uint256 result = (uint256(45) * 250) / 10000;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;More precision is required, so we can convert Ether to Wei; 45 Ether is now 45×1018 Wei and Solidity will compute 1.125×1018 Wei or 1.125 Ether:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;uint256 result = (45000000000000000000 * 250) / 10000;&lt;/p&gt;

&lt;p&gt;This highlights a potential pitfall that Solidity engineers should be no stranger to. That is, the _&lt;em&gt;salePrice&lt;/em&gt; should be sent in the smallest denomination of the currency tendered. This reduces the likelihood of disputes with respect to how Solidity performs arithmetic operations. To further ensure that precision is kept, implementers should consider using basis points (bps). Notice how 2.5% is denoted as 250 bps and 100% is 10,000 bps. This common unit of measure for percentage interest rates in finance works well here.&lt;/p&gt;

&lt;p&gt;In addition to this, it’s advised to extensively unit test this function before deploying to production. Call sites invoking this function can also check that the &lt;em&gt;royaltyAmount&lt;/em&gt; value that was calculated is sensible e.g. &lt;em&gt;royaltyAmount &amp;lt; _salePrice&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pbqVAS59--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj1yb821mrdueekomhc6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pbqVAS59--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dj1yb821mrdueekomhc6.png" alt="Image description" width="880" height="611"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  EIP-2981 in Action
&lt;/h3&gt;

&lt;p&gt;A nice example of EIP-2981 in action can be found at this &lt;a href="https://github.com/dievardump/EIP2981-implementation"&gt;example &lt;/a&gt;. Here we can see royalties implemented on a &lt;em&gt;per token&lt;/em&gt; basis. In contrast, we can also see globally applied royalties, where every token is associated with the &lt;em&gt;same&lt;/em&gt; royalty information. This can be achieved relatively easily with some small tweaks to the smart contract.&lt;/p&gt;

&lt;p&gt;The cryptocurrency space is known for pushing the boundaries and testing assumptions of existing systems. EIP-2981 is no exception — engineers and enthusiasts can get creative with how the &lt;em&gt;royaltyInfo&lt;/em&gt; function is implemented. Some interesting approaches might include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fixed royalties&lt;/strong&gt; — this is expected to be the common case where a static percentage is used for every sale.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decaying royalties&lt;/strong&gt; — reduce royalties owed for every transfer event of the NFT over time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multisig royalties&lt;/strong&gt; — the receiver address could be a multisig smart contract. It may represent a DAO or some effort towards public goods funding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stepped royalties&lt;/strong&gt; — don’t send royalties if the sale price is below a threshold.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many contributors see this standard as a necessary building block towards a more open royalties system. For the most part, there's a particular focus on socially enforced royalties; a system where incentives between participants align such that leaving royalties unpaid is disincentivized. It’s a common belief that this approach could prove to be very resilient, and further reinforced by more transparency with respect to royalty payment obligations.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Next?
&lt;/h3&gt;

&lt;p&gt;For EIP-2981 to become widely supported we must &lt;strong&gt;raise awareness&lt;/strong&gt;. Gentle forces can be applied to marketplaces by artists who request it. In addition to this, marketplaces can also anticipate the demand and implement it sooner.&lt;/p&gt;

&lt;p&gt;All things considered, marketplaces will decide on a case-by-case basis whether to support the EIP-2981 standard. With some familiar names in the NFT landscape already supporting it, we’re optimistic others will follow.&lt;/p&gt;

&lt;p&gt;We see this as an exciting development and one to keep a close eye on in the coming months.&lt;br&gt;
Onward and Upward!&lt;/p&gt;

</description>
      <category>nft</category>
      <category>royalty</category>
      <category>solidit</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
