# DecentralChain documentation The complete manual, 18 sections. Source: https://decentralchain.io/docs --- # Introduction Source: https://decentralchain.io/docs/introduction How did money become the basis of trade for such a long time? To have an answer for such question we must understand what money is and the different ways money has been used through the time. ## Definition of Money Money is often defined it by the roles it plays: - It's a store of value, meaning that money allows you to defer consumption until a later date. - It's a unit of account, meaning that it allows you to assign a value to different goods without having to compare them. So instead of saying that a Rolex watch is worth six cows, you can just say it (or the cows) cost $10 000. - And it's a medium of exchange, meaning it's an easy and efficient way for different parties to trade goods and services with one another. ## History of Money Even though we're able to define what money is, when it comes to its origins, money has been mum about them. For such a central element of our lives, money’s ancient roots and the reasons for its invention are unclear, most of the available knowledge is based on conjectures and logical inferences. Some economists assume that bartering of goods and services inspired money’s invention. On the other hand there are anthropologists and archaeologists contending that early states invented currency as a means of debt payment. Several investigations suggest that money independently appeared for different reasons and assumed different tangible forms in many parts of the world, starting thousands of years ago and bartering had nothing to do with it but instead, money grew out of older systems of credit and debt. In small-scale societies, debts concern obligations to others while among hunter-gatherer and farming groups daughters given away in marriage create debts that are partially repaid with goods known as bridewealth where full repayment requires that the recipient of the first bride provide a bride in return. No cash needed. Revisionists argue that a transition to a new form of money-friendly debt started at least 5,500 years ago in the agricultural states of Mesopotamia and Egypt. In Mesopotamia, the silver shekel — a lump of metal, not a coin — was a basic monetary measure. Rulers decreed that one shekel’s weight in silver was equivalent to a bushel of barley. Shekels of silver, gold and other metals were used in other ancient societies. Precise weights of shekels appear to have varied from one to the next one and therefore are difficult to pin down. Farmers were taxed to support royal lifestyles and public works, what the farmers and other commoners couldn’t pay in goods was recorded as debt in shekels. Merchants and tradespeople acquired goods from temple and palace officials on credit. Coins stamped with images of animals or rulers, acting as denominations and guaranteeing the metal’s value, first appeared in the kingdom of Lydia around 2,600 years ago. Located in what is now Turkey, Lydia sat on the cusp between the Mediterranean and the Near East, and commerce with foreign travelers was common which was one of the major promoters for this coin mint to happen. To understand why, imagine doing a trade in the absence of money or in other words through barter. The chief problem with barter is the double coincidence of wants. Say you have a bunch of bananas and would like a pair of shoes, but it's not enough to find someone who has some shoes or someone who wants some bananas. To make the trade, you need to find someone who has shoes they're willing to trade and that wants bananas which is no easy task. With a common currency, the task becomes easier: You just sell your bananas to someone in exchange for money, with which you then buy shoes from someone else. And if, as in Lydia, you have foreigners from whom you'd like to buy or to whom you'd like to sell, having a common medium of exchange is obviously valuable. That is, money is especially useful when dealing with people you don't know and may never see again. The Lydian system's breakthrough was the standardized metal coin. Made of a gold-silver alloy called electrum, one coin was exactly like another—unlike, say, cattle. Also unlike cattle, the coins didn't age or die or otherwise change over time. And they were much easier to carry around. Other kingdoms followed Lydia's example, and coins became ubiquitous throughout the Mediterranean, with kingdoms stamping their insignia on the coins they minted. This had a dual effect: it facilitated the flow of trade, and it established the authority of the state. The spread of money throughout the Mediterranean didn't mean that it was universally used; soon after Lydia, cities and states in Greece, Persia, India and China began to strike their own coins, but even then most people were still subsistence farmers and existed largely outside the money economy. But as money became more common, it encouraged the spread of markets. Once a small part of the economy is taken over by markets and money, they tend to colonize the rest of the economy, gradually forcing out barter, feudalism, and other economic arrangements. This happens mostly because money makes market transactions so much easier and also because using money seems to redefine what people value, pushing them to view things in economic, rather than social, terms. Governments were quick to embrace hard currency because it facilitated the collection of taxes and the building of military forces, coins funded armies and wars of conquest. In the process, coins became legal tender for all sorts of transactions. Marketplaces were a result of this system, not its cause, revisionists argue. Once the Chinese had started making comparatively inexpensive paper from natural fibers, and discovered block-printing, paper currency came into use in the country. The first known use of paper currency in China is reported from the Tang dynasty and despite the fact that scarce information remains about this early system of paper currency there's evidence that these were certificates issued by the Tang government to pay local merchants in distants parts of the empire. By using certificates, the government could avoid having to transport metal money far away. Each certificate had a certain amount of money stated on it and was redeemable for metal cash on demand in the Chinese capital. Most merchants never went through the trouble of going to the capital to get cash for their certificate, instead the certificates were used as money locally, since they were transfereable. The view of money as commodity began to shift only with the widespread adoption of paper currency. Compared to traditional money made from precious metals, paper currency was easier to transport, and the use of paper currency also freed up metal that could be put to other use. In 1821, the Bank of England adopted the gold standard, promising to redeem its notes for gold upon request. As other countries followed suit, the gold standard became the general rule for developed economies. The discovery of major new gold fields over the course of the 19th century ensured that the money supply kept growing. The gold standard, as it was intended to do, brought stability to prices and was enormously beneficial to property holders and lenders. However, it also brought deflation—that is, prices generally fell—because as countries, populations and economies grew, their governments had no easy way to increase the money supply short of mining more gold, and so money in effect became more scarce. Deflation was hard on farmers and borrowers, who longed for a little inflation to help them with their debts; when money gradually loses some of its value, so, too, do people's debts. What finally derailed the gold standard was World War I. Since governments needed more money for their militaries than they had in gold, and so they simply began printing it. And though many countries tried to return to the gold standard after the war, the Great Depression consequences made it end for good. Because of this currencies today are “fiat" currencies, meaning they're backed by the authority of the issuing government, and nothing more. In the United States, for example, that means the government accepts only dollars as payment for taxes and requires its creditors to accept dollars in payment for debts. But if people were to lose faith in the dollar and stop accepting it in everyday transactions, it would eventually become worthless. The reliance on fiat money, we're told, gives too much power to the government, which can recklessly print as much money as it wants. Yet the truth is that this has always been possible. Even with the gold standard, governments revalued their currencies from time to time, in effect dictating a new price for gold, or they ignored the standard when it proved too limiting, as during the First World War. What's more, the notion that gold is somehow more “real" than paper is, well, a mirage. Gold is valuable because we've collectively decided that it's valuable and that we'll accept goods and services in exchange for it. And that's no different, ultimately, from our collective decision that colorful rectangles of paper are valuable and that we'll accept goods and services in exchange for them. ## Difference Between Money and Currency While most of the time, the terms "money" and "currency" are used interchangeably, there are some suggestions that these terms are not identical terms; these suggest that money is inherently an intangible concept, while currency is the physical or tangible manifestation of the intangible concept of money. By extension, according to this suggestions, money cannot be touched or smelled. Currency is the coin, note, or object that is presented as the physical form of money. The basic form of money is numbers; today some of the basic forms of currency are paper notes, coins, or plastic cards. The powerful combination of computers and telecommunications, of smartphones and social media, of cryptography and virtual economies makes it seem like it's a possibility to create a cashless society. What matters most about money is not what it is, but what it does. After all, people will use the currencies that lubricate commerce, allow people to exchange goods and services, and thus encourage people to work and create. Money, whether it's represented by a metal coin, a shell or a piece of paper, doesn't always have value. Its value depends on the importance that people place on it—as a store of value, a unit of account, and a medium of exchange. Money is valuable merely because everyone knows that it will be accepted as a form of payment. However, throughout history, both the usage and the form of money have evolved. ## Definition of Cryptocurrencies Cryptocurrency is a digital or virtual form of currency; meaning it's a representations of value, that uses cryptography to secure and verify transactions as well as to control the creation of new units. Cryptocurrencies operate on systems that allow for secure online transactions to take place without the need for any central banks or intermediaries. Instead, transactions are recorded on a decentralized and distributed public ledger (DLT) called a blockchain, which is maintained by a network of computers around the world that record all transactions in a secure and transparent manner. ## Definition of Blockchain Technology Blockchain technology is crucial to cryptocurrencies as it allows transactions to be processed and authenticated without any central authority. Instead of relying on a single, centralized authority to manage and store the data, blockchains rely on a network of computers to validate and record transactions, which makes them more secure and resistant to tampering or hacking. A blockchain offers a commonly agreed record of truth to multiple, mutually distrusting participants in an economic system since it keeps track of cryptocurrency transactions which are grouped into blocks. Each block is cryptographically linked to the previous one so as new blocks are added the older blocks become more difficult to modify. New blocks are replicated across all copies of the blockchain within the network, and any conflicts are resolved automatically using established rules. A blockchain is spread across nodes usually in different locations. This is one of the key ideas about blockchain, and gives it its unique decentralized features. Because of this, anyone can submit information to be stored onto a blockchain and therefore it is important that there are processes in place that can ensure everyone agrees on what information to add and what to discard. Different networks use different methods but this procesess together are what's called a consensus protocol and they are essentially the rules by which a network operates. ### Definition of Consensus Protocol Consensus is a pervasive problem in many areas of human endeavor; consensus is the process of agreeing to one of several alternates proposed by a number of agents. Consensus can be defined as an agreement, protocols are rules which describe how an activity should be performed. Simply put, consensus protocols could be viewed as “agreement rules”. A consensus protocol (also known as consensus mechanism or consensus algorithm) is used to achieve the necessary agreement on a single data value or a single state of the distributed ledger at any given time. It provides a method of review and confirmation of what data should be added to a blockchain's record. Because blockchain networks typically don't have a centralized authority dictating who is right or wrong, nodes on a blockchain all must agree on the state of the network, following the predefined rules, or protocol. ## Current State of Blockchain Technology ### Bitcoin The Bitcoin blockchain was first introduced in 2008 through a white paper by its pseudonymous creator Satoshi Nakamoto as a peer-to-peer electronic cash system that allows users to send payments directly to each other using Bitcoin (BTC), the blockchain's native currency, without the need for intermediaries such as financial institutions. The first Bitcoin transaction took place in January 2009, when Satoshi Nakamoto sent 10 Bitcoins to the first person who downloaded the software. The first commercial transaction using Bitcoin took place in 2010, when a programmer named Laszlo Hanyecz ordered two pizzas by paying 10,000 Bitcoins to an intermediary. Bitcoin uses a proof of work (PoW) consensus protocol, in which miners compete to solve complex mathematical equations using their computing power. The first miner who succeeds in solving the cryptographic puzzle adds the latest block of transactions to the blockchain and receives rewards in the form of newly minted coins and transaction fees. This process is energy-intensive and was designed to be difficult on purpose to "prove" that participants have done the "work" and are eligible to add a new block to the blockchain. The scripting language used in Bitcoin transactions is called Script. It is used almost exclusively to define how outputs can be spent and is responsible for enforcing the rules that govern Bitcoin transactions. In other words, Script determines who the BTC was sent to, how much was sent, and under what conditions it can be spent. ### Ethereum Ethereum is a decentralized blockchain platform that revolutionized the way applications are built and executed. Founded in 2015 by co-founder Vitalik Buterin, who published its white paper in 2013, Ethereum offers a range of features that go beyond those of Bitcoin, including the possibility to create new cryptocurrencies and the ability to execute smart contracts, which are self-executing agreements encoded onto the blockchain, with the terms of the agreement between buyer and seller being directly written into lines of code without the need for intermediaries all while enforcing the negotiation or performance of the contract automatically. By enabling the execution of smart contracts, Ethereum opens up the possibility of creating decentralized applications (DApps), which operate transparently and independently without any central authority. Like Bitcoin, Ethereum initially used a proof-of-work (PoW) consensus protocol, similar to Bitcoin, but it has undergone a major upgrade that moved it to a proof-of-stake (PoS) consensus protocol. Unlike Proof of Work (PoW) consensus models, where miners' ability to validate block transactions is based on their hardware's computing power, PoS models assign the task of validating new blocks based on the size of the node's stake, with larger stakes having a higher likelihood of producing the next block. The PoS system aims to provide a more energy-efficient alternative to PoW while still maintaining the security of the blockchain. This upgrade on the concensus protocol aims to increase efficiency, security, and reduce environmental impact by eliminating the need for the intensive computational power that PoW requires. The blockchain's native currency is called Ether or ETH. Ether is used mainly for two purposes—it is traded as a digital currency on exchanges in the same fashion as other cryptocurrencies, and it is used on the Ethereum network to run applications. Therefore all decentralized applications built on Ethereum allow Ether and other crypto assets to be used in a plethora of different ways including as collateral for loans or be lent out to borrowers to earn interest. Collateral refers to assets pledged as security for repayment of a loan. Ethereum offers multiple languages for programmers to develop smart contracts. The two most active and maintained languages are: - Solidity - Vyper ### DecentralChain DecentralChain is a cutting-edge, secure and efficient blockchain ecosystem empowering smart contract creation, decentralized application (DApps) development and a thriving decentralized finance (DeFi) community. It utilizes a consensus protocol called Leased Proof of Stake (LPoS) which aims to improve upon traditional Proof of Stake (PoS) by allowing users to lease their stakes to other users, which increases the latter's ability to produce new blocks. In return, the lender receives a percentage of the transaction fees earned by the validator. This leasing mechanism aims to address the possible centralization problem in traditional PoS models where a few large stakeholders control a significant portion of the network, and the decision-making power is concentrated in the hands of a small group of individuals or entities while at the same time allowing all users to earn rewards, extending the ability to participate in the network to not only minority stakeholders but also users who just want to lease their stakes to other users. DecentralChain offers a unique approach to decentralized application development by avoiding high gas fees for all transactions. The blockchain's native language, called Ride, is a non-Turing-complete language, which helps keep the system secure and predictable. Ride allows for the creation of smart contracts, which are self-executing agreements written in code that run without a central entity behind them. This provides a platform for decentralized applications (DApps), which are applications that work without a central authority. DecentralChain's use of Ride and LPoS helps to ensure the stability and security of the network, making it an attractive option for decentralized application development. ## DecentralChain Ecosystem The DecentralChain ecosystem enables secure communication and interoperability between different blockchain networks. The ecosystem uses protocols to facilitate the transfer of assets and information between blockchain networks, as well as incentivize sustainability by reducing carbon emissions per transaction and generating carbon credits. Additionally, the ecosystem encourages carbon sequestration, where the sequestered carbon is tokenized and can be traded on a blockchain platform. There is also a decentralized wallet and exchange built on the DecentralChain network that offers various benefits, such as fast execution rates, multi-chain capability, low fees, and interoperability. Here are some of our most visited websites: - [DecentralChain Website](https://decentralchain.io/) - [Decentral Exchange](https://decentral.exchange/) - Decentral Scan ### Wallet and Exchange Decentral.Exchange is an all-in-one platform that combines the features of a wallet, decentralized exchange, and cryptocurrency management tool into a single, seamless platform. Built on the DecentralChain blockchain, this platform offers numerous benefits to its users, including fast execution rates, multi-chain capability, low fees, and interoperability. One of the most significant advantages of decentralized exchanges is that they are not controlled by any central authority, giving users complete control over their assets. Unlike centralized exchanges, there is no risk of funds being frozen or confiscated by a centralized entity. With Decentral.Exchange, users can also enjoy enhanced security, as their private keys are stored locally on their device, reducing the risk of cybercrime. Decentralized exchanges also provide access to a wider range of assets, thanks to the absence of restrictions on the number of tokens that can be traded. Decentral.Exchange takes this further with its multi-chain capability, allowing users to trade tokens across different blockchains seamlessly. Decentral.Exchange's interoperability enables users to trade tokens across various chains and different decentralized exchanges, making it possible to access a broader range of assets effortlessly. One of the key selling points of Decentral.Exchange is its low fees, which sets it apart from traditional centralized exchanges that often charge exorbitant fees. The absence of intermediaries means that users can keep more of their profits, making trading more accessible to everyone. In the DecentralChain ecosystem, having a native decentralized exchange is essential, as it facilitates easy buying and selling of DecentralChain tokens within the ecosystem. Additionally, project participants can create their tokens and trade them on the exchange. Decentral.Exchange also enables users to send and receive coins without the need for a centralized intermediary. Decentral.Exchange is at the forefront of the future of crypto trading, providing users with a wide range of benefits that centralized exchanges cannot match. With its native blockchain, DecentralChain, Decentral.Exchange is ideally positioned to revolutionize the crypto industry and redefine the way we trade cryptocurrencies. ### Blockchain Explorer DecentralScan.com is the official block explorer of the DecentralChain blockchain. It is a powerful tool that allows users to view, track, and analyze transactions on the DecentralChain blockchain. The block explorer provides a user-friendly interface that simplifies the navigation of the complex data stored on the blockchain. One of the key benefits of DecentralScan.com is its ability to provide transparency to the DecentralChain ecosystem. It enables users to view all the transactions that have occurred on the blockchain in real-time, including the number of DecentralCoins (DCC) transferred, the addresses involved in the transaction, and the transaction timestamp. This makes it easy to track the movement of DCC and understand how the ecosystem is being used. The block explorer is also valuable in its ability to provide detailed information about the nodes in the network. Users can view the current number of nodes, their geographical distribution, and information about each node, such as its uptime and the number of blocks it has mined. This information is essential for the DecentralChain ecosystem, as it allows users to view the distribution of the network and understand the ecosystem's health. In addition to tracking transactions and nodes, the block explorer also offers users a detailed view of the smart contract deployment on the blockchain. This is particularly useful for developers and businesses building on the DecentralChain blockchain, as it enables them to view and analyze deployed smart contracts, making it easier to identify bugs or potential vulnerabilities in the contract code. Furthermore, the block explorer plays a vital role in ensuring the security of the DecentralChain ecosystem. By providing detailed information about transactions and nodes, it makes it easier for users to identify suspicious activity or potential security threats. The block explorer can also be used to track the movement of coins that have been stolen or lost, making it easier to recover them. ### Inter-Chain Gateway Protocol The DecentralChain Inter-Chain Gateway is a blockchain mechanism designed to enable secure communication and interoperability between different blockchain networks. This is achieved by creating a decentralized network of nodes that utilize smart contract technology to validate and process transactions between different blockchains. One major use case of the gateway is the ability to transfer assets between different blockchain networks. For example, if you hold Bitcoin but want to use it on another blockchain network, such as DecentralChain, the gateway can allow you to transfer your Bitcoin to the DecentralChain network, where it is converted into a form that is compatible with the DecentralChain blockchain. In addition, the gateway facilitates the sharing of information between different blockchain networks. By creating a decentralized oracle network, smart contracts on different blockchain networks can access and utilize external data, enabling the creation of decentralized applications that use data from multiple sources and blockchain networks. To ensure the network's security, the gateway uses smart contract technology with predefined rules and conditions that are automatically executed when specific conditions are met. These conditions include input validation and access controls to ensure that only authorized parties can access and utilize the network's information. ### Proof of Incentivized Sustainability Protocol As society becomes increasingly aware of the impact of climate change, businesses and individuals are looking for ways to reduce their carbon footprint. In the realm of blockchain technology, the high energy consumption and resulting carbon emissions of Bitcoin transactions are particularly problematic. However, the DecentralChain blockchain presents a solution to this problem through the use of its proof of incentivized sustainability protocol. The traditional Bitcoin blockchain consumes a significant amount of energy for each transaction, releasing large amounts of carbon emissions into the atmosphere. In contrast, the DecentralChain blockchain utilizes a proof of stake protocol which is more energy efficient, resulting in significantly lower carbon emissions per transaction. The DecentralChain blockchain generates carbon credits through the proof of incentivized sustainability protocol. Every Bitcoin transaction on the DecentralChain blockchain creates new carbon credits, which can be sold or used to offset the carbon emissions of other activities. DecentralChain shares a percentage of these carbon credits as incentives to node owners who host their nodes on eco-friendly servers. The equation to calculate the carbon emissions of the Bitcoin blockchain is: Carbon Emissions = Electricity used (kWh) x Carbon Intensity (gCO2/kWh) Using this equation, the carbon emissions of the Bitcoin blockchain can be compared to a proof of stake blockchain protocol like DecentralChain. The difference in carbon emissions between the two can then be used to generate carbon credits, creating a new market for businesses and individuals to offset their carbon emissions and invest in a sustainable future. According to a study by the World Bank, carbon credits can yield a return of up to 7.2 percent annually over a 15-year period. This makes them an attractive investment for individuals and companies alike. The DecentralChain blockchain not only provides a more sustainable alternative to traditional Bitcoin transactions but also creates new opportunities for businesses and individuals to invest in a sustainable future. By incentivizing sustainable practices through the proof of incentivized sustainability protocol and the hosting of nodes on eco-friendly servers, DecentralChain is paving the way for a greener, more sustainable future. ### Carbon Sequestration Carbon sequestration, the process of capturing and storing carbon dioxide (CO2) to reduce its concentration in the atmosphere, is a critical strategy in mitigating the effects of climate change. Through the use of blockchain technology, carbon sequestration can be further incentivized, creating a new market for carbon credits. One of the ways to achieve carbon sequestration is by buying property in Costa Rica and tokenizing the sequestered carbon in the form of a digital token that can be traded on a blockchain platform. The Costa Rican government's initiative of National Forest Financing Fund (FONAFIFO) provides a financial incentive for private landowners to reforest and conserve their land, while also allowing them to receive payments for the carbon sequestered on their property in the form of carbon credits. By tokenizing these carbon credits on a blockchain platform, the carbon sequestration process can be further incentivized, creating a new market for carbon credits and a carbon credit-backed crypto-asset. The tokenization of carbon credits on a blockchain platform not only increases transparency and traceability in the carbon market, but it also provides a new way for people to invest in the conservation of natural areas while obtaining the economic benefit of the carbon credits. This creates a win-win situation, in which the carbon sequestration is incentivized, and the conservation of natural areas is supported. The tokenization of carbon credits on a blockchain platform creates a new market for carbon credits and enables the creation of a carbon credit-backed crypto-asset. This approach can increase transparency and traceability in the carbon market, making it easier to track and verify the carbon credits being traded. Moreover, it provides a new way for people to invest in the conservation of natural areas, while also obtaining the economic benefit of the carbon credits. The Costa Rican government's initiative of National Forest Financing Fund (FONAFIFO) has set the base for this process, and with more involvement of the private sector, decentralized finance, and blockchain technology, this approach can be a step towards a sustainable future where everyone can participate in the conservation and mitigation of climate change. ### Native Swap DecentralChain is an innovative blockchain platform that offers a wide range of features to its users, one of which is the upcoming DecentralChain native swap. A swap is a way for users to exchange one cryptocurrency for another, without the need for a centralized intermediary. In this essay, we will delve into how the DecentralChain native swap is expected to work, and explain how users will be able to use it to swap their DecentralCoin for other cryptocurrencies. A swap is essentially a smart contract that facilitates the exchange of one cryptocurrency for another. When a user initiates a swap, their cryptocurrency is locked into the smart contract, and they receive the equivalent amount of the other cryptocurrency in return. The smart contract then releases the locked up cryptocurrency to the other user. This process happens on-chain, meaning that the swap is settled on the blockchain, and the transaction is recorded on the blockchain's ledger. The DecentralChain native swap is expected to be powered by an Automated Market Maker (AMM) algorithm. This algorithm will calculate the price of the coin based on the token supply and the liquidity in the swap. The price will be calculated using the constant product formula. A swap platform can be thought of as a liquidity pool where users can deposit their tokens, and then use those tokens to swap for other tokens on the platform. As more users deposit tokens into the pool, the pool's liquidity increases, making it more attractive for users to swap their tokens on the platform. The DecentralChain native swap is expected to offer users a secure, efficient, and decentralized way to swap their cryptocurrencies. By eliminating the need for centralized intermediaries, users will be able to exchange their cryptocurrencies without relying on third parties, which can be slow, expensive, and risky. With the upcoming launch of the DecentralChain native swap, users will be able to experience the future of crypto swapping firsthand. ### CR Coin CR Coin is a social currency proposed for Costa Rica, designed to provide a secure, efficient and environmentally-friendly medium of exchange for its citizens. The currency is built on the DecentralChain blockchain, a specialized platform for social currencies that ensures maximum security and scalability. It also incorporates carbon negative technology, which aims to minimize the environmental impact of blockchain-based transactions. By introducing CR Coin, Costa Rica's economy can enjoy the advantages of blockchain technology, such as transparency, low transaction costs, and secure transactions. Currently, cash, bank transfers and online payment systems are the most commonly used methods for payments in Costa Rica, but these traditional forms of money and payment systems have limitations and vulnerabilities, including fraud and high costs. The launch of CR Coin is planned to involve a comprehensive marketing strategy, the establishment of a network of merchants and exchanges that accept CR Coin, and measures to ensure the security, stability and reliability of the currency. It is hoped that the introduction of CR Coin will not only provide a new medium of exchange for citizens but also create new opportunities for businesses, entrepreneurs and investors. CR Coin aims to revolutionize the way payments are made in Costa Rica, promoting sustainable development and environmental conservation with the potential to contribute to the country's goal of becoming a carbon-neutral economy that could have significant benefits for Costa Rica and its citizens. Moreover, the education and awareness initiatives and partnerships with schools and non-profit organizations planned by CR Coin will help raise awareness about the importance of preserving the environment and promoting sustainable practices. By combining technology, community engagement and education, CR Coin aims to be a driving force for sustainable development and environmental conservation in Costa Rica. --- # Account Source: https://decentralchain.io/docs/decentralchain/account DecentralChain uses an account-based model: - Each [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) is created on behalf of a certain account. - All the [tokens](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) belong to certain accounts. - All the data is associated with accounts. For details, see the [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage) article. ## Account Keys Unlike centralized applications, users do not have usernames and passwords on the blockchain. User identification and validation of their actions are performed using a cryptographically bound key pair: - The private key is used to sign transactions or orders. - The public key allows the verification of the digital signature. Each transaction contains the public key of the sender's account. The sender generates a digital signature of the transaction using the account's private key. The signature and the sender's public key are used to verify the authenticity of the transaction's data and to check that the signature of the transaction matches the public key. ![](https://decentralchain.io/docs/03_Account-Keys.png) DecentralChain uses an asymmetric cryptographic system based on the elliptic curve Curve25519-ED25519 with X25519 keys. The guideline for generating keys and signatures is given in the [cryptographic practical details](https://decentralchain.io/docs/decentralchain/protocol#cryptographic-practical-details) article. The private and public keys are 32 byte arrays. In UIs, the keys are displayed as base58 encoded strings. Base58-encoded keys can be of different lengths, the maximum length is 44 characters. Example private key in base58: ```none 6yCStrsBs4VgTmYcSgF37pmQhCo6t9LZk5bQqUyUNSAs ``` Example public key in base58: ```none 5cqzmxsmFPBHm4tb7D8DMA7s5eutLXTDnnNMQKy2AYxh ``` ## Secret (Seed) Phrase The private key can be generated from some random seed phrase using hashing functions. The public key is obtained from the private key using an elliptic curve multiplication. The account [address](https://decentralchain.io/docs/decentralchain/account#address) is obtained from the public key. All these transformations are unidirectional. The opposite direction is almost impossible in terms of the required computations. ![](https://decentralchain.io/docs/04_Secret-(Seed)-Phrase.png) The secret phrase (a.k.a. seed phrase, backup phrase) can be any combination of symbols, words, or bytes. DecentralChain wallet apps typically use a random set of 15 English words out of 2048 words available. Using such a phrase is secure since the probability of generating two identical seed phrases is frac{1}{2048^{15}}, so brute-force will take millions of years on an average CPU. The point of using a secret phrase (rather than a private key) is to simplify user experience: the secret phrase is much easier to write down or remember. Example of a secret phrase: ```none body key praise enter toss road cup result shrimp bus blame typical sphere pottery claim ``` Security Information: - The secret phrase or the private key derived from it provide complete control over the account, including the ability to dispose of funds. Do not give your secret phrase or private key to anyone, and do not publish or send them. - The secret phrase cannot be changed: another secret phrase (even one that differs by a single character) will generate a different key pair, and therefore a different account. - If you lose your secret phrase or private key, you will no longer be able to access your account ever again. We strongly encourage you to [backup of your secret phrase](https://decentralchain.io/docs/decentralchain/account#backup-seed-phrase). - If the secret phrase is compromised (you have accidentally sent it to someone or suspect that it was taken by fraudsters), immediately create a new account and transfer all the assets to it. For ways to generate account keys, see the [creating an account](https://decentralchain.io/docs/decentralchain/account#creating-an-account) article. ## Creating an Account To create an account means to generate an [account key pair](https://decentralchain.io/docs/decentralchain/account#account-keys) and [address](https://decentralchain.io/docs/decentralchain/account#address) based on a [secret (seed) phrase](https://decentralchain.io/docs/decentralchain/account#secret-seed-phrase). You can use [Decentral.Exchange](https://decentral.exchange/) online to create an account. - On the main screen click Create Account then in the Create Password box type in the password, type it again in the Confirm Password box, accept the Terms and Conditions as well as the Privacy Policy and click Continue. - On the next screen select Create Account and then choose the avatar you like the most for your account and click Continue. - After that, select the name you want the account to have on that particular device and click Continue. - At this point you will be forwarded to your wallet page. You must do a [backup of your seed phrase](https://decentralchain.io/docs/decentralchain/account#backup-seed-phrase). ## Backup Seed Phrase - Open [Decentral.Exchange](https://decentral.exchange/) main screen and make sure you are logged into your account. Click on the account avatar and navigate to Settings > Security. - Click Show in the Backup Phrase box. - Write down the phrase and store it in a secure location. Do not store the backup phrase unencrypted on any electronic device. We strongly recommend backing up the seed phrase, since this is the only way to restore access to your account in case of loss or theft of the device. ## Log in to Account - Open [Decentral.Exchange](https://decentral.exchange/) main screen and click Create Account then in the Create Password box type in the password, type it again in the Confirm Password box, accept the Terms and Conditions as well as the Privacy Policy and click Continue. - On the next screen select Import Accounts, then choose the Seed or Key option. - After that type in the seed you backed up in the past and click Continue, then select the name you want the account to have on that particular device and click Continue. - At this point you will be forwarded to your wallet page. ## Forgot Password - Open [Decentral.Exchange](https://decentral.exchange/) main screen and click Forgot Password then select the Reset All option. - On the next screen, in the Create Password box type in the password, type it again in the Confirm Password box, accept the Terms and Conditions as well as the Privacy Policy and click Continue. - When this is done, select Import Accounts, then choose the Seed or Key option. - After that type in the seed you backed up in the past and click Continue, then select the name you want the account to have on that particular device and click Continue. - At this point you will be forwarded to your wallet page. ## Address Address is an [account](https://decentralchain.io/docs/decentralchain/account#account) attribute derived from the [public key](https://decentralchain.io/docs/decentralchain/account#account-keys). The address also contains the [chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) that identifies the blockchain network, therefore the address on the Mainnet cannot be used on the Testnet and vice versa. The address is a 26 byte array (see the [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format)). In UIs the address is displayed as a base58 encoded string. ```none 3PDfnPknnYrg2k2HMvkNLDb3Y1tDTtEnp9X ``` Normally, the address starting with 3P refers to the Mainnet, and the address starting with 3M or 3N refers to Testnet or Stagenet. The address is used to obtain information about the account: - [Token balances](https://decentralchain.io/docs/decentralchain/account#account-balance), - Entries of [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage), - [Aliases](https://decentralchain.io/docs/decentralchain/account#alias), - [Assigned script](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), etc. The address is indicated: - In [transfer](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction), [mass transfer](https://decentralchain.io/docs/decentralchain/transaction#mass-transfer-transaction) and [lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction) to identify a recipient; - In [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) to identify an invoked dApp. ## Get Personal Address - Open [Decentral.Exchange](https://decentral.exchange/) main screen and make sure you are logged into your account. Click on the account avatar and navigate to Address. - Copy the address and use it, or you can also use the generated QR code. ## Alias Alias is a short, easy to remember, name of the [address](https://decentralchain.io/docs/decentralchain/account#address). The alias is unique on the blockchain. One address can have several aliases. The alias can be used instead of the address: - In [transfer](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction), [mass transfer](https://decentralchain.io/docs/decentralchain/transaction#mass-transfer-transaction) and [lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction) to identify a recipient; as well as in [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) to identify an invoked dApp. - To find an account in DecentralChain Explorer. The alias cannot be deleted. ### Alias Requirements The length of an alias can be from 4 to 30 bytes (1 character can take up to 4 bytes). The following characters are allowed: - lowercase Latin letters - numbers - dot - underscore - hyphen - @ ### Create Alias You can use [Decentral.Exchange](https://decentral.exchange/) online to create an alias. - Make sure you are logged into your account. On the main screen click on the account avatar and navigate to Aliases. - On the next screen select Create New and then type in the name of the alias and click Create New again to complete the process. ### View Aliases The list of account aliases, as well as other blockchain data, is public and can be read by anyone. For example, you can see aliases in DecentralChain Explorer. To do this, find an account by its [address](https://decentralchain.io/docs/decentralchain/account#address) and switch to the Aliases tab. Using Node REST API, you can obtain a list of aliases by address using the GET/alias/by-address/{address} method and an address by alias using the GET /alias/by-alias/{alias} method. ### Binary Format See the [alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) article. ## Account Balance Account balance is the amount of a [token (asset)](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) that belongs to the [account](https://decentralchain.io/docs/decentralchain/account#account). One account can store different tokens in different amounts. For example, an account can have 50 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) and USD-N at the same time. The amount of the Y token on the account is called the account balance in Y token. If there is no Y token on the account, it is said that the account balance in Y token is equal to zero. ### Account Balance in DecentralCoin There are four types of balances in DecentralChain: - regular - available - effective - generating The regular balance is the amount of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) that belongs directly to the account. Thе other types of balances are determined counting [leased](https://decentralchain.io/docs/decentralchain/node#leased-proof-of-stake) DecentralCoins. Let us introduce the following notation: ```none R is the regular balance, Lo is the amount of DecentralCoins which the account leased to other accounts, Li is the amount of DecentralCoins which are leased to the account by other accounts. ``` Then: ```none Available balance = R – Lo Effective balance = R – Lo + Li Generating balance is the minimum value of the effective balance during the last 1000 blocks. ``` The generating balance of a [node](https://decentralchain.io/docs/decentralchain/node#node) account affects the ability to participate in block generation. To generate blocks, you need a generating balance of at least 10000 DecentralCoins. The larger the generating balance, the greater the chance to add the next block is. ### View Account Balance The balances of any account, as well as other blockchain data, are public and can be read by anyone. For example, you can see the list of tokens and their amount on the account in DecentralChain Explorer. To do this, find an account by its address or alias. Balances in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) are displayed right under the address, balances in other assets are at the Assets tab, and [non-fungible tokens (NFT)](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token) are at the Non-fungible tokens tab. ![](https://decentralchain.io/docs/05_View-Account-Balance.png) ### Top up Balance You can buy DecentralCoin tokens at [Decentral.Exchange](https://decentral.exchange/). ## Account Data Storage Account data storage is a key-value storage associated with an [account](https://decentralchain.io/docs/decentralchain/account#account). The key of each entry is a unique string. The value is the data being stored, it’s store using one of the types: - String - Boolean - Integral - Array of bytes The size of an account data storage is unlimited. For key and value size limitations, see the [data transaction](https://decentralchain.io/docs/decentralchain/transaction#data-transaction) article. ### View Account Data Data storage of any account, as well as other blockchain data, are public and can be read by anyone. For example, you can see data entries in DecentralChain Explorer. To do this, find an account by its [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) and switch to the Data tab. ![](https://decentralchain.io/docs/06_View-Account-Data.png) ### Add, Modify, Delete Entries The account owner can add, modify or delete entries of the account data storage via a [data transaction](https://decentralchain.io/docs/decentralchain/transaction#data-transaction). A [dApp script](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account) can add, modify or delete entries in the dApp's data storage as a result of an [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) transaction via script actions: - [BinaryEntry](https://decentralchain.io/docs/ride/structures#binaryentry) - [BooleanEntry](https://decentralchain.io/docs/ride/structures#booleanentry) - [IntegerEntry](https://decentralchain.io/docs/ride/structures#integerentry) - [StringEntry](https://decentralchain.io/docs/ride/structures#stringentry) - [DeleteEntry](https://decentralchain.io/docs/ride/structures#deleteentry) ## dApp and Smart Account An account with a script assigned to it becomes a dApp or smart account. dApp is the account with the [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script) assigned. dApp is an application whose functions can be called from other accounts via an [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction). Callable functions can accept payments to the dApp and also perform actions applied to the blockchain: - Add, modify or delete entries of the dApp account data storage. - Transfer tokens from the dApp balance. - Issue, reissue, burn tokens on behalf of the dApp, sponsorship setup. Beyond that, a dApp script can comprise the verifier function that allows or denies transactions and orders that are sent on behalf of the dApp account depending on the specified conditions. The verifier function replaces the default verification that is used to verify the sender's signature and allows you to set more complex rules, such as multisignature. Using dApps, you can implement various blockchain-empowered applications: gaming and gambling, DeFi, digital identity, supply chains, and many others. A smart account is an account with the [account script](https://decentralchain.io/docs/ride/script-types#account-script) assigned. The account script is similar to a verifier function of a dApp script. Please note: - To assign a script to an account, you have to send a [set script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-script-transaction) on behalf of the account. - You can also change or delete the script via the set script transaction, unless the script itself prohibits it. - The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for any transaction sent from a dApp or smart account is increased by 0.004 DecentralCoins if the complexity of sender's account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations). --- # Token (Asset) Source: https://decentralchain.io/docs/decentralchain/token-asset Token is a digital asset on the blockchain. A token can be used: - As a cryptocurrency to pay for goods and services within a project, as well as for crowdfunding; - As an object or resource in games etc. A token can represent a physical or an intangible object. The words “token” and “asset” are used interchangeably in the DecentralChain ecosystem. DecentralCoin is the native token on the DecentralChain blockchain. [More about DecentralCoin](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). All other tokens are custom tokens issued on behalf of some account. Any account that has enough DecentralCoins to pay the fee can issue its own token. The new token is immediately available: - For transfers between accounts, - For trading on [Decentral.Exchange](https://decentral.exchange/) (except for [NFTs](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token); [smart assets](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset) trading is temporarily unavailable), - For payments attached to dApp [script invocation](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction). ## Token Issue You can use [Decentral.Exchange](https://decentral.exchange/) online to create an asset. - On the main screen make sure you are logged into your account, then click on Create Token. - On the next screen specify the token parameters: - Name: The name of the created asset can not be shorter than 4 characters. - Description: A short description where you can include website links that can be particularly useful. - Quantity: Define the total supply of your asset. The total supply can either be fixed at the issuance or increased later by making the asset re-issuable. - Reissuable: Defines if the asset total supply can be increased later. If set to reissuable, the issuer can increase the supply at any time (If reissuable is selected when the asset is created, it can be changed to not reissuable at a later stage). - Decimals: Specify how many decimals your asset will have. For example, if you specify 8 decimals, as in Bitcoin, your asset can be divided down to 0.00000001. - [Smart asset](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset): A smart asset is an asset with an attached script that places conditions on every transaction made for the asset in question. - Script (for issuing a smart asset). - Before creating a new asset, carefully read the creation conditions. If necessary, change the name of the asset according to the conditions, then select the I understand... checkbox and click Generate. - On the next screen double-check the entered data and if everything is correct click Send to finish the creation or click Go Back to make corrections.. The transaction fee is 1 DecentralCoin for a regular token or 0.001 DecentralCoins for a [non-fungible token (NFT)](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token). Moreover, the token can be issued by the [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script) as a result of the [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) when the callable function result contains the [Issue](https://decentralchain.io/docs/ride/structures#issue) action. The minimum fee for invoke script transaction is increased by 1 DecentralCoin for each non-NFT token issued. ## Token ID Token ID is a byte array calculated as follows: - If the token is issued by [issue transaction](https://decentralchain.io/docs/decentralchain/transaction#issue-transaction), the token ID is the same as the transaction ID. - If the token is issued by [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) when the callable function of [dApp script](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account) performed the [Issue](https://decentralchain.io/docs/ride/structures#issue) action, the token ID is calculated as the BLAKE2b-256 hash of the byte array containing transaction ID and the fields of the Issue structure. In the Node REST API, the token identifier is encoded in base58. For example: ```none "assetId": "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS" ``` The [DecentralCoin](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) token has no identifier. The Node REST API uses null for DecentralCoin. ## Token Operations - Transfer to another account Can be done via a [transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction) or a [mass transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#mass-transfer-transaction). A [dApp script](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account) can transfer the token via a [ScriptTransfer](https://decentralchain.io/docs/ride/structures#scripttransfer) script action as a result of an [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction). - Exchange (trade deal) Three accounts can participate in the exchange: one user creates an [order](https://decentralchain.io/docs/decentralchain/order#order) to buy a token, the other creates an order to sell a token. The matcher combines buy and sell orders with suitable parameters and creates an [exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction). - Burning Decreases the amount of token on the account and thereby the total amount of the token on the blockchain. Any token owner can burn it, not only the issuer. It is impossible to burn [DecentralCoin](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). Can be done via a [burn transaction](https://decentralchain.io/docs/decentralchain/transaction#burn-transaction). A dApp script can burn the token via a [Burn](https://decentralchain.io/docs/ride/structures#burn) script action as a result of the Invoke script transaction. - Payment to [dApp](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account) An [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) can contain up to two payments to the dApp. Payment amount and token are available to the callable function. ### Operations Available Only to Issuer The following token operations can only be performed by the account that issued the token: - Sponsorship setup The token issuer can enable sponsorship which allows all users to pay fees in this token (instead of DecentralCoins) for invoke script transactions and transfer transactions. [More about sponsorship](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees). Enabling or disabling sponsorship can be done via a [sponsor fee transaction](https://decentralchain.io/docs/decentralchain/transaction#sponsor-fee-transaction). A dApp script can set up sponsorship using a [SponsorFee](https://decentralchain.io/docs/ride/structures#sponsorfee) as a result of the invoke script transaction. - Reissue Increases the amount of token on the blockchain. The reissuable field of token determines whether the token can be reissued. Can be done via a [reissue transaction](https://decentralchain.io/docs/decentralchain/transaction#reissue-transaction). A dApp script can reissue the token via a [Reissue](https://decentralchain.io/docs/ride/structures#reissue) script action as a result of the invoke script transaction. - Replacing the asset script Can be done via a [set asset script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-asset-script-transaction). If the token is not a smart asset, that is, the script was not attached when the token was issued, then it is impossible to attach the script later. - Modifying the token name and / or description Can be done via an [update asset info transaction](https://decentralchain.io/docs/decentralchain/transaction#update-asset-info-transaction). ## Token Types ### Non-Fungible Token Non-fungible token or NFT is a special type of a [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) that is issued with the following parameters: - "quantity": 1 - "decimals": 0 - "reissuable": false NFT is a singular entity that has a unique ID. This contrasts with a regular token, two coins of which (for example, two WBTC) cannot be distinguished from each other. NFTs can be used as in-game items, collectibles, certificates, or unique coupons. #### Issue of NFT NFT can be issued in the same ways as a regular token, see [token issue](https://decentralchain.io/docs/decentralchain/token-asset#token-issue). The minimum fee for an NFT issue is 0.001 DecentralCoins, 1000 times less than for a regular token. ### Smart Asset Smart asset is a [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) that has an [asset script](https://decentralchain.io/docs/ride/script-types#asset-script) assigned to it. By default, tokens on the DecentralChain blockchain are not smart contracts, and any transactions with them are allowed. The script endows a token with functionality that sets the rules for its circulation. Each transaction involving a smart asset is automatically checked against the conditions specified in the script. If the asset's script allows the transaction, it will be executed; if the script denies the transaction, it is either not put onto the blockchain at all or saved as failed (for details, see the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation) article). Using smart assets, you can implement various financial instruments on the blockchain (options, interval trading, taxation), game mechanics (allowing transactions only between characters with certain properties). Please note: - If a token is issued without a script, then the script cannot be added later. - The script cannot be removed, so it is impossible to turn a smart asset into a regular one. - The asset script can be changed using the [set asset script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-asset-script-transaction), unless prohibited by the asset script itself (as well as by the [dApp or account script](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account) assigned to the issuer account). - The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for transaction is increased by 0.004 DecentralCoins for each smart asset involved, except for: - [Invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction), - Smart assets used as matcher fee in [exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction). ### Tokens of Other Blockchains A token issued on another blockchain cannot be used directly on the DecentralChain blockchain. A new token representing the original one can be issued on the DecentralChain blockchain, and a gateway that pegs the two tokens 1:1 can be deployed. ## DecentralCoin DecentralCoin is the native [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) of the DecentralChain blockchain. [Block generators](https://decentralchain.io/docs/decentralchain/node#generating-node) receive [transaction fees](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) and [block rewards](https://decentralchain.io/docs/decentralchain/node#block-reward) in DecentralCoins, which encourages generators to maintain and develop the blockchain network infrastructure. The more DecentralCoins the generator holds (by ownership or lease), the greater its chance to add the next block is. ### DecentralCoin Parameters DecentralCoins are present on the blockchain since inception, there is no issue transaction for it, therefore the DecentralCoin token does not have an ID. The REST API uses null for DecentralCoins. The number of decimal places (decimals) for DecentralCoins is 8. The atomic unit called Decentralite is frac{1}{100,000,000} DecentralCoins. ### Leasing The owner of DecentralCoins can lease them via a [lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction). DecentralCoins received on lease are included in the [generating balance](https://decentralchain.io/docs/decentralchain/account#account-balance). Block generators send back different percentages as rewards to lessors. A lessor can cancel the lease at any time via a [lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction). [More about leasing](https://decentralchain.io/docs/decentralchain/node#leased-proof-of-stake). ### How to Get DecentralCoin You can buy DecentralCoins tokens at [Decentral.Exchange](https://decentral.exchange/), or at one of the centralized exchanges. In addition, cryptocurrency gateways can be used to transfer external cryptocurrencies such as Bitcoin, Ethereum etc. from the external blockchain to the DecentralChain blockchain and vice versa. The gateway provides the user with the address on the external blockchain. After receiving a confirmation of transfer to this external address, the gateway transfers the corresponding asset (minus the fee) to the user's DecentralChain address. ## Token Custom Parameters Below is an example of JSON representation returned by the GET /assets/details/{assetId} method of Node REST API: ```none { "assetId": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p", "issueHeight": 1806810, "issueTimestamp": 1574429393962, "issuer": "3PC9BfRwJWWiw9AREE2B3eWzCks3CYtg4yo", "issuerPublicKey": "BRnVwSVctnV8pge5vRpsJdWnkjWEJspFb6QvrmZvu3Ht", "name": "USD-N", "description": "Neutrino USD", "decimals": 6, "reissuable": false, "quantity": 999999999471258900, "scripted": false, "minSponsoredAssetFee": 7420, "originTransactionId": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p" } ``` **Token Custom Parameters** | Field | Description | | --- | --- | | assetId | Token ID: base58 encoded byte array. The token ID is calculated as a hash of the token parameters upon issue. See also the [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id) article. | | issueHeight | Blockchain height (the sequence number of the block) at which the token is issued. | | issueTimestamp | Token issue timestamp: Unix time in milliseconds. | | issuer | [address](https://decentralchain.io/docs/decentralchain/account#address) of issuer account: base58 encoded byte array. | | issuerPublicKey | [Public key](https://decentralchain.io/docs/decentralchain/account#account-keys) of issuer account: base58 encoded byte array. | | name | Token name. From 4 to 16 bytes (1 character can take up to 4 bytes). | | description | Token description. From 0 to 1000 bytes. | | decimals | Number of decimal places, from 0 to 8. | | reissuable | Reissue availability flag. | | quantity | Total supply of token on the blockchain specified in [atomic units](https://decentralchain.io/docs/decentralchain/token-asset#atomic-unit). From 1 to 9,223,372,036,854,775,807. Total supply can change as a result of reissue or burning, see [token operations](https://decentralchain.io/docs/decentralchain/token-asset#token-operations) below. | | scripted | There being a script: true for smart asset, false for regular token. [More about smart assets](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset). | | minSponsoredAssetFee | For sponsored asset only: an amount of asset that is equivalent to 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). [More about sponsorship](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees). | | originTransactionId | ID of the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) that issued the token: base58 encoded byte array. | | scriptDetails | For [smart asset](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset) only: [asset script](https://decentralchain.io/docs/ride/script-types#asset-script) and its attributes. | ### Atomic Unit The amount of token is displayed differently in UIs and in the [JSON representation](https://decentralchain.io/docs/decentralchain/transaction#json-representation) used by the Node REST API. In API requests and responses, amount values are integers indicated in atomic units to avoid precision issues in floating-point calculations. An atomic unit is the minimum fraction (“cent”) of a token, it is equal to 10^{-decimals}. The amount of token in JSON is the real quantity multiplied by 10^{decimals}. For USD-N in the example above: - decimals = 6, - atomic unit is frac{1}{1,000,000} USD-N. - "quantity": 999999999471258900 corresponds to 999,999,999,471.258900 USD-N in UIs, "minSponsoredAssetFee": 7420 corresponds to 0.007420 USD-N. --- # Transaction Source: https://decentralchain.io/docs/decentralchain/transaction ## Transaction Issue ### How to Sign and Send Transactions - In [Decentral.Exchange](https://decentral.exchange/) you can create some types of transactions such as transfer, issue/reissue/burn, sponsor fee transaction, set asset script, create alias. - Via Node REST API: - The POST /transactions/broadcast method sends a signed transaction to a node; - The POST /transactions/sign method generates transaction signature (but this method is only available to the node owner). ### Transaction Sender and Signature Each transaction contains the public key of the sender’s account, on behalf of which the action is performed on the blockchain. [Smart accounts and dApps](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account) can set their own rules for outgoing transactions verification. Transactions that are sent from an ordinary account (without script) must contain the sender's digital signature. The sender generates a signature using the account's private key. Along with the signature, the transaction contains the sender's public key, so the node (and anyone) can verify the integrity of the transaction data and the authenticity of the signature, that is, make sure that the signature of the transaction matches the public key. ### After Transaction is Sent Upon receiving a transaction, the node validates its signature, checks the sender's balance, and so on, see the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation) article for details. If the transaction is valid, the node puts the transaction to the UTX pool, which is a list of transactions awaiting to be added, and also broadcasts the transaction to other nodes of the blockchain network. Due to block size limitation (1 MB) the transaction may not get to the block immediately. First of all, nodes add the most “profitable” transactions with the highest fee per byte. After being added to a block, the transaction changes the blockchain state: account balances, records in the account data storage, and so on. The transaction may never be added to a block if it becomes invalid while waiting in the UTX pool. For example, the transaction has expired (the timestamp is more than 2 hours behind current time) or another transaction has changed the blockchain state and now the sender's balance is insufficient to execute the transaction or the account or asset script denies the transaction. ## Transaction Proofs ### Verification by Script If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), then the transaction is verified by the script assigned to the account instead of signature verification. The script allows or denies the transaction depending on whether it meets the specified conditions. In particular, the script can run various verifications of the proofs. A common example is a smart account with a multisignature where three co-owner users store shared funds. ## Transaction Fees Transaction fee is a fee that an [account](https://decentralchain.io/docs/decentralchain/account#account) owner pays to send a [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction). A transaction sender can specify any amount of fee but not less than the minimum amount. The larger the fee is, the quicker the transaction will be added to the new [block](https://decentralchain.io/docs/decentralchain/block#block). For [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) and [transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction), a sender can specify a transaction fee nominated in a sponsored asset instead of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin), see the section [fee in sponsored asset](https://decentralchain.io/docs/decentralchain/transaction#fee-in-sponsored-asset) below. ### Regular Fees #### Minimum Fee The minimum fees in DecentralCoins for each type of transaction are listed below. - If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. If the order sender in [exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction) is a dApp or smart account, this does nor affect the minimum fee. - The minimum fee is increased by 0.004 DecentralCoins for each smart asset involved, except for: - [Invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction), - [Smart assets](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset) used as matcher fees in exchange transactions. **Example 1** - The minimum fee for a transfer transaction: - No smart account or smart assets: 0.001 DecentralCoins. - Transfer from smart account*: 0.001 + 0.004 = 0.005 DecentralCoins. - Transfer of smart asset: 0.001 + 0.004 = 0.005 DecentralCoins. - Transfer of smart asset sent from smart account*: 0.001 + 0.004 + 0.004 = 0.009 DecentralCoins. If the account script complexity is higher than the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations). **Example 2** The minimum fee for an Invoke Script transaction: - No smart account, no assets issued: 0.005 DecentralCoins. - dApp script invocation is sent from a smart account*: 0.005 + 0.004 = 0.009 DecentralCoins. - dApp script invocation issues an asset that is not [non-fungible tokens](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token): 0.005 + 1 = 1.005 DecentralCoins. - dApp script invocation is sent from smart account*, and 10 assets that are not non-fungible tokens are issued: 0.005 + 0.004 + 10 × 1 = 10.009 DecentralCoins. If the account script complexity is higher than the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations). **Minimum Fees** | Transaction type | Transaction type ID | Minimum transaction fee in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) | | --- | --- | --- | | [Burn transaction](https://decentralchain.io/docs/decentralchain/transaction#burn-transaction) | 6 | 0.001 | | [Create alias transaction](https://decentralchain.io/docs/decentralchain/transaction#create-alias-transaction) | 10 | 0.001 | | [data transaction](https://decentralchain.io/docs/decentralchain/transaction#data-transaction) | 12 | 0.001 per kilobyte. The size is rounded up to an integer number of kilobytes. | | [Exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction) | 7 | 0.003 | | [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) | 16 | 0.005 + K. K is the number of assets issued as a result of dApp script invocation that are not non-fungible tokens. | | [Issue transaction](https://decentralchain.io/docs/decentralchain/transaction#issue-transaction) | 3 | 1 for reqular token. 0.001 for [non-fungible token](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token). | | [Lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction) | 9 | 0.001 | | [Lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction) | 8 | 0.001 | | [Mass transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#mass-transfer-transaction) | 11 | 0.001 + 0.0005 × N. N is the number of transfers inside of the transaction. The value is rounded up to the three decimals. | | [Reissue transaction](https://decentralchain.io/docs/decentralchain/transaction#reissue-transaction) | 5 | 0.001 | | [Set asset script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-asset-script-transaction) | 15 | 1 | | [set script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-script-transaction) | 13 | 0.01 | | [Sponsor fee transaction](https://decentralchain.io/docs/decentralchain/transaction#sponsor-fee-transaction) | 14 | 0.001 | | [Transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction) | 4 | 0.001 | | [Update asset info transaction](https://decentralchain.io/docs/decentralchain/transaction#update-asset-info-transaction) | 17 | 0.001 | #### Fee for Failed Transactions [Invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) and [exchange transactions](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction) can be saved on the blockchain even if the result of a dApp script or asset script execution failed. In this case, the sender is charged a fee. For an exchange transaction, the matcher is charged the transaction fee but the order senders are not charged the matcher fee. [More about transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation). #### Fee in Sponsored Asset An issuer of an asset can set up sponsorship — so that any user can specify a transaction fee in this asset for [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) and [transfer transactions](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction). To activate sponsorship, the issuer puts a [sponsor fee transaction](https://decentralchain.io/docs/decentralchain/transaction#sponsor-fee-transaction) that specifies an amount of asset that is equivalent to the minimum fee of 0.001 DecentralCoins. For example, if minSponsoredAssetFee: 5, then the fee in this asset for an invoke script transaction equals 5 * frac{0.005}{0.001} = 25. ### Sponsored Fees Users of DecentralChain-based apps should pay a fee for each transaction. This is the entry threshold for new users. Sometimes users don't know anything about [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) or don't understand how to get DecentralCoins or don't want to spend money. Sponsorship enables launching apps that do not require DecentralCoins from users. #### Sponsored Asset An account that issued an asset can enable sponsorship, that is, allow all users to pay a fee in this asset for [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) and [transfer transactions](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction). The sponsor can distribute the sponsored asset among app users. #### How to Enable Sponsorship You can use [Decentral.Exchange](https://decentral.exchange/) online to enable sponsorship. - Make sure you are logged into your account. Find the desired asset in the list, hover cursor over it and in its menu (⋮) click Enable Sponsorship. - Carefully read the Terms and Conditions before proceeding and then in the Amount per transaction box specify the required amount of sponsored asset to be charged to users. Then click Continue. - In the following window double-check the entered data and if everything is correct click Send or click Go Back to make corrections. Activation will be processed with the next block. - After activation you'll be able to change the specified amount without deactivation. To do so, find your asset in the list, hover cursor over it and in its menu (⋮) click Change Sponsorship. The fee for this type of transaction is 0.001 DecentralCoins. #### How to Disable Sponsorship You can use [Decentral.Exchange](https://decentral.exchange/) online to disable sponsorship. - Make sure you are logged into your account. Find the desired asset in the list, hover cursor over it and in its menu (⋮) click Disable Sponsorship. - In the following window click Sign to deactivate the sponsorship. Deactivation will be processed with the next block. #### Restrictions - Only the issuer of the asset can be a sponsor. - Smart assets cannot be sponsored assets. - Sponsorship only works if the sponsor's account balance is greater than 1.005 DecentralCoins. If the account balance becomes less than 1.005 DecentralCoins, the sponsorship is suspended, and if the balance becomes more than 1.005 DecentralCoins the sponsorship is resumed. - The fee in the sponsored asset can only be specified for [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) and [transfer transactions](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction). #### How It Works After [enabling sponsorship](https://decentralchain.io/docs/decentralchain/transaction#how-to-enable-sponsorship), if the requirements described in the [restrictions](https://decentralchain.io/docs/decentralchain/transaction#restrictions) section are met, the sponsorship works as follows: - A user broadcasts a transaction and specifies a fee in the sponsored asset. - The sponsor receives the fee in the sponsored asset from the user's account. - Block generators receive the fee in DecentralCoins from the sponsor's account (in accordance with the [DecentralChain-M5 protocol](https://decentralchain.io/docs/decentralchain/protocol#decentralchain-m5-protocol), the fee is distributed between the current block generator and the next block generator in a ratio of frac{40}{60}. The script on the sponsor's account is not executed and does not affect the sponsorship because the transaction is sent from the user's account. ![](https://decentralchain.io/docs/07_How-It-Works.png) The fee in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) charged to the sponsor is proportional to the fee specified by the transaction sender: ```none feeInDecentralCoins = feeInSponsoredAsset × 0,001 / minSponsoredAssetFee ``` minSponsoredAssetFee is the amount of sponsored asset equivalent to 0.001 DecentralCoins. The sponsor sets this value when enabling sponsorship. For example, if the sponsor sets 3 tokens = 0.001 DecentralCoins, then the minimum fee for [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) is 15 tokens, which corresponds to 0.005 DecentralCoins. Please note: - The user can use the sponsored asset to pay for transactions that are not related to a certain app. - The user can specify any amount of fee, such as the one significantly exceeding the minimum. ## Transaction Representations ### JSON Representation The Node REST API of DecentralChain nodes uses the JSON representation of transactions. You can send transactions to a node and read transactions stored on the blockchain via REST API in JSON. Here is an example of JSON representation: ```none { "senderPublicKey": "BVv1ZuE3gKFa6krwWJQwEmrLYUESuUabNCXgYTmCoBt6", "sender": "3N8S4UtauvDAzpLiaRyDdHn9muexWHhBP4D", "feeAssetId": null, "proofs": [ "22QJfRKX7kUQt4qjdnUqZAnhqukqhnofE27uvP8Q5xnBf8M6PCNtWVGq2ngm6m7Voe7duys59D1yU9jhKrmdXDCe" ], "fee": 100000, "alias": "91f452553298770f", "id": "AD7KmXwoVNc2fXsmaxsHsrnT1tfPF3HsWYtfjFijVsvM", "type": 10, "version": 2, "timestamp": 1548443069053, "height": 466104 } ``` **JSON Representation** | Field | Description | | --- | --- | | senderPublicKey | [Public key](https://decentralchain.io/docs/decentralchain/account#account-keys) of the transaction sender: base58 encoded byte array. | | sender | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender: base58 encoded byte array. | | feeAssetId | ID of the fee token. null means that the fee is in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). The sender can specify the fee for [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) and [transfer transactions](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction) in a sponsored asset, see the [sponsored fee](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees) article for details. | | proofs | Array of [transaction proofs](https://decentralchain.io/docs/decentralchain/transaction#transaction-proofs). Up to 8 proofs, each proof up to 64 bytes base58 encoded. | | fee | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees): an integer value indicated in the minimum fraction (“cent”) of the fee asset. For example, if the fee is 0.001 DecentralCoins, 100000 is indicated in the JSON representation, so far as 1 DecentralCoin = 10^{8} Decentralites. | | id | Transaction ID. For the transaction ID calculation method, see the [cryptographic practical details](https://decentralchain.io/docs/decentralchain/protocol#cryptographic-practical-details) article. | | type | Transaction type. Type IDs are listed in the [transaction type](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) article. | | version | Transaction version. Versions for each type of transaction are listed in [transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-binary-format) descriptions. | | applicationStatus | Status of transaction execution: 1) succeeded: transaction is successful. 2) script_execution_failed: the dApp script or the asset script failed. See the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation) article for details. | | timestamp | Transaction timestamp specified by the sender: Unix time in milliseconds. The transaction cannot be added to the blockchain if the timestamp value is more than 2 hours behind or 1.5 hours ahead of current block timestamp. | | height | The sequence number of the block that contains the transaction. | The sender, id, applicationStatus, and height fields do not need to be filled when sending a transaction, and they are not stored on the blockchain. The node calculates these fields when providing transaction data via the Node REST API. The fields that depend on the type of transaction are listed in the description of each [type of transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction-types). ### Binary Format Transactions are stored on the blockchain in the binary format (byte representation). Node extensions such as gRPC server can work directly with data in binary format. The transaction signature and ID are also formed on the basis of the binary format. The guideline for generating a signature and ID is given in the [cryptographic practical details](https://decentralchain.io/docs/decentralchain/protocol#cryptographic-practical-details) article. Transaction binary format is described in the [transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-binary-format) article. You can get the transaction by ID, or the list of transactions by certain account address, or the list of all transactions in the block: - In DecentralChain Explorer. - Via Node REST API using the following methods: - GET /transactions/info/{id} returns transaction data by transaction ID. - GET /transactions/address/{address}/limit/{limit} returns the list of transactions where the specified address is involved. - GET /blocks/at/{height} returns block data at the specified height including all transactions in the block. ## Transaction Types ### Tokenization **Tokenization** | Transaction type ID | Name | Description | | --- | --- | --- | | 3 | [Issue transaction](https://decentralchain.io/docs/decentralchain/transaction#issue-transaction) | Issues a token. | | 5 | [Reissue transaction](https://decentralchain.io/docs/decentralchain/transaction#reissue-transaction) | Reissues a token. | | 6 | [Burn transaction](https://decentralchain.io/docs/decentralchain/transaction#burn-transaction) | Decreases the amount of token. | | 15 | [Set asset script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-asset-script-transaction) | Modifies the asset script. | | 17 | [Update asset info transaction](https://decentralchain.io/docs/decentralchain/transaction#update-asset-info-transaction) | Changes the token name and description. | #### Issue Transaction Issue transaction creates a new [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset). **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for an issue transaction is 1 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin), in case of issue of a [non-fungible tokens (NFT)](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token) 0.001 DecentralCoins. If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "2M25DqL2W4rGFLCFadgATboS8EPqyWAN3DjH12AH5Kdr", "quantity": 50000, "fee": 100000000, "description": "Script true.", "type": 3, "version": 2, "reissuable": true, "script": "base64:AQa3b8tH", "sender": "3Mz9N7YPfZPWGd4yYaX6H53Gcgrq6ifYiH7", "feeAssetId": null, "chainId": 84, "proofs": [ "4yjVxzrLuXUq5y2QCa2LDn1Fp9P63hPBmqDLGQCqn41EB1uZ1pys79NP81h7FxRBnZSbpNGbz1xjwckHcPAQHmFX" ], "assetId": "7Xpp9PPeZbG4wboJrcbRQdq3SxCJqbeFRUjjKccM1DsD", "decimals": 2, "name": "Smart", "id": "7Xpp9PPeZbG4wboJrcbRQdq3SxCJqbeFRUjjKccM1DsD", "timestamp": 1548653407494, "height": 469677 } ``` **Issue Transaction JSON Representation** | Field | Description | | --- | --- | | name | Token name. From 4 to 16 bytes (1 character can take up to 4 bytes). | | description | Token description. From 0 to 1000 bytes. | | quantity | Token quantity: an integer value specified in the minimum fraction (“cents”), that is, the real quantity multiplied by 10^{decimals}. From 1 to 9,223,372,036,854,775,807. 1 for NFT. | | decimals | Number of decimal places, from 0 to 8. 0 for NFTs. | | reissuable | Reissue availability flag, see the [reissue transaction](https://decentralchain.io/docs/decentralchain/transaction#reissue-transaction) article. False for NFTs. | | script | For the [smart asset](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset): the compiled [Asset script](https://decentralchain.io/docs/ride/script-types#asset-script), up to 8192 bytes, base64 encoded. For the token without a script: null. The token issued without a script cannot be converted to a smart asset. | | chainId | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | assetId | Token ID base58 encoded. The token ID is the same as the Issue transaction ID. | The assetId field does not need to be filled when sending a transaction, and it is not stored on the blockchain. The node calculates these fields when providing transaction data via the REST API. The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [issue transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#issue-transaction-binary-format). **Ride Structure** The [IssueTransaction](https://decentralchain.io/docs/ride/structures#issuetransaction) structure is used for transaction handling in smart contracts. #### Reissue Transaction Reissue transaction increases the amount of the [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) on the blockchain and/or prohibits its reissue. Only the token issuer can send a reissue transaction. The additional amount of token increases the balance of the transaction sender. The reissuable field of the token determines whether the token can be reissued. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a reissue transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). If the token is a smart asset, the minimum fee is increased by 0.004 DecentralCoins. If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "DjYEAb3NsQiB6QdmVAzkwJh7iLgUs3yDLf7oFEeuZjfM", "quantity": 200000, "fee": 100000000, "type": 5, "version": 2, "reissuable": true, "sender": "3PLJciboJqgKsZWLj7k1VariHgre6uu4S2T", "feeAssetId": null, "chainId": 87, "proofs": [ "5mEveeUwBdBqe8naNoV5eAe5vj6fk8U743eHGkhxhs3v9PMsb3agHqpe4EtzpUFdpASJegXyjrGSbynZg557cnSq" ], "assetId": "GA4gB3Lf3AQdF1vBCbqGMTeDrkUxY7L83xskRx6Z7kEH", "id": "27ETigYaHym2Zbdp4x1gnXnZPF1VJCqQpXmhszC35Qac", "timestamp": 1548521785933, "height": 1368623 } ``` **Reissue Transaction JSON Representation** | Field | Description | | --- | --- | | assetId | Token ID base58 encoded. | | quantity | Amount of token to reissue: an integer value specified in the minimum fraction (“cents”) of token. The total quantity of token as a result of the reissue should not exceed 9,223,372,036,854,775,807. | | chainId | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | reissuable | Reissue availability flag. | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [reissue transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#reissue-transaction-binary-format). **Ride Structure** The [ReissueTransaction](https://decentralchain.io/docs/ride/structures#reissuetransaction) structure is used for transaction handling in smart contracts. #### Burn Transaction Burn transaction decreases the amount of token on sender's account and thereby the total amount of the token on the blockchain. Any account that owns a token (not necessarily the token issuer) can send the burn transaction. Burned tokens cannot be restored back to the account. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a burn transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin), in case of burning a smart asset 0.005 DecentralCoins. If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "9GaQj7gktEiiS1TTTjGbVjU9bva3AbCiawZ11qFZenBX", "amount": 9999, "fee": 100000, "type": 6, "version": 2, "sender": "3P9QZNrHbyxXj8P9VrJZmVu2euodNtA11UW", "feeAssetId": null, "chainId": 87, "proofs": [ "61jCivdv3KTuTY6QHgxt4jaGrXcszWg3vb9TmUR26xv7mjWWwjyqs7X5VDUs9c2ksndaPogmdunHDdjWCuG1GGhh" ], "assetId": "FVxhjrxZYTFCa9Bd4JYhRqXTjwKuhYbSAbD2DWhsGidQ", "id": "csr25XQHT1c965Fg7cY2vJ7XHYVsudPYrUbdaFqgaqL", "timestamp": 1548660675277, "height": 1370971 } ``` **Burn Transaction JSON Representation** | Field | Description | | --- | --- | | amount | Amount of token to burn: an integer value specified in the minimum fraction (“cents”) of token. | | assetId | Token ID base58 encoded. | | chainId | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [burn transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#burn-transaction-binary-format). **Ride Structure** The [BurnTransaction](https://decentralchain.io/docs/ride/structures#burntransaction) structure is used for transaction handling in smart contracts. #### Set Asset Script Transaction Set asset script transaction replaces the [asset script](https://decentralchain.io/docs/ride/script-types#asset-script). Only the token issuer can send an asset script transaction. If a token is issued without a script, then no script can be assigned to it. It is also impossible to remove the script and turn the smart asset into a regular one. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a set asset script transaction is 1 [DecentralCoin](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "AwQYJRHZNd9bvF7C13uwnPiLQfTzvDFJe7DTUXxzrGQS", "fee": 100000000, "type": 15, "version": 1, "script": "base64:AQa3b8tH", "sender": "3P67JUW8Djit7hMjKhADmn6CWvKPbRuh2sQ", "feeAssetId": null, "chainId": 87, "proofs": [ "nzYhVKmRmd7BiFDDfrFVnY6Yo98xDGsKrBLWentF7ibe4P9cGWg4RtomHum2NEMBhuyZb5yjThcW7vsCLg7F8NQ" ], "assetId": "7qJUQFxniMQx45wk12UdZwknEW9cDgvfoHuAvwDNVjYv", "id": "FwYSpmVDbWQ2BA5NCBZ9z5GSjY39PSyfNZzBayDiMA88", "timestamp": 1547201038106, "height": 1346345 } ``` **Set Asset Script Transaction JSON Representation** | Field | Description | | --- | --- | | assetId | Token ID base58 encoded. | | chainId | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | script | Compiled asset script, up to 8192 bytes, base64 encoded. | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [set asset script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#set-asset-script-transaction-binary-format). **Ride Structure** The [SetAssetScriptTransaction](https://decentralchain.io/docs/ride/structures#setassetscripttransaction) structure is used for transaction handling in smart contracts. #### Update Asset Info Transaction Update asset info transaction modifies the name and description of the token. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for an update asset info transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin), in case of a smart asset 0.005 DecentralCoins. If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "6a6r9d3r2ccyE9SvuxmdZbfSHXmKPUoExnigvippJLfu", "fee": 100000, "description": "xxxXXXxxx", "type": 17, "version": 1, "applicationStatus": "succeeded", "sender": "3MQdH4MAmM5RNz5TAT43UXXCvMtCa9YgHq9", "feeAssetId": null, "chainId": 83, "proofs": [ "4DfvJL4cVisQaMuMB7ar15EtYZTvTZzAUQQMkq4RA3uTMzziVYLrbNHSL2a1eCqBV3YQb7dddXdjywETXHuu65ij" ], "assetId": "syXBywr2HVY7wxqkaci1jKY73KMpoLh46cp1peJAZNJ", "name": "zzzz", "id": "4DL8K4bRvYb9Qrys9Auq7hSGuLGq8XsUYZqDDBBfVGMf", "timestamp": 1591886337668, "height": 411389 } ``` **Update Asset Info Transaction JSON Representation** | Field | Description | | --- | --- | | name | Token name. From 4 to 16 bytes. | | description | Token description. From 0 to 1000 bytes. | | chainId | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | assetId | Token ID base58 encoded. | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [update asset info transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#update-asset-info-transaction-binary-format). **Ride Structure** The [UpdateAssetInfoTransaction](https://decentralchain.io/docs/ride/structures#updateassetinfotransaction) structure is used for transaction handling in smart contracts. ### Usage **Usage** | Transaction type ID | Name | Description | | --- | --- | --- | | 4 | [Transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction) | Transfers a token to another account. | | 7 | [Exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction) | Exchanges two different tokens between two accounts. Contains two counter orders: a buy order and a sell order. | | 10 | [Create alias transaction](https://decentralchain.io/docs/decentralchain/transaction#create-alias-transaction) | Creates alias for the sender's address. | | 11 | [Mass transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#mass-transfer-transaction) | Transfers a token, up to 100 recipients. | | 12 | [Data transaction](https://decentralchain.io/docs/decentralchain/transaction#data-transaction) | Adds, modifies and deletes data entries in the sender's account data storage. | | 13 | [Set script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-script-transaction) | Assigns the dApp script or account script to the sender's account. | | 16 | [Invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) | Invokes a callable function of a dApp. | #### Transfer Transaction Transfer transaction transfers a certain amount of token to another account. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a transfer transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin), in case of transferring a smart asset 0.005 DecentralCoins. If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "Cs4DShy4nTx6WyxjKRoDtoYsGhvT663pYLysPCLeVZHE", "amount": 15540, "signature": "5EaYqFx2xFJmdvwZ1gT3yLecKr88z3jByCj5GE1MjE1ossvehExZKoT7uhGatiYCGM9Co8iUR8Q5ce52XDmno3rn", "fee": 100000, "type": 4, "version": 1, "attachment": "3vrgtyozxuY88J9RqMBBAci2UzAq9DBMFTpMWLPzMygGeSWnD7k", "sender": "3PN2bVFxJjgudPKqEGZ41TVsD5ZJmxqnPSu", "feeAssetId": null, "proofs": [ "5EaYqFx2xFJmdvwZ1gT3yLecKr88z3jByCj5GE1MjE1ossvehExZKoT7uhGatiYCGM9Co8iUR8Q5ce52XDmno3rn" ], "assetId": "7uncmN7dZfV3fYVvNdYTngrrbamPYMgwpDnYG1bGy6nA", "recipient": "3PFmoN5YLoPNsL4cmNGkRxbUKrUVntwyAhf", "feeAsset": null, "id": "D79kL1Jr5xyL2Rmw2FnafQHugJGvuBhNEbLnhMuwMkDC", "timestamp": 1548660895034, "height": 1370973 } ``` **Transfer Transaction JSON Representation** | Field | Description | | --- | --- | | assetId | Token ID base58 encoded. null means [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | | amount | Amount of token to transfer: an integer value specified in the minimum fraction (“cents”) of token. | | attachment | Arbitrary binary data (typically a comment to transfer) base58 encoded, up to 4 bytes. | | recipient | Recipient address base58 encoded or recipient alias with alias:: prefix, for example alias:T:merry (See [chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id)). | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [transfer transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#transfer-transaction-binary-format). **Ride Structure** The [TransferTransaction](https://decentralchain.io/docs/ride/structures#transfertransaction) structure is used for transaction handling in smart contracts. #### Exchange Transaction Exchange transaction exchanges two different tokens between two accounts. Commonly the exchange transaction is created by the matcher service that executes orders to buy and sell tokens. The exchange transaction contains two counter orders: a buy order and a sell order. The blockchain guarantees that the terms of the exchange are not worse than those indicated in each order. An order can be filled partially. An order can participate in several exchange transactions, with different counter orders. One of the two exchanged tokens is the amount asset (base currency): it represents the amount of token in orders and in the Exchange transaction. Another token is a price asset (quote currency): it represents the price. ![](https://decentralchain.io/docs/08_Exchange-Transaction.png) **Transaction Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for an exchange transaction is 0.003 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). In case of exchange of a [smart asset](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset) for an ordinary asset the minimum fee is 0.007 DecentralCoins, in case of exchange of two smart assets the minimum fee is 0.011 DecentralCoins. If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **Matcher Fee** The matcher receives a fee for order execution from each order sender. The minimum matcher fee is set by the matcher. The order sender specifies the fee not less than the minimum amount. If the order is fully filled with one exchange transaction, the matcher receives the entire fee specified in the order. If the order is partially filled, the matcher receives a part of the fee. The blockchain guarantees that the total matcher fee received from the order sender in all exchange transactions does not exceed the fee specified in the order. ![](https://decentralchain.io/docs/09_Matcher-Fee.png) **JSON Representation** ```none { "senderPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5", "amount": 100000000, "fee": 300000, "type": 7, "version": 2, "sellMatcherFee": 750, "sender": "3PEjHv3JGjcWNpYEEkif2w8NXV4kbhnoGgu", "feeAssetId": null, "proofs": [ "LQD8VoFhHEW2b6o2e2ujzDHdZatwMMwigC2tmoSHcFNRGXrowA1yyVxD6nZBNeABLWjs59dnuLhgNP7UMfFKDuR" ], "price": 1134500, "id": "EHLccXcemZPEvUpM9UkASG1GciwMt9R5B3QuYFxywj9g", "order2": { "version": 3, "id": "JCiF3gmprLc8u7xdWR7KUkJ3YfM6yfgxB6CvhJYGJFAa", "sender": "3PRBeeFD64wvTMfS3HEoDDFPXfJs3gFdAxk", "senderPublicKey": "ytgWVbKG9e6TSsQ5buMryr2QyxNoL3RezXP3f9RJ2As", "matcherPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5", "assetPair": { "amountAsset": null, "priceAsset": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p" }, "orderType": "sell", "amount": 40000000000, "price": 1134500, "timestamp": 1591356602063, "expiration": 1593862202062, "matcherFee": 300000, "matcherFeeAssetId": null, "signature": "3D2Ngr7H6MQRs1izMQSix3dMHmDfg4bcRjxamFXFsb4Ku28neNWHdtwE6LtR3eq69Jqr1CvEsAKCWkQEeEEomcoK", "proofs": [ "3D2Ngr7H6MQRs1izMQSix3dMHmDfg4bcRjxamFXFsb4Ku28neNWHdtwE6LtR3eq69Jqr1CvEsAKCWkQEeEEomcoK" ] }, "order1": { "version": 3, "id": "FNvEGPgUqEWnrnpxevZQnaZS3DUTBGE2wa6L75xCw7mo", "sender": "3PDxxx7eSeYLgzTAtuAV7gUCtHeeXeU85fP", "senderPublicKey": "3WEkbavP3Sw4y5tsgxbZvKkWh87BdB3CPVVxhcRUDBsJ", "matcherPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5", "assetPair": { "amountAsset": null, "priceAsset": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p" }, "orderType": "buy", "amount": 100000000, "price": 1134500, "timestamp": 1591356752271, "expiration": 1593862352271, "matcherFee": 300000, "matcherFeeAssetId": null, "signature": "2gvqaYy2BFbK4BJZS8taRJnhgfQ1z2CytF2RqjcyEfzFiu9tkTjN5q4UyFXpPqS3E6eD2WQBUaYCTYDKv98iW1sy", "proofs": [ "2gvqaYy2BFbK4BJZS8taRJnhgfQ1z2CytF2RqjcyEfzFiu9tkTjN5q4UyFXpPqS3E6eD2WQBUaYCTYDKv98iW1sy" ] }, "buyMatcherFee": 300000, "timestamp": 1591356752456, "height": 2093333 } ``` **Exchange Transaction JSON Representation** | Field | Description | | --- | --- | | amount | Amount of the amount asset: an integer value specified in the minimum fraction (“cent”) of asset. | | price | Price for the amount asset nominated in the price asset, multiplied by the factor: 1) 10^{8} for the exchange transaction version 3. 2) 10^{(8 + priceAssetDecimals – amountAssetDecimals)}. Where amountAssetDecimals, priceAssetDecimals are decimals of the assets, for the exchange transaction version 2 or 1. | | buyMatcherFee | Matcher fee for the buy order execution. The fee token ID is indicated in buy order. | | sellMatcherFee | Matcher fee for the sell order execution. The fee token ID is indicated in sell order. | | order1, order2 | Buy and sell orders. See the [order](https://decentralchain.io/docs/decentralchain/order#order) article for details. | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [exchange transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#exchange-transaction-binary-format). **Ride Structure** The [ExchangeTransaction](https://decentralchain.io/docs/ride/structures#exchangetransaction) structure is used for transaction handling in smart contracts. #### Create Alias Transaction Create Alias transaction creates an [alias](https://decentralchain.io/docs/decentralchain/account#alias) for the sender's address.A created alias cannot be deleted. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a Create Alias transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey":"BVv1ZuE3gKFa6krwWJQwEmrLYUESuUabNCXgYTmCoBt6", "sender":"3N8S4UtauvDAzpLiaRyDdHn9muexWHhBP4D", "feeAssetId":null, "proofs": [ "22QJfRKX7kUQt4qjdnUqZAnhqukqhnofE27uvP8Q5xnBf8M6PCNtWVGq2ngm6m7Voe7duys59D1yU9jhKrmdXDCe" ], "fee":100000, "alias":"91f452553298770f", "id":"AD7KmXwoVNc2fXsmaxsHsrnT1tfPF3HsWYtfjFijVsvM", "type":10, "version":2, "timestamp":1548443069053, "height":466104 } ``` **Create Alias Transaction JSON Representation** | Field | Description | | --- | --- | | alias | Alias. From 4 to 30 bytes (1 character can take up to 4 bytes). | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [create alias transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#create-alias-transaction-binary-format). **Ride Structure** The [CreateAliasTransaction](https://decentralchain.io/docs/ride/structures#createaliastransaction) structure is used for transaction handling in smart contracts. #### Mass Transfer Transaction Mass transfer transaction transfers a [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) to several accounts, from 1 [DecentralCoin](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to 100 DecentralCoins . **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a Mass Transfer transaction is 0.001 + 0.0005 × N DecentralCoins, in case of transferring a [smart asset](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset) 0.001 + 0.0005 × N DecentralCoins, where N DecentralCoins is the number of recipients. The fee value is rounded up to three decimals. If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "5DphrhGy6MM4N3yxfB2uR2oFUkp2MNMpSzhZ4uJEm3U1", "fee": 5100000, "type": 11, "transferCount": 100, "version": 1, "totalAmount": 500000000000, "attachment": "xZBWqm9Ddt5BJVFvHUaQwB7Dsj78UQ5HatQjD8VQKj4CHG48WswJxUUeHEDZJkHgt9LycUpHBFc8ENu8TF8vvnDJCgfy1NeKaUNydqy9vkACLZjSqaVmvfaM3NQB", "sender": "3P2rvn2Hpz6pJcH8oPNrwLsetvYP852QQ2m", "feeAssetId": null, "proofs": [ "FmGBaWABAy5bif7Qia2LWQ5B4KNmBnbXETL1mE6XEy4AAMjftt3FrxAa8x2pZ9ux391oY5c2c6ZSDEM4nzrvJDo" ], "assetId": "Fx2rhWK36H1nfXsiD4orNpBm2QG1JrMhx3eUcPVcoZm2", "transfers": [ { "recipient": "3PHnjQrdK389SbzwPEJHYKzhCqWvaoy3GQB", "amount": 5000000000 }, { "recipient": "3PGNLwUG2GPpw74teTAxXFLxgFt3T2uQJsF", "amount": 5000000000 }, { "recipient": "3P5kQneM9EdpVUbFLgefD385LLYTXY5J32c", "amount": 5000000000 }, ... ], "id": "3LRfudet7avpQcW1AdauiBGb8SSRAaoCugDzngDPLVcv", "timestamp": 1528973951321, "height": 1041197 } ``` **Mass Transfer Transaction JSON Representation** | Field | Description | | --- | --- | | assetId | Token ID base58 encoded. null means [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | | attachment | Arbitrary binary data (typically a comment to transfer) base58 encoded, up to 140 bytes. | | transfers.recipient | Recipient address base58 encoded or recipient alias with alias:: prefix, for example alias:T:merry (See [chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id)). | | transfers.amount | Amount of token to transfer: an integer value specified in the minimum fraction (“cents”) of token. | | transferCount | Number of recipients. | | totalAmount | Total amount of transfers in transaction. | The transferCount and totalAmount fields do not need to be filled when sending a transaction, and they are not stored on the blockchain. The node calculates these fields when providing transaction data via the REST API. The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [mass transfer transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#mass-transfer-transaction-binary-format). **Ride Structure** The [MassTransferTransaction](https://decentralchain.io/docs/ride/structures#masstransfertransaction) structure is used for transaction handling in smart contracts. #### Data Transaction Data transaction adds, modifies and deletes data entries in sender's [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage). Limitations are as follows: - The maximum number of entries is 100. - For a transaction version 2 the maximum data size (keys + values) is 165,890 bytes. - For a transaction version 1 the maximum transaction size (except proofs) is 153,600 bytes. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a Data transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) per kilobyte, the size is rounded up to an integer number of kilobytes. If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "38bYRUxFCaoa9h822nMnsoTX1qfczqtHJLgouNcNnd8h", "data": [ { "type": "boolean", "value": true, "key": "bool" }, { "type": "binary", "value": "base64:SGVsbG8gV2F2ZXM=", "key": "bin" }, { "type": "integer", "value": 1234567, "key": "int" }, { "type": "string", "value": "some text", "key": "str" } ], "sender": "3N4iKL6ikwxiL7yNvWQmw7rg3wGna8uL6LU", "feeAssetId": null, "proofs": [ "kE1hjN1yW68j8DsYGNB7Gg1ydC4hqRmt3wBaFQUPkftnbiM7QfJCn1gTHgveJ7pCLXvvqffhKBmiF8qS1Uqk6SR" ], "fee": 100000, "id": "3EPJuvQiJYiu9Y5g6mYDQgHVu8GFUfnZurHrVwwF1ViH", "type": 12, "version": 2, "timestamp": 1591351545000, "height": 1029815 } ``` **Data Transaction JSON Representation** | Field | Description | | --- | --- | | data.key | Entry key. String, up to 400 bytes for version 2, up to 100 characters for version 1. | | data.type | Entry type: 1) binary. 2) boolean. 3) integer. 4) string. 5) null – delete entry. | | data.value | Entry value. Up to 32,767 bytes. Binary value is base64 encoded. null – delete entry. | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [data transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#data-transaction-binary-format). **Ride Structure** The [DataTransaction structure](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations) is used for transaction handling in smart contracts. #### Set Script Transaction Set script transaction assigns the dApp script [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script) or [account script](https://decentralchain.io/docs/ride/script-types#account-script) to the sender's account. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a Set Script transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "7nLAwoiRA4fWF4VHd6gRsbwF2UFFmRADXHqRcgy3h27w", "sender": "3N9yCRmNsLK2aPStjLBne3EUiPSKvVHYgKk", "feeAssetId": null, "chainId": 84, "proofs": [ "2ihGFLUbvJHEpuGRqx5MXEXsEzwMuCmB8FgUTZgSPdANA4iab4M3nsNJ7a7hyiuqjrvwNCHoWn69hvUeziJiSAie" ], "fee": 1400000, "id": "28hbeFhYBq6uir1bbjt2dxbpqxCM2B6GKq4c7zf7AbkX", "type": 13, "version": 1, "script": "base64:AAIDAAAAAAAAAAYIARIAEgAAAAACAQAAAApyYW5kb21pemVyAAAAAQAAAANpbnYEAAAACGxhc3RQbGF5BAAAAAckbWF0Y2gwCQAEHAAAAAIFAAAABHRoaXMCAAAACGxhc3RQbGF5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAApCeXRlVmVjdG9yBAAAAAFzBQAAAAckbWF0Y2gwBQAAAAFzAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAARVbml0BAAAAAFhBQAAAAckbWF0Y2gwAQAAAAxXYXZlc0xvdHRvVjIJAQAAAAV0aHJvdwAAAAAEAAAABHJhbmQJAADLAAAAAgkAAMsAAAACCQAAywAAAAIJAADLAAAAAgkAAMsAAAACBQAAAAhsYXN0UGxheQgFAAAAA2ludgAAAA10cmFuc2FjdGlvbklkCAUAAAADaW52AAAAD2NhbGxlclB1YmxpY0tleQgFAAAACWxhc3RCbG9jawAAABNnZW5lcmF0aW9uU2lnbmF0dXJlCQABmgAAAAEIBQAAAAlsYXN0QmxvY2sAAAAJdGltZXN0YW1wCQABmgAAAAEIBQAAAAlsYXN0QmxvY2sAAAAGaGVpZ2h0CQAB9wAAAAEFAAAABHJhbmQBAAAACnN0YXJ0TG90dG8AAAABAAAAA2ludgQAAAAJcGxheUxpbWl0CQAAaQAAAAIJAQAAAAx3YXZlc0JhbGFuY2UAAAABBQAAAAR0aGlzAAAAAAAAAABkBAAAAAdwYXltZW50CQEAAAAHZXh0cmFjdAAAAAEIBQAAAANpbnYAAAAHcGF5bWVudAMJAQAAAAEhAAAAAQkBAAAACWlzRGVmaW5lZAAAAAEIBQAAAANpbnYAAAAHcGF5bWVudAkAAAIAAAABAgAAAB9TaG91bGQgYmUgd2l0aCBQYXltZW50IGluIFdhdmVzAwkBAAAACWlzRGVmaW5lZAAAAAEIBQAAAAdwYXltZW50AAAAB2Fzc2V0SWQJAAACAAAAAQIAAAAaUGF5bWVudCBzaG91bGQgYmUgaW4gV2F2ZXMDCQAAZgAAAAIIBQAAAAdwYXltZW50AAAABmFtb3VudAUAAAAJcGxheUxpbWl0CQAAAgAAAAEJAAEsAAAAAgIAAAAcUGF5bWVudCBzaG91bGQgYmUgbGVzcyB0aGFuIAkAAaQAAAABBQAAAAlwbGF5TGltaXQEAAAACHJhbmRoYXNoCQEAAAAKcmFuZG9taXplcgAAAAEFAAAAA2ludgQAAAALd2luVHJhbnNmZXIJAQAAAAtUcmFuc2ZlclNldAAAAAEJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAA2ludgAAAAZjYWxsZXIJAABpAAAAAgkAAGgAAAACCAUAAAAHcGF5bWVudAAAAAZhbW91bnQAAAAAAAAAAL4AAAAAAAAAAGQFAAAABHVuaXQFAAAAA25pbAQAAAANd3JpdGVMYXN0UGxheQkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgIAAAAIbGFzdFBsYXkFAAAACHJhbmRoYXNoBQAAAANuaWwDCQAAZgAAAAIAAAAAAAAAAfQJAABqAAAAAgkABLEAAAABBQAAAAhyYW5kaGFzaAAAAAAAAAAD6AkBAAAADFNjcmlwdFJlc3VsdAAAAAIFAAAADXdyaXRlTGFzdFBsYXkFAAAAC3dpblRyYW5zZmVyCQEAAAAMU2NyaXB0UmVzdWx0AAAAAgUAAAANd3JpdGVMYXN0UGxheQkBAAAAC1RyYW5zZmVyU2V0AAAAAQUAAAADbmlsAAAAAgAAAANpbnYBAAAABWxvdHRvAAAAAAkBAAAACnN0YXJ0TG90dG8AAAABBQAAAANpbnYAAAADaW52AQAAAAdkZWZhdWx0AAAAAAkBAAAACnN0YXJ0TG90dG8AAAABBQAAAANpbnYAAAAA4XqnJg==", "timestamp": 1592408917668, "height": 1047736 } ``` **Set Script Transaction JSON Representation** | Field | Description | | --- | --- | | chainId | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | script | Compiled script, base64 encoded. Account script up to 8192 bytes, dApp script up to 32,767 bytes. null – delete script. | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [set script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#set-script-transaction-binary-format). **Ride Structure** The [SetScriptTransaction](https://decentralchain.io/docs/ride/structures#setscripttransaction) structure is used for transaction handling in smart contracts. #### Invoke Script Transaction Invoke script transaction invokes the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions) of the [dApp](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account). In addition to the dApp address, callable function name, and arguments, the Invoke Script transaction can contain payments to dApp. The maximum number of payments is 10. **Fee** The sender can specify a transaction fee nominated in a sponsored asset instead of DecentralCoins, see the [sponsored fee](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees) article. The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) for an invoke script transaction is Fee = 0.005 + S + 1 × I. - If the transaction sender is a dApp or smart account, and that the complexity of the account script or dApp script verifier function exceeds the sender complexity threshold, then S = 0.004, otherwise S = 0. - I is the number of issued assets that are not [NFT](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token). **Total Complexity** A dApp callable function can invoke a callable function of another dApp, or another callable function of the same dApp, or even itself. All invoked functions are executed within a single Invoke Script transaction. [More about dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation). The total [complexity](https://decentralchain.io/docs/ride/dapp-to-app-invocation#script-complexity) is limited by 26,000 for all callable functions and asset scripts of involved smart assets in a single invoke script transaction. The sender's account script complexity is not included in that limit. **JSON Representation** ```none { "type": 16, "id": "DN9Ny8mph4tLjn58e9CqhckPymH9zwPqBSZtcv2bBi3u", "sender": "3Mw48B85LvkBUhhDDmUvLhF9koAzfsPekDb", "senderPublicKey": "BvJEWY79uQEFetuyiZAF5U4yjPioMj9J6ZrF9uTNfe3E", "fee": 500000, "feeAssetId": null, "timestamp": 1601652119485, "proofs": [ "2536V2349X3cuVEK1rSxQf3HneJwLimjCmCfoG1QyMLLq1CNp6dpPKUG3Lb4pu76XqLe3nWyo3HAEwGoALgBhxkF" ], "version": 2, "chainId": 84, "dApp": "3N28o4ZDhPK77QFFKoKBnN3uNeoaNSNXzXm", "payment": [], "call": { "function": "foo", "args": [ { "type": "list", "value": [ { "type": "string", "value": "alpha" }, { "type": "string", "value": "beta" }, { "type": "string", "value": "gamma" } ] } ] }, "height": 1203100, "applicationStatus": "succeeded", "stateChanges": { "data": [ { "key": "3Mw48B85LvkBUhhDDmUvLhF9koAzfsPekDb", "type": "string", "value": "alphabetagamma" } ], "transfers": [], "issues": [], "reissues": [], "burns": [], "sponsorFees": [], "leases": [], "leaseCancels": [], "invokes": [] } } ``` **Invoke Script Transaction JSON Representation** | Field | Description | | --- | --- | | call.function | Callable function name. Up to 255 bytes (1 character can take up to 4 bytes). | | call.args.type | Argument type: 1) binary. 2) boolean. 3) integer. 4) string. 5) list. | | call.args.value | Argument value. 1) integer: from -9,223,372,036,854,775,808 to 9,223,372,036,854,755,807 inclusive. 2) string or binary: up to 32,767 bytes. Binary value should be base64 encoded. 3) list: up to 1000 elements. | | dApp | dApp address base58 encoded or dApp alias with alias:: prefix, for example alias:T:merry (See [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id)). | | payment.amount | Amount of token in payment: an integer value specified in atomic units. | | payment.assetId | ID of token in payment, base58 encoded. null means that the payment is in [DecentralCoin](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | | stateChanges | Script actions performed by the callable function and dApp-to-dApp invocation results. | The stateChanges structure does not need to be filled when sending a transaction, and it is not stored on the blockchain. The node returns this structure when providing transaction data via the REST API. The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [invoke script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#invoke-script-transaction-binary-format). **Ride Structure** The [InvokeScriptTransaction](https://decentralchain.io/docs/ride/structures#invokescripttransaction) structure is used for transaction handling in smart contracts. ### Network **Network** | Transaction type ID | Name | Description | | --- | --- | --- | | 8 | [Lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction) | Leases [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | | 9 | [Lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction) | Cancels the leasing. | | 14 | [Sponsor fee transaction](https://decentralchain.io/docs/decentralchain/transaction#sponsor-fee-transaction) | Configures sponsorship. | #### Lease Transaction Lease transaction leases [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to another account. After 1000 block the leased tokens are accounted for by the recipient's generating balance. The larger the generating balance of the node is, the higher the chances for that node to be selected to generate the next block. Commonly node owners share the reward for generated blocks with lessors. [More about leasing](https://decentralchain.io/docs/decentralchain/node#leased-proof-of-stake). Leased tokens remain locked on the sender's account with the full control of their owner. The sender can cancel the lease at any time by the [lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction). **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a lease transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "b8AB1PQWE7kH55cS48uDTV5fezrAyDTCf7iePyXNzNm", "amount": 500000000, "signature": "3n34MYd3Acx1JpTtvYffdVYCVySuRgZvSbHMA3AxqQwr4xvfZedv9UbqSB9k84PGY5C8RSwGRjDnMGcYwQu2x7B5", "fee": 100000, "type": 8, "version": 1, "sender": "3P6iv9tYo3ELne7tc9HR8BzhK3LE2aDDu1A", "feeAssetId": null, "proofs": [ "3n34MYd3Acx1JpTtvYffdVYCVySuRgZvSbHMA3AxqQwr4xvfZedv9UbqSB9k84PGY5C8RSwGRjDnMGcYwQu2x7B5" ], "recipient": "3P2HNUd5VUPLMQkJmctTPEeeHumiPN2GkTb", "id": "7k4EPgA3VxoE56TMJLjvF9FMpywyfeS5qRJSEEN9XGuU", "timestamp": 1528813353617, "status": "canceled", "height": 1038624 } ``` **Lease Transaction JSON Representation** | Field | Description | | --- | --- | | amount | Amount of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to lease. | | recipient | Recipient address base58 encoded or recipient alias. | | status | Lease status: 1) active: lease is active. 2) canceled: lease is cancelled, see [lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction). | The status field does not need to be filled when sending a transaction, and it is not stored on the blockchain. The node calculates these fields when providing transaction data via the REST API. The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [lease transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#lease-transaction-binary-format). **Ride Structure** The [LeaseTransaction](https://decentralchain.io/docs/ride/structures#leasetransaction) structure is used for transaction handling in smart contracts. #### Lease Cancel Transaction Lease cancel transaction cancels the leasing. See the [lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction) article. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for a lease cancel transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "type": 9, "id": "6rzxZ3rEsCxgmkcn6DDPB9f9Phi28D4JWZsCtwcViD8C", "sender": "3Mx7kNAFcGrAeCebnt3yXceiRSwru6N3XZd", "senderPublicKey": "81fxJw7HM2VX1ucq1vNKiedM1XBGX7H2TDUtxN6ib68Z", "fee": 100000, "feeAssetId": null, "timestamp": 1622579112096, "proofs": [ "3eFnprsRSeczc371bQ7AUsbh6qjiUFze6y5BZGKbxyHG27K1cU6jVUgRdthYz9uWVw1FgVpLjMciGCb64rJnMp3k" ], "version": 2, "leaseId": "BhHPPHBZpfp8FBy8DE7heTpWGJySYg2uU2r4YM6qaisw", "chainId": 84, "height": 1551763, "applicationStatus": "succeeded", "lease": { "id": "BhHPPHBZpfp8FBy8DE7heTpWGJySYg2uU2r4YM6qaisw", "originTransactionId": "BhHPPHBZpfp8FBy8DE7heTpWGJySYg2uU2r4YM6qaisw", "sender": "3Mx7kNAFcGrAeCebnt3yXceiRSwru6N3XZd", "recipient": "3Mz9N7YPfZPWGd4yYaX6H53Gcgrq6ifYiH7", "amount": 124935000, "height": 1551763, "status": "canceled" } } ``` **Lease Cancel Transaction JSON Representation** | Field | Description | | --- | --- | | leaseId | Lease transaction ID. | | chainId | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | lease | Parameters of canceled lease. | The lease structure does not need to be filled when sending a transaction, and it is not stored on the blockchain. The node returns this structure when providing transaction data via the REST API. The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [lease cancel transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#lease-cancel-transaction-binary-format). **Ride Structure** The [LeaseCancelTransaction](https://decentralchain.io/docs/ride/structures#leasecanceltransaction) structure is used for transaction handling in smart contracts. #### Sponsor Fee Transaction Sponsor fee transaction enables or disables sponsorship. Sponsorship allows any user to pay a fee in the sponsored asset (instead of DecentralCoins) for invoke script transactions and transfer transactions. [More about sponsorship](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees). Only the asset issuer can set up sponsorship. Smart asset cannot be a sponsored asset. **Fee** The [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) for the sponsor fee transaction is 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). If the transaction sender is a [dApp or smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account), and the complexity of the account script or dApp script verifier function exceeds the [sender complexity threshold](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the minimum fee is increased by 0.004 DecentralCoins. **JSON Representation** ```none { "senderPublicKey": "5HNegWomhj1nzyggf1oAvujNJGCqbzFjM72BLYtrBecw", "sender": "3N3ErpmUdJWy6DW4ruAr14YDis9UaiTwHd6", "feeAssetId": null, "proofs": [ "5jF8WpF7jxf5SBMHMbc2WcfqX3R6fRvssBGSNfzAM8p3uSmno9XzYy5b565ez5fG9vqUGrENFvcrbhk36bzCaqkP" ], "assetId": "p1vuxnGyfH9VFiuyKmsh25rn6MedjGbQu7d6Zt1sY4U", "fee": 100000000, "minSponsoredAssetFee": 100, "id": "5gHUMzmBfn4KP3tELzHtw3EYR947rzWUp5PuyF7hUW23", "type": 14, "version": 1, "timestamp": 1585725309659, "height": 934757 } ``` **Sponsor Fee Transaction JSON Representation** | Field | Description | | --- | --- | | minSponsoredAssetFee | Amount of asset that is equivalent to 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) (100,000 Decentralites): an integer value specified in the minimum fraction (“cents”) of asset. null – disable sponsorship. | | assetId | Token ID base58 encoded. | The fields that are common to all types of transactions are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. **Binary Format** See the [sponsor fee transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#sponsor-fee-transaction-binary-format). **Ride Structure** The [SponsorFeeTransaction](https://decentralchain.io/docs/ride/structures#sponsorfeetransaction) structure is used for transaction handling in smart contracts. ### Genesis **Genesis** | Transaction type ID | Name | Description | | --- | --- | --- | | 1 | [Genesis transaction](https://decentralchain.io/docs/decentralchain/transaction#genesis-transaction) | Accrues [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to an account upon the initial distribution during the creation of the blockchain. | #### Genesis Transaction Genesis transaction accrues [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to account upon the initial distribution of DecentralCoins during the creation of the blockchain. The first block of the blockchain, the genesis block, consists of genesis transactions. **Binary Format** See the [genesis transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#genesis-transaction-binary-format). ## Transaction Validation A DecentralChain node validates each transaction in the following cases: - The node receives the transaction via the broadcast endpoint of Node extensions or gRPC server. - The node receives the transaction from another node of the blockchain network using the binary protocol. - The block generator adds the transaction to a block. - The node receives a block (or microblock) from another node in the network. Full transaction validation includes the following checks: 1. Transaction fields check including: 1. Timestamp check: the transaction timestamp should be not more than 2 hours ago or 1.5 hours ahead from the current block timestamp. 2. Transaction version check: all the features required to support this version should be activated. 3. Transaction type check: all the features required to support this type should be activated. 4. Check of token amounts: the values must be non-negative. 5. Check different fields depending on the transaction type. 2. Sender's balance check. 1. The sender should have enough funds to pay the fee. If a sponsored asset is used for the fee, the sponsor's balance is also checked. 2. Depending on the type of transaction, the sender should have enough assets for transfer or for payments attached to the [invoke script transactions](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction). Order senders in the [exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction) should have enough funds to exchange. 3. The sender's signature verification 1. For ordinary accounts (without script). 2. For account script execution if the sender is a [smart account](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account). 3. For verifier function execution if the sender is [dApp](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account). 4. A similar check is performed for orders in an [exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction). 4. For the invoke script transaction: 1. Calculation of the result of dApp callable function. 2. dApp balance check: dApp account should have enough funds for [dApp script actions](https://decentralchain.io/docs/ride/structures#script-actions). 3. Check that the transaction fee is not less than the [minimum fee](https://decentralchain.io/docs/decentralchain/transaction#minimum-fee) based on script actions. 5. Execution of asset scripts if the transaction uses [smart assets](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset), including scripts of assets used in dApp script actions. When receiving the transaction via the broadcast endpoint, or adding a transaction to a block, or receiving a block over the network, the node performs full validation of the transaction. When receiving an invoke script transaction over the network, the node performs calculations of the callable function (check 4.1) up to the [threshold for saving unsuccessful transactions](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations). ### Validation Result When the transaction is received via broadcast or over the network: - If one of the checks fails, the transaction is discarded. - If all the checks passed, the transaction is added to the UTX pool, which is the list of transactions waiting to be added to the block. When adding the transaction to the block, the result of validation depends on the transaction type. For the invoke script transaction: - If one of the checks 1–3 failed, the transaction is discarded. - If checks 1–3 passed, and the calculation of the result of the dApp callable function (check 4.1) failed with an error or [throwing an exception](https://decentralchain.io/docs/ride/syntax-basics#exceptions) before the [complexity](https://decentralchain.io/docs/ride/dapp-to-app-invocation#script-complexity) of performed calculations exceeded the [threshold for saving failed transactions](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the transaction is also discarded. - If checks 1–3 passed but checks 4–5 failed and besides the result of the callable function is calculated successfully or the complexity exceeded the threshold, the transaction is saved on the blockchain but marked as failed: "applicationStatus": "script_execution_failed". The sender is charged the transaction fee. The transaction doesn't entail any other changes to the state of the blockchain. - If all checks passed, the transaction is saved on the blockchain as successful: "applicationStatus": "succeeded" and the sender is charged the fee. For the exchange transaction: - If one of the checks 1–3 failed, the transaction is discarded. - If checks 1–3 passed but check 5 failed, the transaction is saved on the blockchain but marked as failed: "applicationStatus": "script_execution_failed". The sender of the transaction (matcher) is charged the transaction fee. The transaction doesn't entail any other changes in balances, in particular, the order senders don't pay the matcher fee. - If all checks passed, the transaction is saved on the blockchain as successful: "applicationStatus": "succeeded". The matcher is charged the transaction fee as well as the order senders are charged the matcher fee. For the other transactions: - If one of the checks fails, the transaction is discarded. - If all checks passed, the transaction is saved on the blockchain as successful and the sender is charged the fee. --- # Block Source: https://decentralchain.io/docs/decentralchain/block A block is a link in the chain of the blockchain. Block contains transactions. A block has its height. The maximum block size is 1 MB. The maximum total complexity of scripts in transactions of the block is 2,500,000. The complexity of all executed scripts is taken into account: dApp scripts, account scripts, and asset scripts. ## Block Generation A block generation is a creation of a new [block](https://decentralchain.io/docs/decentralchain/block#block) on the blockchain. Blocks are generated by [generating nodes](https://decentralchain.io/docs/decentralchain/node#generating-node) according to [FPoS algorithm](https://decentralchain.io/docs/decentralchain/protocol#fair-proof-of-stake) and the [DecentralChain-M5 protocol](https://decentralchain.io/docs/decentralchain/protocol#decentralchain-m5-protocol). The block generator signs the block headers only. The block headers contain the merkle root hash of the block transactions. This makes it possible to verify the block headers apart from transactions and to provide evidence of the presence of transactions in the block without the presence of all transactions. See details in the [transactions root hash](https://decentralchain.io/docs/decentralchain/block#transactions-root-hash) article. ### Base Target The base target is the variable in the average block generation time formula that adjusts [block generation](https://decentralchain.io/docs/decentralchain/block#block-generation) time to 60 seconds. ### Generation Signature Generation signature is the variable in the average block generation time formula. It is used to check whether the current [generating node](https://decentralchain.io/docs/decentralchain/node#generating-node) is eligible to generate the next block. The generation signature is calculated using VRF (verifiable random function with short proofs and keys) — a pseudo-random function that uses a message and the private key of an account to provide a non-interactively verifiable proof for the correctness of its output. This improvement allows resisting stake grinding attacks aimed at influencing block generation randomness to skip miner's opportunity to create a block. The use of VRF makes signature generation unpredictable because of the need to know the private key for calculation. Only the holder of the private key can compute the hash, but verifying the correctness of the hash using the public key from block header is available to anyone. The VRF contains calculateVRF function, which calculates proof for some message, and verifyVRF function, which verifies proof from calculateVRF function with a message and the public key of the signer. Considering that a block’s generation signature is equal to calculateVRF output for a previous generation signature with account private key sk (of generator of i+1 th block): ```none generationSignaturei+1 = VRFproof = calculateVRFsk(VRFi) ``` The output of calculateVRF function is a VRF proof, which means that the validity of the signature can be checked. The output of function verifyVRF(pk _i, generationSignature _i) is used to define the time delay between i+99 and i+100 blocks for concrete block generator. ## Block Height The block height is a sequence number of a [block](https://decentralchain.io/docs/decentralchain/block#block) in the blockchain. ## Block Signature A block signature is a hash that a [generating node](https://decentralchain.io/docs/decentralchain/node#generating-node) acquires when it signs the [generated block](https://decentralchain.io/docs/decentralchain/block#block-generation) with the private key of the account from the node's wallet. ## Block Timestamp A block timestamp is a time of [block generation](https://decentralchain.io/docs/decentralchain/block#block-generation). The time is specified in milliseconds that have passed since the beginning of the unix epoch. When the [node](https://decentralchain.io/docs/decentralchain/node#node) receives a new block from the blockchain network, it verifies that the timestamp value of the block does not outpace the UTC time by more than 100 milliseconds. The timestamp value of the block is validated by nodes using the formula from FPoS. ## Genesis Block A genesis block is the first [block](https://decentralchain.io/docs/decentralchain/block#block) of the blockchain. A genesis block contains one or more [genesis transactions](https://decentralchain.io/docs/decentralchain/transaction#genesis-transaction). There is one genesis block in the blockchain. ## Transactions Root Hash The transactionsRoot field in the block header contains the root hash of the Merkle tree of transactions of the block. The root hash is the proof that the block contains all the transactions in the proper order. The transactions root hash in the block header has the following purposes: - To prove the integrity of transactions in the block without presenting all transactions. - To sign the block header only, separately from its transactions. ### transactions Root Сalculation ![](https://decentralchain.io/docs/10_transactionsRoot-Calculation.png) 1. The hash of each transaction in the block is calculated. For example: - H_A = hash(T_A) - H_B = hash(T_B) 2. Each pair of adjacent hashes is concatenated, and the hash is calculated for each resulting concatenation: - H_{AB} = hash(H_A + H_B) - If the last hash does not have a pair, it is concatenated with the zero byte hash: H_{GH} = hash(H_G + hash(0)) 3. Step 2 is repeated until the root hash is obtained: - H_{ABCDEFGH} - The root hash is written in the transactionsRoot field. If the block is empty, then transactionsRoot = hash(0). DecentralChain blockchain uses BLAKE2b-256 hashing function. ### Proof of Transaction in Block Let's suppose that side 1 stores the full blockchain data and side 2 stores the block headers only. To prove that the block contains a given transaction, side 1 provides the following data: - T: Transaction to check. - merkleProofs: Array of sibling hashes of the Merkle tree, bottom-to-top. - index: Index of the transaction in the block. ![](https://decentralchain.io/docs/11_Proof-of-Transaction-in-Block.png) For example, for the T_D transaction: - merkleProofs = [ H_C, H_{AB}, H_{EFGH} ] - index = 3 Side 2 checks the proof: 1. It calculates the hash of the transaction being checked (all the transaction data is hashed, including the signature): H_D = hash(T_D) 2. It concatenates the current hash with the corresponding hash of the merkleProofs array and calculates the hash of concatenation. index determines in which order to concatenate the hashes: - If the nth bit of index from the end is 0, then the order is: the current hash + the nth hash of the merkleProofsarray (proof hash is on the right). - If the nth bit is 1 , the order is: the nth hash of the merkleProofsarray + the current hash (proof hash is on the left). For example, index = 3_{10} = 11_2 , thus: - merkleProofs[0] = H_{C} is on the left, - merkleProofs[1] = H_{AB} is on the left, - merkleProofs[2] = H_{EFGH} is on the right. 3. It repeats step 2 until the root hash is obtained: H_{ABCDEFGH} 4. It compares the root hash obtained with the already known transactionsRoot from the block header. If the hashes match, then the transaction exists in the block. ### Tools The following Node API methods accept transaction IDs and provide the proof that the transaction is in a block for each transaction: - GET /transactions/merkleProof - POST /transactions/merkleProof The methods are described in the [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) article. You can check a transaction on the same blockchain without using a root hash, since the DecentralChain nodes store the entire blockchain data, including all transactions. Use the following built-in Ride function: ```none transactionHeightById(id: ByteVector): Int|Unit ``` The function returns the block height if the transaction with the specified ID exists. Otherwise, it returns a unit. See the function description in the [blockchain functions](https://decentralchain.io/docs/ride/functions#blockchain-functions) article. To check a transaction in a block on the external blockchain you can use the following built-in Ride function: ```none createMerkleRoot(merkleProofs: List[ByteVector], valueBytes: ByteVector, index: Int): ByteVector ``` This function is applicable if the external blockchain uses the same algorithm for calculating the root hash of transactions. The createMerkleRoot function calculates the root hash from the transaction hash and sibling hashes of the merkle tree (see Steps 1–3). To check a transaction in a block, compare the calculated root hash with the transactionsRoot value in the block header. --- # Node Source: https://decentralchain.io/docs/decentralchain/node A node is a host connected to the blockchain network. Node functions are: - [Block](https://decentralchain.io/docs/decentralchain/block#block) storage. - [Transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation). - Sending [transactions](https://decentralchain.io/docs/decentralchain/transaction#transaction). ## Generating Node Generating node is a node that generates blocks. Each generating node is a [validating node](https://decentralchain.io/docs/decentralchain/node#validating-node). Generating account is an [account](https://decentralchain.io/docs/decentralchain/account#account) that a node uses for [signing](https://decentralchain.io/docs/decentralchain/block#block-signature) generated blocks. A node can generate blocks if the following conditions are met: - The node's generating balance is at least 10000 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). This means that the account balance in DecentralCoins, taking into account leasing, was not less than 10000 DecentralCoins in each of the last 1000 blocks (more details in the [account balance](https://decentralchain.io/docs/decentralchain/account#account-balance) article). The greater the generating balance, the higher is your chance of being eligible to generate the next block. - Node's account is not a [smart account or dApp](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account). - Block generation is not disabled in node settings. By default, block generation is enabled. - The node is connected to at least the number of peers specified in the required parameters (1 by default). ## Validating Node A validating node is a node that [validates](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation) transactions. ## Generator’s Income A node's income from adding a new block to the blockchain consists of the following amounts: 1. Block reward: The current reward size is 6 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) but it can be changed by voting, see the [block reward](https://decentralchain.io/docs/decentralchain/node#block-reward) article. 2. 40% of the total transaction fees in the current block. The exact value is calculated as follows: - sum_{i}^{} 2 * (frac{f_i}{5}) - Here f _i is the fee for the i-th transaction. For each transaction fee, an integer division by 5 is performed, then a multiplication by 2, and finally they are summed up. 3. 60% of the total transaction fees in the previous block. - sum_{i}^{} (f_i - 2 * (frac{f_i}{5})) - The block generator receives exactly the part of the fee that the previous block generator did not receive. If the [transaction fees](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) are specified in a sponsored asset, then the block generators receive the fee equivalent in DecentralCoins instead of the fee (as a general rule, in a frac{40}{60} ratio): ```none feeInDecentralCoins = feeInSponsoredAsset × 0.001 / minSponsoredAssetFee ``` minSponsoredAssetFee is the amount of the sponsored asset equivalent to 0.001 DecentralCoins. The sponsor sets this value when enabling sponsorship. For details, see the [sponsored fees](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees) article. ## Block Reward Block reward is a blockchain feature under which [generating nodes](https://decentralchain.io/docs/decentralchain/node#generating-node) receive a fixed fee in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) for each [generated block](https://decentralchain.io/docs/decentralchain/block#block-generation). Block rewards are paid due to the additional issue of the DecentralCoin token. The community of generating nodes can change the size of reward through voting. ### Current Reward Size You can view the current reward size by making a request to the Node REST API. In response to the request, a JSON file is returned, the value of the currentReward field of which is the current block reward size in Decentralites. Example of response: ```none { "height": 1742254, "totalDecentralCoinsAmount": 10001353000000000, "currentReward": 600000000, "minIncrement": 50000000, "term": 100000, "nextCheck": 1839999, "votingIntervalStart": 1830000, "votingInterval": 10000, "votingThreshold": 5001, "votes": { "increase": 0, "decrease": 0 } } ``` In the example above, the value of the JSON's currentReward field is 600,000,000 Decentralites— i.e. it's 6 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). ### The Change of Block Reward Size Over Time Every 100,000 blocks, i.e. approximately every 70 days, a new voting for the current reward size change begins among the generators. The voting duration is 10,000 blocks. During this time, generating nodes vote to increase, decrease or leave the current reward size unchanged. The elected reward size remains unchanged for 100,000 blocks following the end of voting. ### Voting A generating node specifies the new desired reward size via settings in the node configuration file, the setting value is specified in Decentralites. If the value is greater than the current reward size, then the generator votes for the current reward size increase; if the value is smaller — for the decrease. If the setting value is not specified in the configuration file, then the generator votes for keeping the current reward size. When a node generates a block, it writes into that block the value of the desired reward size specified in the setting from its own node configuration file. If the setting value is not specified in the configuration file, then -1 is written to the block. During the voting time in 10,000 blocks, a single node can generate several blocks, therefore one node can vote several times. How often a node generates blocks is determined by the LPoS consensus. ### How Votes are Counted To count the votes, all 10,000 blocks generated during the voting period are inspected. If either -1 or the value that is equal to the current reward size is recorded to the block, then the generator votes for keeping the current reward size. If the value recorded to the block is greater than the current reward size, then the generator votes for the current reward size increase; if the value is smaller — for the decrease. The block reward is increased/decreased only if more than half of the 10,000 votes — i.e. 5,001 votes or more — were given for increase/decrease. The amount of the current reward is increased/decreased by 0.5 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). **Example 1** At the blockchain height of 2,000,000, the block reward equals 5 DecentralCoins. At the height of 2,090,000, another voting starts. During the 10,000 blocks of voting 6,000 votes were given for reward increase, 1,000 — for decrease, 3,000 — for keeping the current reward size. From the height of 2, 100,000 to the height of 2,199,999, the new reward size will be 5.5 DecentralCoins, because the reward change step is 0.5 DecentralCoins. The next voting will take place from the height of 2,190,000 to 2,199,999. **Example 2** At the blockchain height of 2,100,000, the block reward equals 5.5 DecentralCoins. At the height of 2,190,000, another voting starts. During the 10,000 blocks of voting 4,500 votes were given for reward increase, 4,000 — for decrease, 1,500 — for keeping the current reward size. From the height of 2,200,000 to the height of 2,299,999, the "new" reward size will be the same — 5.5 DecentralCoins. Although the highest number of votes were given for the reward increase, it was not enough to change the current reward size. In order for the current reward size to be increased, at least 5,001 votes must be given for the increase. The next voting will take place from the height of 2,290,000 to 2,299,999. ## Leased Proof of Stake Leased Proof of Stake (LPoS) is an enhanced type of proof of stake consensus algorithm by which the DecentralChain blockchain network aims to achieve the distributed consensus to secure the network. ### Leasing Benefits for the Node Owner [Nodes](https://decentralchain.io/docs/decentralchain/node#node) can use the leased tokens to generate blocks and get the [mining reward](https://decentralchain.io/docs/decentralchain/node#block-reward). For that purpose, the generating balance of a node must be at least 10000 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). ### Leasing Benefits for the Token Holder LPoS allows the token holders to lease their tokens to the DecentralChain nodes and earn a percentage of the payout as a reward. By using LPoS, lessors will be able to participate in the process of generating new blocks because the larger the amount that is leased to a DecentralChain node, the higher the chances for that node to be selected to generate the next block. If that node is selected, then the leaser will receive a reward. When the user starts leasing the tokens, those leased tokens are locked and remain in the same address with the full control of their owner (they are not transferred to the node, they just remain unspendable until the lease is canceled by the lessor). The only thing to consider when leasing is to choose the right node operator, as the operator's node may work with different efficiency and send back different percentages as rewards. #### Rewards - The node owner may send the lessor a part of the rewards according to his conditions. - The more transactions that are made on the network, the more rewards the lessors get. - These rewards mostly are in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) but also they can be in the form of different tokens with the unique DecentralCoins feature where different tokens can be accepted as a fee. ### LPoS Transactions To start leasing, the token holder needs to create a lease transaction and specify the recipient address (node address) along with the amount of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to lease. There are two types of transactions which are used in the LPoS: - [Lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction) to activate the leasing process. - [Lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction) to deactivate the leasing process. ### Create a Lease You can use [Decentral.Exchange](https://decentral.exchange/) online to create a lease. - Make sure you are logged into your account. On the main screen navigate to Wallet > Leasing. - On the next screen click Start Lease and then select the recipient between the list of nodes and indicate the amount you want to lease. - Verify all the information and click Start Lease again to confirm. --- # Order Source: https://decentralchain.io/docs/decentralchain/order Order is the instruction from the [account](https://decentralchain.io/docs/decentralchain/account#account) to matcher to buy or sell a [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) on the exchange. ## Asset Pair Each order contains amount asset / price asset pair, also called asset pair. **Example** ```none "assetPair": { "amountAsset": "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2", "priceAsset": "null" } ``` **Asset Pair Fields** **Asset Pair Fields** | Field name | Description | | --- | --- | | amountAsset | ID of the pair's first asset, that the order's sender wants to buy or sell. | | priceAsset | ID of the pair's second asset, in which the price of the order is expressed. null value means that asset is [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | ## Order's Amount and Price In the user interface, the amount and price are usually presented as values with a fractional part (for example, 0.74585728 DecentralCoins), i.e. in the denormalized form. The denormalized form is convenient for humans, but not for calculations. To solve the problem of calculation accuracy, the normalization is performed. In the user interface, the amount and price are usually presented as values with a fractional part (for example, 0.74585728 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin)), i.e. in the denormalized form. The denormalized form is convenient for humans, but not for calculations. To solve the problem of calculation accuracy, the normalization is performed, i.e. amount and price are represented as an integer. So, 0.74585728 DecentralCoins is 0.74585728 × 10^{8} or 74585728 Decentralites. In this case, the exponent is 8, because DecentralCoins has 8 decimals after the decimal point. Other assets may have different amount of decimals. For example, TDX has 2 decimals. ### Amount Consider buying 2.13 TDX at the price of 0.35016774 DecentralCoins for one TDX. Here the asset pair is TDX / DecentralCoins. The amount in the order is the number of units sold or bought in conventional "pennies". This value in the current case is 213, since 2.13 TDX = 2.13 × 10^{2} = 213` "pennies" of TDX. So, to bring the amount to the normalized form, it is multiplied by 10^{amountAssetDecimals}. ### Price Price is the value of 1 unit of the amount asset, expressed in the price asset. In the TDX / DecentralCoins example above, this is the price in DecentralCoins for 1 TDX. To normalize price, it is multiplied by: - In orders of versions 1, 2, 3: 10^{(8 + priceAssetDecimals - amountAssetDecimals)}. - In orders of version 4: at 10^{8}. The exponent of 8 is selected because there cannot be an asset with the exceeding quantity of decimals on the DecentralChain blockchain. The matcher algorithm has a limitation in relation to price: the last N digits of the normalized price must be zeros (N is price_decimals minus amount_decimals). If this is not so, then the matcher rejects the order on placement. ### Price Asset Quantity Calculation The quantity of price asset in normalized form which: - Will be given by sender if order is BUY. - Will be acquired by sender if order is SELL. Is calculated by the following formula: amount × price × 10^{(priceAssetDecimals - amountAssetDecimals - 8)}. - In orders of versions 1, 2, 3: amount × price × 10^{-8} - In orders of version 4: amount × price × 10^{(priceAssetDecimals - amountAssetDecimals - 8)}. If the result of the calculation is a value with a fractional part, then the fractional part is discarded. Designations in the above formula: - Amount — amount in normalized form. - Price — price in normalized form. - PriceAssetDecimals — the number of decimal places of the price asset. - AmountAssetDecimals — the number of decimal places of the amount asset. ## Order Cancellation The order sender may cancel the order before it is executed. Unexecuted orders are automatically canceled at the date and time specified by the order sender. ## Order Expiration Date Order expiration date is the date and time of automatic cancellation of an unexecuted order. The date is specified in milliseconds which have passed since the beginning of the unix epoch. The expiration time can't be earlier than matcher time + 1 minute and later than matcher time + 30 days. ## Order Timestamp Order timestamp is the time when the matcher added the order to the order book. The time is specified in milliseconds that have passed since the beginning of the unix epoch. ## Order Binary Format See the [order binary format](https://decentralchain.io/docs/decentralchain/binary-format#order-binary-format) page. --- # Oracle Source: https://decentralchain.io/docs/decentralchain/oracle Oracle is a data provider from the outside world on the blockchain. ## Sources of the Outside World Software oracles handle data accessible on the web. For example, the temperature, costs of products and merchandise, flight or train delays, etc. The information originates from online sources, e.g. API. The product prophet extricates the required data and pushes it into the blockchain. Hardware oracles track real-world objects with devices and sensors. For example, a video camera with an analytics function virtual line crossing tracks vehicles entering a specific zone. If an event is detected, the oracle writes about it on the blockchain. Based on the data of such oracle, some script of decentralized application on the blockchain may be triggered. In this case, for example, a fine and the write-off of tokens from the account of the vehicle owner. But it is not in oracle scope, it is in the scope of the script that is based on the data of such an oracle. Human oracles imply that the data is entered by a human being. ## Oracles Issue The oracle is a way of connecting the blockchain with the outside world. The major problem that is solved by the usage of oracles is the very point that blockchains can only access data that is stored on the blockchain. Here, in blockchain, the point is that it is important that decentralized applications can only access data that is stored on the blockchain so that every execution of the script leads to the same result at a given point in time. Therefore, decentralized applications are not able to access data from outside the blockchain, e.g., provided by web services or other external sources of data. Nevertheless, many interesting applications need access to the outside world, e.g., decentralized applications for insurances, decentralized betting systems, financial services and so forth. Here, the solution is quite straightforward: if external data is necessary for the execution of a decentralized application, this data needs to be stored on the blockchain. To achieve this, there are usually small programs implemented that access the necessary data and write it to the blockchain. Those little programs are called oracles. ## Consensus of Oracles One source may be unsafe if it does not have the authority or high rating. However, several oracles can be used to stay away from the monopoly and be safer. For example, get information from ten oracles and only if the data of 6 out of 10 oracles coincide, to accept them. This is the consensus of the oracles. --- # Mainnet, Testnet, Stagenet Source: https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet ## Connecting Node to Blockchain Network You can launch your node in any blockchain network. Select the network in the node configuration file. - For more information about the configuration file, see the node configuration article. - For installing a node, see the install DecentralChain node article. - For starting your own blockchain network, see the custom blockchain article. ## Chain ID Chain ID is a symbol that is passed over a network during a handshake and allows nodes not to connect to the nodes of other networks. The chain ID is used while building account addresses, therefore, an address on one blockchain network cannot be used on another network. The chain ID is also indicated in transactions so it is impossible to move transactions between different blockchain networks. **Chain ID** | Blockchain Network | Chain ID | | --- | --- | | Mainnet | W or 87 (ASCII code of W). | | Testnet | T or 84 (ASCII code of T). | | Stagenet | S or 83 (ASCII code of s). | ## Tools ### API of Pool of Public Nodes Chain ID is a symbol that is passed over a network during a handshake and allows nodes not to connect to the nodes of other networks. The chain ID is used while building account addresses, therefore, an address on one blockchain network cannot be used on another network. The chain ID is also indicated in transactions so it is impossible to move transactions between different blockchain networks. **API of Pool of Public Nodes** | | | | --- | --- | | Mainnet | https://mainnet-node.decentralchain.io | | Testnet | https://testnet-node.decentralchain.io | | Stagenet | TBA | ### Data Service API **Data Service API** | | | | --- | --- | | Mainnet | https://data-service.decentralchain.io | | Testnet | TBA | | Stagenet | TBA | ### Decentral.Exchange [Decentral.Exchange](https://decentral.exchange/) is a decentralized exchange. **Decentral.Exchange** | | | | --- | --- | | Mainnet | https://decentral.exchange/ | | Testnet | TBA | | Stagenet | TBA | ### API of Decentral.Exchange Matcher The addresses for order sending and market data obtaining are as follows: **API of Decentral.Exchange Matcher** | | | | --- | --- | | Mainnet | https://mainnet-matcher.decentralchain.io/api-docs/index.html | | Testnet | https://matcher.decentralchain.io/api-docs/index.html | | Stagenet | TBA | ### DecentralChain Explorer DecentralChain Explorer is a service for browsing blockchain data. **DecentralChain Explorer** | | | | --- | --- | | Mainnet | Go to http://decentralscan.com/ and click the three lines, then switch to Mainnet. | | Testnet | Go to http://decentralscan.com/ and click the three lines, then switch to Testnet. | | Stagenet | Go to http://decentralscan.com/ and click the three lines, then switch to Stagenet. | ### Faucet: Obtaining Tokens **Faucet: Obtaining Tokens** | | | | --- | --- | | Mainnet | | | Testnet | TBA | | Stagenet | TBA | --- # Protocol Source: https://decentralchain.io/docs/decentralchain/protocol ## Cryptographic Practical Details ### Description This section describes all the details of cryptographic algorithms which are used to: - Create private and public keys from seed. - Create addresses from public keys. - Create blocks and transactions signing. We use Blake2b256 and Keccak256 algorithms (in the form of hash chain) to create cryptographic hashes. And Curve25519 (ED25519 with X25519 keys) to create and verify signatures. Base58 to create the string form of bytes. ### Bytes Encoding Base58 All arrays of bytes in the project are encoded by Base58 algorithm with Bitcoin alphabet to make it ease human readable (text readability). **Example** The string teststring is coded into the bytes [5, 83, 9, -20, 82, -65, 120, -11]. The bytes [1, 2, 3, 4, 5] are coded into the string 7bWpTW. ### Creating a Private Key From a Seed A seed string is a representation of entropy, from which you can re-create deterministically all the private keys for one wallet. It should be long enough so that the probability of selection is an unrealistic negligible. In fact, seed should be an array of bytes but for ease of memorization lite wallet uses Brainwallet, to ensure that the seed is made up of words and easy to write down or remember. The application takes the UTF-8 bytes of the string and uses them to create keys and addresses. For example, ```none seed string manage manual recall harvest series desert melt police rose hollow moral pledge kitten position add ``` After reading this string as UTF-8 bytes and encoding them to Base58, the string will be coded as: ```none xrv7ffrv2A9g5pKSxt7gHGrPYJgRnsEMDyc4G7srbia6PhXYLDKVsDxnqsEqhAVbbko7N1tDyaSrWCZBoMyvdwaFNjWNPjKdcoZTKbKr2Vw9vu53Uf4dYpyWCyvfPbRskHfgt9q ``` A seed string is involved with the creation of private keys. To create a private key using the official web wallet or the node, to 4 bytes of int 'nonce' field (big-endian representation), which initially has a value of 0 and increases every time you create the new address, should be prepended to seed bytes. Then we use this array of bytes to calculate hash keccak256(blake2b256(bytes)). This resulting array of bytes we call account seed, from it you can definitely generate one private and public key pair. Then this bytes hash passed in the method of creating a pair of public and private key of Curve25519 algorithm. DecentralChain uses Curve25519-ED25519 signature with X25519 keys (montgomery form), but most embedded cryptography devices and libraries don't support X25519 keys. There are libraries with conversion functions from: - ED25519 keys to X25519 (Curve25519) crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, ed25519_pk) for public key. - Crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, ed25519_skpk) for private key. NOTE: Not all random 32 bytes can be used as private keys (but any bytes of any size can be a seed). The signature scheme for the ED25519 introduces restrictions on the keys, so create the keys only through the methods of the Curve25519 libraries and be sure to make a test of the ability to sign data with a private key and then check it with a public key, however obvious this test might seem. There are valid Curve25519 realizations for different languages: - [Java](https://github.com/signalapp/curve25519-java/) - [C](https://github.com/signalapp/curve25519-java/tree/master/android/jni) - [Python](https://github.com/tgalal/python-axolotl-curve25519) Also some Curve25519 libraries (as the one used in our project) have the Sha256 hashing integrated, some not (such as most of c/c++/python libraries), so you may need to apply it manually. Note that the private key is clamped, so not any random 32 bytes can be a valid private key. **Example** Brainwallet seed string ```none manage manual recall harvest series desert melt police rose hollow moral pledge kitten position add ``` As UTF-8 bytes encoded ```none xrv7ffrv2A9g5pKSxt7gHGrPYJgRnsEMDyc4G7srbia6PhXYLDKVsDxnqsEqhAVbbko7N1tDyaSrWCZBoMyvdwaFNjWNPjKdcoZTKbKr2Vw9vu53Uf4dYpyWCyvfPbRskHfgt9q ``` Account seed bytes with nonce 0 before apply hash function in Base58 ```none 1111xrv7ffrv2A9g5pKSxt7gHGrPYJgRnsEMDyc4G7srbia6PhXYLDKVsDxnqsEqhAVbbko7N1tDyaSrWCZBoMyvdwaFNjWNPjKdcoZTKbKr2Vw9vu53Uf4dYpyWCyvfPbRskHfgt9q ``` blake2b256(account seed bytes) ```none 6sKMMHVLyCQN7Juih2e9tbSmeE5Hu7L8XtBRgowJQvU7 ``` Account seed ( keccak256(blake2b256(account seed bytes))) ```none H4do9ZcPUASvtFJHvESapnxfmQ8tjBXMU7NtUARk9Jrf ``` Account seed after Sha256 hashing (optional, if your library does not do it yourself) ```none 49mgaSSVQw6tDoZrHSr9rFySgHHXwgQbCRwFssboVLWX ``` Created private key ```none 3kMEhU5z3v8bmer1ERFUUhW58Dtuhyo9hE5vrhjqAWYT ``` Created public key ```none HBqhfdFASRQ5eBBpu2y6c6KKi1az6bMx8v1JxX4iW1Q8 ``` ### Creating Address from a Public Key Our network address obtained from the public key depends on the byte chainID ('T' for Testnet, 'W' for Mainnet, 'S' for Stagenet), so different networks obtained a different address for a single seed (and hence public keys). **Example** For the public key: ```none HBqhfdFASRQ5eBBpu2y6c6KKi1az6bMx8v1JxX4iW1Q8 ``` Created public key: ```none 3PPbMwqLtwBGcJrTA5whqJfY95GqnNnFMDX ``` ### Signing Curve25519 is used for all the signatures in the project. The process is as follows: create the special bytes for signing for transaction or block, then create a signature using these bytes and the private key bytes. For the validation of signatures it’s enough with signature bytes, signed object bytes and the public key. Do not forget that there are many valid (not unique!) signatures for a one array of bytes (block or transaction). Also you should not assume that the ID of the block or transaction is unique. The collision can occur one day! They have already taken place for some weak keys. **Example** Transaction Data: **Transaction Data** | Field | Value | | --- | --- | | Sender address (not used, just for information) | 3N9Q2sdkkhAnbR4XCveuRaSMLiVtvebZ3wp | | Private key (used for signing, not in tx data) | 7VLYNhmuvAo5Us4mNGxWpzhMSdSSdEbEPFUDKSnA6eBv | | Public key | EENPV1mRhUD9gSKbcWt84cqnfSGQP5LkCu5gMBfAanYH | | Recipient address | 3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8 | | Asset id | BG39cCNUFWPQYeyLnu7tjKHaiUGRxYwJjvntt9gdDPxG | | Amount | 1 | | Fee | 1 | | Fee asset id | BG39cCNUFWPQYeyLnu7tjKHaiUGRxYwJjvntt9gdDPxG | | Timestamp | 1479287120875 | | Attachment (as byte array) | 1[1, 2, 3, 4] | Bytes: **Bytes** | # | Field name | Type | Position | Length | Value | Base58 bytes value | | --- | --- | --- | --- | --- | --- | --- | | 1 | Transaction type (0x04) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 0 | 1 | 4 | 5 | | 2 | Sender's public key | Bytes | 1 | 32 | ... | EENPV1mRhUD9gSKbcWt84cqnfSGQP5LkCu5gMBfAanYH | | 3 | Amount's asset flag (0-DecentralCoins, 1-Asset) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 33 | 1 | 1 | 2 | | 4 | Amount's asset ID (*if used) | Bytes | 34 | 0 (32*) | ... | BG39cCNUFWPQYeyLnu7tjKHaiUGRxYwJjvntt9gdDPxG | | 5 | Fee's asset flag (0-DecentralCoins, 1-Asset) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 34 (66*) | 1 | 1 | 2 | | 6 | Fee's asset ID (**if used) | Bytes | 35 (67*) | 0 (32**) | ... | BG39cCNUFWPQYeyLnu7tjKHaiUGRxYwJjvntt9gdDPxG | | 7 | Timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 35 (67_ ) (99*_ ) | 8 | 1479287120875 | 11frnYASv | | 8 | Amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 43 (75_ ) (107*_ ) | 8 | 1 | 11111112 | | 9 | Fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 51 (83_ ) (115*_ ) | 8 | 1 | 11111112 | | 10 | Recipient's address | Bytes | 59 (91_ ) (123*_ ) | 26 | ... | 3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8 | | 11 | Attachment's length (N) | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 85 (117_ ) (149*_ ) | 2 | 4 | 15 | | 12 | Attachment's bytes | Bytes | 87 (119_ ) (151*_ ) | N | [1,2,3,4] | 2VfUX | Total data bytes for sign ```none Ht7FtLJBrnukwWtywum4o1PbQSNyDWMgb4nXR5ZkV78krj9qVt17jz74XYSrKSTQe6wXuPdt3aCvmnF5hfjhnd1gyij36hN1zSDaiDg3TFi7c7RbXTHDDUbRgGajXci8PJB3iJM1tZvh8AL5wD4o4DCo1VJoKk2PUWX3cUydB7brxWGUxC6mPxKMdXefXwHeB4khwugbvcsPgk8F6YB ``` Signature of transaction data bytes (one of an infinite number of valid signatures) ```none 2mQvQFLQYJBe9ezj7YnAQFq7k9MxZstkrbcSKpLzv7vTxUfnbvWMUyyhJAc1u3vhkLqzQphKDecHcutUrhrHt22D ``` Total transaction bytes with signature: ```none 6zY3LYmrh981Qbzj7SRLQ2FP9EmXFpUTX9cA7bD5b7VSGmtoWxfpCrP4y5NPGou7XDYHx5oASPsUzB92aj3623SUpvc1xaaPjfLn6dCPVEa6SPjTbwvmDwMT8UVoAfdMwb7t4okLcURcZCFugf2Wc9tBGbVu7mgznLGLxooYiJmRQSeAACN8jYZVnUuXv4V7jrDJVXTFNCz1mYevnpA5RXAoehPRXKiBPJLnvVmV2Wae2TCNvweHGgknioZU6ZaixSCxM1YzY24Prv9qThszohojaWq4cRuRHwMAA5VUBvUs ``` ### Calculating Transaction ID Transaction ID is not stored in the transaction bytes and for most transactions (except Payment) it can be easily calculated from the special bytes for signing using blake2b256(bytes_for_signing). For payments, the transaction ID is just the signature of this transaction. ## DecentralChain-M5 Solution ### Reasoning The maximum rate of transactions in blockchain systems is limited by the choice of two parameters: block size and block interval. The block interval defines the average amount of time that passes between the creation of two blocks. If we reduce this time, forks will appear more frequently, which will lead to either non-resolved forks or to decreased throughput since a considerable amount of time would be spent on resolving these forks. Larger blocks lead to huge network usage spikes during block propagation, which in turn will lead to throughput problems and huge forks. #### DecentralChain-M5 Solution With Technical Details DecentralChain addresses this issue by allowing the miner to continuously farm a block during the time of mining. This continuously increasing block is called liquid block, which becomes immutable when the next block referencing it is built and appended. A liquid block consists of a key block and chain of microblocks. The process of creating liquid block goes as follows: - When a miner node observes it has the right to create a block, it creates and sends keyBlock, which is regularly just an empty block. - After that, it creates and sends microblocks every 3 seconds. Microblock is very similar to a regular block: it's a non-empty pack of transactions, which references its parent: previous microblock or key block. - Microblocks are continuously mined and propagated to the network until a new key block, referencing the current liquid block appears. #### Microblock Structure ```none generator: PublicKeyAccount transactionData: Seq[Transaction] prevResBlockSig: BlockId totalResBlockSig: BlockId signature: ByteStr ``` totalResBlockSig is the new total signature of a block with all transactions from blockId=prevResBlockSig and transactionData. This means that having a liquid block consisting of 1 keyblock and 3 microblocks: KEYBLOCK() <-MICRO1(tx1,tx2) <-MICRO2(tx3,tx4) <-MICRO3(tx5,tx6) We have 4 versions of last block: **Microblock Structure** | ID | Transactions | | --- | --- | | KEYBLOCK.uniqueId | | | MICRO1.totalResBlockSig | tx1,tx2 | | MICRO2.totalResBlockSig | tx1,tx2,tx3,tx4 | | MICRO3.totalResBlockSig | tx1,tx2,tx3,tx4,tx5,tx6 | Next miner can reference any of these ids in its keyBlock. ### Economy For a miner, it might seem a good idea to reference KEYBLOCK from previous example and pack all txs from microblocks to its own (micro)block(s). In order to make 'stealing' transactions less profitable than referencing the best-known version of liquid block(= the last known microblock), we change the mechanics of fees: After activating M5, miner will receive 40% of fees from the block it creates and 60% of fees from the block he references. ### Related Protocol Changes - A block can contain up to 65535 transactions and doesn't require transaction sorting. - By default miners will first create an empty key block. It's a regular block, propagated byBlockForgedmessage, but it now gets broadcasted if it's empty. - Microblocks are propagated by broadcasting its header for every node which applied it (MicroBlockInv)MicroBlockInv contains a verifiable signature to prevent a node from being flooded. Microblock will be requested afterward via MicroBlockRequestand received back withinMicroBlockResponse.Microblocks will be re-requested from another node which has it if a node doesn't respond. ### Configuration The following miner parameters can be tuned(though it's best not to change them in order to maximize final version of your liquid block in the resulting blockchain): - KeyBlock size (maxTransactionsInKeyBlock, default = 0). If changed, it won't be rebroadcasted and the usual extension requesting mechanics will be used. - Microblock mining interval (microBlockInterval, default = 3 s). - Max amount of transactions per microblock (maxTransactionsInMicroBlock, default = 200). - Miner will try to reference the best-known microblock with at leastminMicroBlockAgeage(default = 3 s). This is required in order for a miner to reference already-propagated block so its key block doesn't get orphaned. - Microblock synchronization mechanism can be tuned with waitResponseTimeout(default = 2 s), processedMicroBlocksCacheTimeout(default = 10 s),invCacheTimeout(default = 10 s) which are basically time of awaiting a microblock and times to cache a processed microblock ids and a list of nodes which have a microblock(by id). ### API changes - Upon applying every microblock, the last block gets changed, which means/blocks/lastand/blocks/at/...will reflect that. - /peers/blacklistednow expose ban reason, one can clear a node's blacklist via/peers/clearblacklist - /debug/and/consensus/section are expanded, stateHash doesn't take liquid block into consideration. ## DecentralChain-M5 Protocol ### Scalability Limits and Challenges in Current Blockchain Systems #### Problem Statement and Motivation Blockchains protocols have some scalability limits and challenges that tradeoff between throughput and latency. The current blockchain technology is not fast enough and does not scale to include more transactions into the system so we have a performance challenge to be considered. There is a united agreement between miners, consumers, and developers with several perspectives that we need to deploy scalability measures, and there has been an ongoing argument on how to improve Bitcoin’s scalability. Current proposals have focused on how big to make the blocks and how to handle the block size increases in the future. All proposals suffer from a major scalability bottleneck: No matter what block size is chosen, the blockchain system can at best reach a proper transaction throughput, increasing from ~ 3 transactions per second to ~ 7 transactions per second. This is so far from the 30,000 transactions per second which are necessary to compete with the existing systems such as VISA transactions. The same major limitations apply to litecoin, Ethereum, and all other currencies that share Bitcoin’s blockchain protocol. DecentralChain-M5 will address the scalability bottleneck by making the network reach the highest throughput depending on the network conditions. It will not only enhance the transaction throughput, it will also reduce transaction latencies. So it will be possible to get an initial transaction confirmation in seconds rather than in minutes. #### Weaknesses of Current Proposals to Improve Scalability Blockchain Systems can process transactions and the maximum rate of these transactions is limited by the choice of two parameters: block size and block interval. - The block interval defines the average amount of time that passes between the creation of two blocks. By deciding to reduce the block interval to solve the latency limit, the system will have less security (increase forks probability) due to the reason of new miners for every second which will lead to instability where the blockchain is subject to reorganization and the system is in disagreement (Figure 1). If we reduce the time per block, then we will have a situation where a significant number of blocks are solved in less time than it takes to relay a solved block throughout the network. So there will be no way to know which block is the "real" one and which one is a "fork" because the transactions that appeared to have multiple confirmations suddenly have fewer confirmations (or possibly go back to being unconfirmed). ![](https://decentralchain.io/docs/12_Weaknesses-of-Current-Proposals-to-Improve-Scalability-1.png) Figure 1: Increasing block frequency with static block size will result in less security. - The throughput of a system is bounded by the maximum block size (given a fixed block interval), as the maximum number of included transactions is directly dependent on the block size. - Larger blocks do however cause slower propagation speeds, which causes more discarded blocks (orphaning risk). An unlimited blocksize could, for example, result in a DoS attack on the system by creating a block that takes a long time to validate. If the choice is to Increase block size in order to improve throughput, there will be Network spikes with longer time to propagate in the network (Figure 2). ![](https://decentralchain.io/docs/13_Weaknesses-of-Current-Proposals-to-Improve-Scalability-2.png) Figure 2: Increasing block size with Static block frequency will lead to more discarded blocks and network spikes. #### Brief Summary of Bitcoin-M5 It is a next-generation blockchain protocol which is an alternative bitcoin scaling solution that does not involve increasing the size of blocks or decreasing the block time interval. This reduces the risk of forks amongst other advantages. Bitcoin-M5 describes that the basic tradeoffs in Bitcoin can be reduced with an alternative blockchain protocol, offering a consensus delay and bandwidth limited only by the Network Plane. The protocol splits time into time periods(epoch). In each time period, a particular leader is responsible for serializing transactions (Figure 3). The leaders take the rule of generating blocks: - Key blocks for the election of a leader. - Micro blocks for ledger records. ![](https://decentralchain.io/docs/14_Brief-Summary-of-Bitcoin-M5.png) Figure 3: Bitcoin-M5 time periods structure with serializing transactions. ### DecentralChain-M5 Overlay DecentralChain-M5 is based on the bitcoin next generation protocol that serializes transactions and offers important improvements in the transaction latency(lower latency) and bandwidth(higher throughput) in comparison to Bitcoin without sacrificing other properties. DecentralChain approaches this scalability matter by providing the miner with the ability to farm a block during the time of mining in a continuous approach. This block continues increments called liquid blocks. This liquid block is unchangeable over time once the next block referencing is created and appended. This approach increases effective bandwidth and speed of block creation, which is described as being “especially significant for businesses” using the DecentralChain-M5 protocol since it allows for conducting micro-transactions - without any delays that are typical with traditional blockchain systems. Furthermore, it allows the blockchain to withstand high loads, such as distribution of tokens following crowdsales and airdrops of bonus tokens. The speed of processing trading transactions on the exchange gets increased as well. #### DecentralChain-M5 Operations The main and core idea of DecentralChain-M5 is to split the Liquid block into two types, Key blocks and Micro blocks. The process of creating liquid block works as follows: - The miner node gets the permission to create a block. - The miner node creates and sends the key block (which does not contain transactions). - The miner node creates and sends the micro blocks (which contain transactions just as in normal blocks with a reference to previous micro blocks or key blocks) with a mining time interval of three seconds. - Miners will mine those micro blocks and propagate them directly to the network until the next new key block appears with a reference to the liquid block. All of the transactions are part of the same block and are contributed all together. In between blocks, the traditional Bitcoin system appears idle to an onlooker, as miners are working to discover the next block, but without apparent progress on the consensus front. In contradiction, in DecentralChain-M5, the key-blocks can be small because they need to contain only the coinbase transaction, which defines the public key that the miner will be using to sign microblocks. Because a key-block requires proof of stake, miners can not just produce one and expropriate the leadership at will. Following the key-block, the lead miner can quickly issue microblocks, simply by signing them with the private key corresponding to the public key named in the key-block’s coinbase (Figure 4). ![](https://decentralchain.io/docs/15_DecentralChain-M5-Operations.png) Figure 4: Key-blocks and Micro-blocks signing process. **Leader Blocks** They’re also called "Key Blocks", these blocks are generated with proof of stake but do not contain transactions. They serve as a leader election mechanism and contain a public key that identifies the chosen leader. Each block has a header that contains, among other fields, the unique reference of its predecessor which is a cryptographic hash of the predecessor header (either a key block or a microblock). **Micro Blocks** Once a node generates a key block it becomes the leader. As a leader, the node is allowed to generate microblocks at a set rate smaller than a predefined maximum. These micro blocks will contain the ledger entries with no requirement for any Proof of Stake and they're generated by the elected leader in every block-generation cycle. This block-generation cycle is initiated by a leader block. The only requirement is to sign the micro blocks with the elected leader's private key. The micro blocks can be generated at a very high speed by the elected leader(miner), thus resulting in increased performance and transaction speed. For a microblock to be valid, all its entries must be valid according to the specification of the state machine, and the signature has to be valid. Figure 5 illustrates the structure. Note that microblocks do not affect the weight of the chain, as they do not contain proof of stake. When all micro blocks have been validated, they will be merged with their key block into one block. #### DecentralChain-M5 Reward Mechanisms Remuneration consists of two parts. First, each key block entitles its generator a set amount. Second, each ledger entry carries a fee. This fee is split by the leader that places this entry in a microblock and the subsequent leader that generates the next key block. In order to motivate participants to follow the protocol, DecentralChain-M5 uses the following mechanisms: Each transaction pays a fee to the system, but unlike Bitcoin, this fee is distributed, with 40% to the leader, and 60% to the subsequent leader. Finally, if a leader forks the chain by generating two microblocks with the same parent, it is punished by revoking the subsidy revenue; whoever detects the fraud wins a nominal fee, (Figure 5). ![](https://decentralchain.io/docs/16_DecentralChain-M5-Reward-Mechanisms.png) Figure 5: chain structure of the DecentralChain-M5 Protocol. Microblocks (circles) are signed with the private key matching with the public key in the last key block (squares). The fee is distributed 40% to the leader and 60% to the next one. In practice, the remuneration is implemented by having each key block contain a single coinbase transaction that mints new coins and deposits the funds to the current and previous leaders. As in Bitcoin, this transaction can only be spent after a maturity period of 100 key blocks, to avoid non-mergeable transactions following a fork. ## Fair Proof of Stake In this model, the choice of account that has the right to generate the next block and receive the corresponding transaction fees is based on the number of tokens in the account. The more tokens that are held in the account, the greater the chance that account will earn the right to generate a block. In DecentralChain, we are convinced that each participant in the blockchain should participate in the block generation process proportionally to his stake: we have decided to correct the PoS formula. At the moment we do not have the goal of completely changing the algorithm, since there is no need; we simply want to make some adjustments. We presented an improved PoS algorithm that makes the choice of block creator fair and reduces vulnerability to the multi-branching attacks, in accordance with the shortcomings of the current algorithm. We analyzed the model of the new algorithm for its correspondence to the stake share and the share of blocks, and the results were positive. Also, the algorithm was analyzed for vulnerability to attacks, and results obtained with the new model were better than with the old one. The attacks’ results for the attacker were not so successful in terms of the profits gained. The number of forks and their length decreased. ## Blockchain Data Types The blockchain data types are the data types that are used to describe the [binary format](https://decentralchain.io/docs/decentralchain/binary-format#binary-format) of blockchain entities. Here’s a list of blockchain data types: **Blockchain Data Types** | # | Keyword | Possible values | Variable size in bytes | | --- | --- | --- | --- | | 1 | Boolean | 0 and 1. | 1 | | 2 | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Integer from -128 to 127 inclusive. | 1 | | 3 | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Integer from -2,147,483,648 to 2,147,483,647 inclusive. | 4 | | 4 | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Integer from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 inclusive. | 8 | | 5 | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Integer from -32,768 to 32,767 inclusive. | 2 | | 6 | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | From 0 to 2,147,483,647 characters inclusive. | From 1 to 4 bytes per character. | ## Validation Rules ### Account Validation Account is valid then it is a valid Base58 string and the length of the corresponding array is 26 bytes. Version of address (1st byte) is equal to 1. The network byte (2nd byte) is equal to network ID. The checksum of address (last 4 bytes) is correct. ### Transactions Validation #### Transfer Transaction Validation Transfer transaction is valid then: - Recipient address is valid. If not, InvalidAddress validation result will be returned. - Size of attachment is less than or equals MaxAttachementSize(140 bytes). In other case TooBigArray validation result will be returned. - Transaction's amount is more than 0, otherwise NegativeAmount validation result is returned. - Transaction's fee is positive, otherwise InsufficientFee validation result is returned. - Adding fee to amount does not lead to Long overflow. In case of Long overflow OverflowError validation result will be returned. - Transaction's signature is valid, otherwise InvalidSignature validation result is returned. #### Issue Transaction Validation Issue transaction is valid then: - Sender's address is valid. If not, InvalidAddress validation result will be returned. - Quantity of asset is positive, otherwise NegativeAmount validation result is returned. - Transaction's fee is more than or equals MinFee(100000000 Decentralites = 1 DecentralCoin), in other case InsufficientFee validation result is returned. - Size of description is less than or equals MaxDescriptionLength(1000 bytes), otherwise TooBigArray is returned. - Size of name is more than or equals MinAssetNameLength and less or equals MaxAssetNameLength, in other case InvalidName validation result will be returned. - Decimals is positive and less than or equals MaxDecimals, in other case TooBigArray is returned. - Transaction's signature is valid, otherwise InvalidSignature validation result is returned. #### Reissue Transaction Validation Reissue transaction is valid then: - Sender's account is valid. Otherwise InvalidAddress validation result is returned. - Quantity is positive, in other case NegativeAmount validation result will be returned. - Transaction's fee is positive, in other case InsufficientFee result will be returned. - Transaction's signature is valid, otherwise InvalidSignature validation result is returned. ### Block Validations Block is valid then: - Block chain contains referenced blocks. - Block's signature is valid. - Block's consensus data is valid. - Block's transactions are valid. #### Consensus Data Validation Block's consensus data is valid then: - Block creation time is no more than MaxTimeDrift(15 seconds) in future. - Block's transactions are sorted. This rule works only after 1477958400000 on Testnet and 1479168000000 on Mainnet. - Block chain contains parent block or block chain height is equal 1. - Block's base target is valid. - Block's generator signature is valid. - Generator's balance is more than or equals MinimalEffectiveBalanceForGeneration(1000000000000 Decentralites). This rule always works on Testnet and works only after 1479168000000 on Mainnet. - Block's hit is less than calculated block's target. - Voted features are sorted in ascending order and are not repeated. #### Transactions Data Validation Block's transactions are valid then: - Creation time of every transaction in block is less than block's creation time no more than on MaxTxAndBlockDiff(2 hours). - All transactions are valid against state. Transaction validation against state. Transactions are valid then: - Transaction is valid by transaction validation rules. - Transaction creation time more than block's creation time no more than on MaxTimeForUnconfirmed(90 minutes). This limitation works always on Testnet and only after 1479168000000 on Mainnet. - Application of transaction to accounts should not lead to temporary negative balance. This rule works after 1479168000000 on Mainnet and after 1477958400000 on Testnet. - Changes made by transaction should be sorted by their amount. This rule works on both Mainnet and Testnet after 1479416400000. - Application of transaction's amount to current balance should not lead to Long overflow. - After application of all block's transactions affected balances should not be negative. ### Unconfirmed Transactions Pool Validation Transaction could be inserted in unconfirmed transactions pool then: - Transaction is valid by transaction validation rules. - If transaction's fee is more than or equals minimum fee that was set by the owner of a node. - There is a space for a new transaction if unconfirmed transactions pool. By default the pool is limited by 1000 transactions. - unconfirmed transactions pool does not contain transaction with the same ID. - Transaction created not later than MaxTimeForUncofimed(90 minutes) after the last block was created. - Transaction creation time is no more than MaxTimeDrift(15 seconds) in future. - Transaction is valid against state. --- # Binary Format Source: https://decentralchain.io/docs/decentralchain/binary-format - [Address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format) - [Alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) - [Block binary format](https://decentralchain.io/docs/decentralchain/binary-format#block-binary-format) - [Network message binary format](https://decentralchain.io/docs/decentralchain/binary-format#network-message-binary-format) - [Block message binary format](https://decentralchain.io/docs/decentralchain/binary-format#block-message-binary-format) - [Checkpoint message binary format](https://decentralchain.io/docs/decentralchain/binary-format#checkpoint-message-binary-format) - [Get block message binary format](https://decentralchain.io/docs/decentralchain/binary-format#get-block-message-binary-format) - [Get peers message binary format](https://decentralchain.io/docs/decentralchain/binary-format#get-peers-message-binary-format) - [Get signatures message binary format](https://decentralchain.io/docs/decentralchain/binary-format#get-signatures-message-binary-format) - [Handshake message binary format](https://decentralchain.io/docs/decentralchain/binary-format#handshake-message-binary-format) - [Peers message binary format](https://decentralchain.io/docs/decentralchain/binary-format#peers-message-binary-format) - [Score message binary format](https://decentralchain.io/docs/decentralchain/binary-format#score-message-binary-format) - [Signatures message binary format](https://decentralchain.io/docs/decentralchain/binary-format#signatures-message-binary-format) - [Transaction message binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-message-binary-format) - [Order binary format](https://decentralchain.io/docs/decentralchain/binary-format#order-binary-format) - [Transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-binary-format) - [Burn transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#burn-transaction-binary-format) - [Create alias transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#create-alias-transaction-binary-format) - [Data transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#data-transaction-binary-format) - [Exchange transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#exchange-transaction-binary-format) - [Genesis transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#genesis-transaction-binary-format) - [Invoke script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#invoke-script-transaction-binary-format) - [Issue transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#issue-transaction-binary-format) - [Lease cancel transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#lease-cancel-transaction-binary-format) - [Lease transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#lease-transaction-binary-format) - [Mass transfer transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#mass-transfer-transaction-binary-format) - [Reissue transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#reissue-transaction-binary-format) - [Set asset script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#set-asset-script-transaction-binary-format) - [Set script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#set-script-transaction-binary-format) - [Sponsor fee transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#sponsor-fee-transaction-binary-format) - [Transfer transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#transfer-transaction-binary-format) - [Transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) ## Address Binary Format Learn more about [address](https://decentralchain.io/docs/decentralchain/account#address). **Address Binary Format** | Field order number | Field | Field type | Field size in bytes | Comments | | --- | --- | --- | --- | --- | | 1 | Entity type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 1. | | 2 | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 87 — for Mainnet. 84 — for Testnet. 83 — for Stagenet. | | 3 | Account public key hash | Array of bytes | 20 | First 20 bytes of the result of the Keccak256 (Blake2b256 (publicKey)) hashing function. Here publicKey is the array of bytes of the account public key. | | 4 | Checksum | Array of bytes | 4 | First 4 bytes of the result of the Keccak256 (Blake2b256 (data)) hashing function. Here data is the array of bytes of three fields put together: 1) Entity type. 2) Chain ID. 3) Account public key hash. | ## Alias Binary Format Learn more about [alias](https://decentralchain.io/docs/decentralchain/account#alias). **Alias Binary Format** | Field order number | Field | Field type | Field size in bytes | Comments | | --- | --- | --- | --- | --- | | 1 | Entity type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 2. | | 2 | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 87 — for Mainnet. 84 — for Testnet. 83 — for Stagenet. | | 3 | Number of characters in the alias | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | 4 | Alias | Array of bytes | From 4 to 30. | ## Block Binary Format Learn more about [block](https://decentralchain.io/docs/decentralchain/block#block). Blocks are stored on the blockchain in a binary format (byte representation). Node extensions such as gRPC server can work directly with data in binary format. **Version 5** ```none message Block { message Header { int32 chain_id = 1; bytes reference = 2; int64 base_target = 3; bytes generation_signature = 4; repeated uint32 feature_votes = 5; int64 timestamp = 6; int32 version = 7; bytes generator = 8; int64 reward_vote = 9; bytes transactions_root = 10; } Header header = 1; bytes signature = 2; repeated SignedTransaction transactions = 3; } ``` **Block Binary Format Version 5** | Field | Description | | --- | --- | | chain_id | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | reference | BLAKE2b-256 hash of the previous block header. | | base_target | [Base target](https://decentralchain.io/docs/decentralchain/block#base-target): а variable that is used in the block generation algorithm. | | generation_signature | [Generation signature](https://decentralchain.io/docs/decentralchain/block#block-generation): а variable that is used in the block generation algorithm (32 bytes). | | feature_votes | List of features for which the block generator votes. See the features. | | timestamp | [Block timestamp](https://decentralchain.io/docs/decentralchain/block#block-timestamp): Unix time in milliseconds. | | version | Block version: 5. | | generator | Block generator's account public key (32 bytes). | | reward_vote | [Block generation reward](https://decentralchain.io/docs/decentralchain/node#block-reward) for which the block generator votes. -1 means that block generator votes for the current reward size. | | transactions_root | [Transactions Root Hash](https://decentralchain.io/docs/decentralchain/block#transactions-root-hash) (32 bytes). | | signature | [Block header signature](https://decentralchain.io/docs/decentralchain/block#block-signature) (64 bytes). | | transactions | For each transaction: 1) Body bytes: up to 165,487 bytes. 2) Proofs: up to 531 bytes. See the [transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-binary-format) article for details. | **Version 4** **Block Binary Format Version 4** | # | Field | Field type | Field size in bytes | Comments | | --- | --- | --- | --- | --- | | 1 | Block version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | The value must be 4. | | 2 | [Block timestamp](https://decentralchain.io/docs/decentralchain/block#block-timestamp) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Unix time in milliseconds. | | 3 | [Signature](https://decentralchain.io/docs/decentralchain/block#block-signature) of the previous block | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | | 4 | [Base target](https://decentralchain.io/docs/decentralchain/block#base-target) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 5 | [Generation signature](https://decentralchain.io/docs/decentralchain/block#block-generation) | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6 | Number of transactions in the block | [Integer](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | | 7.1 | Transaction 1 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | Body bytes: up to 165,996 bytes. Proofs: up to 531 bytes. | Bytes of the 1st transaction in binary format. | | 7.2 | Transaction 2 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | Body bytes: up to 165,996 bytes. Proofs: up to 531 bytes. | Bytes of the 2nd transaction in binary format. | | ... | ... | ... | ... | ... | | 7.[N] | Transaction N | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | Body bytes: up to 165,996 bytes. Proofs: up to 531 bytes. | Bytes of the Nth transaction in binary format. | | 8 | Number of features for which the block generator votes | 4 | [Integer](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | | | 9.1 | Feature 1 | 2 | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | | | ... | ... | ... | ... | ... | | 9.[M] | Feature M | 2 | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | | | 10 | [Block generation reward](https://decentralchain.io/docs/decentralchain/node#block-reward) for which the block generator votes | 8 | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | -1 means that block generator votes for the current reward size. | | 11 | Block generator’s account public key | 32 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | | | 12 | [Block signature](https://decentralchain.io/docs/decentralchain/block#block-signature) | 64 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | | **Version 3** **Block Binary Format Version 3** | # | Field | Field type | Field size in bytes | Comments | | --- | --- | --- | --- | --- | | 1 | Block version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | The value must be 4. | | 2 | [Block timestamp](https://decentralchain.io/docs/decentralchain/block#block-timestamp) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Unix time in milliseconds. | | 3 | [Signature](https://decentralchain.io/docs/decentralchain/block#block-signature) of the previous block | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | | 4 | [Base target](https://decentralchain.io/docs/decentralchain/block#base-target) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 5 | [Generation signature](https://decentralchain.io/docs/decentralchain/block#block-generation) | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6 | Number of transactions in the block | [Integer](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | | 7.1 | Transaction 1 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | Body bytes: up to 165,996 bytes. Proofs: up to 531 bytes. | Bytes of the 1st transaction in binary format. | | 7.2 | Transaction 2 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | Body bytes: up to 165,996 bytes. Proofs: up to 531 bytes. | Bytes of the 2nd transaction in binary format. | | ... | ... | ... | ... | ... | | 7.[N] | Transaction N | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | Body bytes: up to 165,996 bytes. Proofs: up to 531 bytes. | Bytes of the Nth transaction in binary format. | | 8 | Block generator’s account public key | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 9 | [Block signature](https://decentralchain.io/docs/decentralchain/block#block-signature) | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | ## Network Message Binary Format - [Block message binary format](https://decentralchain.io/docs/decentralchain/binary-format#block-message-binary-format) - [Checkpoint message binary format](https://decentralchain.io/docs/decentralchain/binary-format#checkpoint-message-binary-format) - [Get block message binary format](https://decentralchain.io/docs/decentralchain/binary-format#get-block-message-binary-format) - [Get peers message binary format](https://decentralchain.io/docs/decentralchain/binary-format#get-peers-message-binary-format) - [Get signatures message binary format](https://decentralchain.io/docs/decentralchain/binary-format#get-signatures-message-binary-format) - [Handshake message binary format](https://decentralchain.io/docs/decentralchain/binary-format#handshake-message-binary-format) - [Peers message binary format](https://decentralchain.io/docs/decentralchain/binary-format#peers-message-binary-format) - [Score message binary format](https://decentralchain.io/docs/decentralchain/binary-format#score-message-binary-format) - [Signatures message binary format](https://decentralchain.io/docs/decentralchain/binary-format#signatures-message-binary-format) - [Transaction message binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-message-binary-format) ### Block Message Binary Format Block message is a reply to GetBlock message. **Block Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x17) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | | 6 | Block bytes (N) | Bytes | N | ### Checkpoint Message Binary Format **Checkpoint Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x64) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | | 6 | Checkpoint items count (N) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 7 | Checkpoint #1 height | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 8 | Checkpoint #1 signature | Bytes | 64 | | ... | ... | ... | ... | | 6 + 2 * N - 1 | Checkpoint #N height | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 6 + 2 * N | Checkpoint #N signature | Bytes | 64 | ### Get Block Message Binary Format **Get Block Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x16) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | | 6 | Block ID | Bytes | 64 | ### Get Peers Message Binary Format Get peers message is sent when one sending node wants to know about other nodes on the network. **Get Peers Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x01) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | ### Get Signatures Message Binary Format **Get Signatures Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x14) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | | 6 | Block IDs count (N) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 7 | Block #1 ID | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 64 | | ... | ... | ... | ... | | 6 + N | Block #N ID | Bytes | 64 | ### Handshake Message Binary Format Handshake is used to start communication between two nodes. **Handshake Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Application name length (N) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 2 | Application name (UTF-8 encoded bytes) | Bytes | N | | 3 | Application version major | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 4 | Application version minor | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 1 | Application version patch | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 6 | Node name length (M) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 7 | Node name (UTF-8 encoded bytes) | Bytes | M | | 8 | Node nonce | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 9 | Declared address length (K) or 0 if no declared address was set | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 10 | Declared address bytes (if length is not 0) | Bytes | K | | 11 | Timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | ### Peers Message Binary Format Peers message is a response to get peers message. **Peers Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x02) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | | 6 | Peers count (N) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 7 | Peer #1 IP address | Bytes | 4 | | 8 | Peer #1 port | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | ... | ... | ... | ... | | 6 + 2 * N - 1 | Peer #N IP address | Bytes | 4 | | 6 + 2 * N | Peer #N port | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | ### Score Message Binary Format **Score Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x18) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | | 6 | Score (N bytes) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | N | ### Signatures Message Binary Format **Signatures Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x15) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | | 6 | Block signatures count (N) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 7 | Block #1 signature | Bytes | 64 | | ... | ... | ... | ... | | 6 + N | Block #N signature | Bytes | 64 | ### Transaction Message Binary Format **Transaction Message Binary Format** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Packet length (BigEndian) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 2 | Magic Bytes | Bytes | 4 | | 3 | Content ID (0x19) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4 | Payload length | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | 5 | Payload checksum | Bytes | 4 | | 6 | Transaction (N bytes) | Bytes | N | ## Order Binary Format Learn more about [order](https://decentralchain.io/docs/decentralchain/order#order). - An exchange transaction of version 3 can accept orders of versions 1–4. - An exchange transaction of version 2 can accept orders of versions 1–3. - An exchange transaction of version 1 can accept orders of version 1 only. **Version 4** ```none message AssetPair { bytes amount_asset_id = 1; bytes price_asset_id = 2; }; message Order { enum Side { BUY = 0; SELL = 1; }; int32 chain_id = 1; bytes sender_public_key = 2; bytes matcher_public_key = 3; AssetPair asset_pair = 4; Side order_side = 5; int64 amount = 6; int64 price = 7; int64 timestamp = 8; int64 expiration = 9; Amount matcher_fee = 10; int32 version = 11; repeated bytes proofs = 12; }; message Amount { bytes asset_id = 1; int64 amount = 2; }; ``` **Order Binary Format Version 4** | Field | Size | Description | | --- | --- | --- | | chain_id | 1 byte | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | sender_public_key | 32 bytes | Public key of the order sender. | | matcher_public_key | 32 bytes | Public key of matcher. | | asset_pair.amount_asset_id | 32 bytes for asset. 0 for DecentralCoins. | ID of the amount asset. | | asset_pair.price_asset_id | 32 bytes for asset. 0 for DecentralCoins. | ID of the price asset. | | order_side | 1 byte | Order type: buy or sell. | | amount | 8 bytes | Amount of the amount asset, specified in the minimum fraction (“cent”) of asset. | | price | 8 bytes | Price for the amount asset nominated in the price asset, multiplied by 108. | | timestamp | 8 bytes | Order timestamp: Unix time in milliseconds. | | expiration | 8 bytes | Unix time in milliseconds when the order will be expired. | | matcher_fee.asset_id | 32 bytes for asset. 0 for DecentralCoins. | Matcher fee token ID. | | matcher_fee.amount | 8 bytes | Matcher fee | | version | 1 byte | Order version: 4. | | proofs | Each proof up to 64 bytes, up to 8 proofs. | Order proofs that are used to check the validity of the order. | **Version 3** **Order Binary Format Version 3** | # | Field name | JSON field name | Field type | Length in bytes | Value | | --- | --- | --- | --- | --- | --- | | 1 | [Order](https://decentralchain.io/docs/decentralchain/order#order) binary format version number | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Must be 3. | | 2 | Order sender public key | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | 3 | Matcher public key | matcherPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | 4.1 | Asset B (amount asset) flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | If token is DecentralCoins, then value is 0, else 1. | | 4.2 | Asset B (amount Asset) ID | amountAsset | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | S | If token is not DecentralCoins, then S = 32, else the field should be absent. | | 5.1 | Asset A (price asset) flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | If token is DecentralCoins, then value is 0, else 1. | | 5.2 | Asset A (price asset) ID | priceAsset | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | S | If token is not DecentralCoins, then S = 32, else the field should be absent. | | 6 | Order type | orderType | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | If order is for buying, then value is 0, if order is for selling, then value is 1. | | 7 | Amount of asset B (amount asset), which the order sender offers for one price asset(asset A) | price | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Bytes in big-endian notation. | | 8 | Amount of asset B (price asset), which the order sender wants to buy or send depending on order type | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Bytes in big-endian notation. | | 9 | Amount of milliseconds from the beginning of Unix epoch till the moment of validation of order by matcher | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Bytes in big-endian notation. | | 10 | Amount of milliseconds from the beginning of Unix epoch till the unfulfilled order cancellation | expiration | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Bytes in big-endian notation. | | 11 | Matcher fee | matcherFee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Bytes in big-endian notation. | | 12 | Matcher fee token flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | If token is DecentralCoins, then value is 0, else 1 | | 13 | Matcher fee token | matcherFeeAssetId | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | F | If token is not DecentralCoins, then F = 32, else the field should be absent. | | 14 | Proofs | proofs | Array[Proof] | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + (P_{1} + P_{2} + ... + P_{n}), where N is amount of proofs in the array, P_{n} — size N-th proof in bytes. Maximum amount of proofs in the array is 8. Maximum length of each proof is 64 bytes. | JSON Representation of Order Version 3 ```none { "version": 3, "senderPublicKey": "FMc1iASTGwTC1tDwiKtrVHtdMkrVJ1S3rEBQifEdHnT2", "matcherPublicKey": "7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy", "assetPair": { "amountAsset": "BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa", "priceAsset": null }, "orderType": "buy", "amount": 150000000, "timestamp": 1548660872383, "expiration": 1551252872383, "matcherFee": 300000, "proofs": [ "YNPdPqEUGRW42bFyGqJ8VLHHBYnpukna3NSin26ERZargGEboAhjygenY67gKNgvP5nm5ZV8VGZW3bNtejSKGEa" ], "id": "Ho6Y16AKDrySs5VTa983kjg3yCx32iDzDHpDJ5iabXka", "sender": "3PEFvFmyyZC1n4sfNWq6iwAVhzUT87RTFcA", "price": 1799925005, } ``` **Version 2** **Order Binary Format Version 2** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) (constant, value = 2) | 1 | | 2 | Sender's public key | PublicKey (Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 | | 3 | Matcher's public key | PublicKey (Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 | | 4.1 | Amount asset flag (1 - asset, 0 - DecentralCoins) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 4.2 | Amount asset | AssetId (ByteStr = Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 or 0 (depends on the byte in 4.1). | | 5.1 | Price asset flag (1 - asset, 1 - DecentralCoins) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 5.2 | Price asset | AssetId (ByteStr = Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 or 0 (depends on the byte in 5.1). | | 6 | Order type (0 - Buy, 1 - Sell) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 7 | Price | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 8 | Amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 9 | Timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 10 | Expiration | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 11 | Matcher's fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 12 | Proofs | Proofs | | **Version 1** **Order Binary Format Version 1** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Sender's public key | PublicKey (Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 | | 2 | Matcher's public key | PublicKey (Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 | | 3.1 | Amount asset flag (1 - asset, 0 - DecentralCoins) | | 1 | | 3.2 | Amount asset | AssetId (ByteStr = Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 or 0 (depends on the byte in 3.1). | | 4.1 | Price asset flag (1 - asset, 0 - DecentralCoins) | | 1 | | 4.2 | Price asset | AssetId (ByteStr = Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 or 0 (depends on the byte in 4.1). | | 5 | Order type (0 - Buy, 1 - Sell) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | 6 | Price | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 7 | Amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 8 | Timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 9 | Expiration | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 10 | Matcher fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 11 | Signature | Bytes | 64 | The price listed for amount asset in price asset * 10^8. Expiration is order time to live, timestamp in future, max = 30 days in future. The signature is calculated from the following bytes: **Order Binary Format Version 1 Bytes** | # | Field name | Type | Length in Bytes | | --- | --- | --- | --- | | 1 | Sender's public key | PublicKey (Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 | | 2 | Matcher's public key | PublicKey (Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 | | 3.1 | Amount asset flag (1 - asset, 0 - DecentralCoins) | | 1 | | 3.2 | Amount asset | AssetId (ByteStr = Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 or 0 (depends on the byte in 3.1). | | 4.1 | Price asset flag (1 - asset, 0 - DecentralCoins) | | 1 | | 4.2 | Price asset | AssetId (ByteStr = Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]) | 32 or 0 (depends on the byte in 4.1). | | 5 | Order type (0 - Buy, 1 - Sell) | Bytes | 1 | | 6 | Price | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 7 | Amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 8 | Timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 9 | Expiration | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 10 | Matcher fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | ## Transaction Binary Format Learn more about [transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction). Transactions are stored on the blockchain in a binary format (byte representation). Node extensions such as gRPC server can work directly with data in binary format. The transaction signature and ID are also formed on the basis of the binary format, namely the transaction body bytes. The contents of transaction body bytes is given in the description of the binary format of each type and version of the transaction. Normally the transaction body bytes include all transaction fields, with the exception of the following fields: - Transaction ID (it is not stored on the blockchain), - Version flag, - Proofs or signature, depending on the version of the transaction. The guideline for generating a signature and ID is given in the [cryptographic practical details](https://decentralchain.io/docs/decentralchain/protocol#cryptographic-practical-details) article. All strings are UTF-8 encoded. ### Protobuf Protobuf facilitates the development of client libraries for the DecentralChain blockchain, as it avoids serialization errors and streamlines the creation of a correctly signed transaction. How to generate a transaction signature using protobuf: - Download the [protocol buffers package](https://github.com/protocolbuffers/protobuf/releases/) for your programming language. Generate the Transaction class on the basis of transaction.proto. - Fill in the transaction fields. - Asset IDs should be specified in the binary format. - Addresses should be specified in the shortened binary format (without the first two and the last four bytes). See the [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format)) article. - Serialize the transaction object to get transaction body bytes. Detailed instructions for various programming languages are provided in [protocol buffers tutorials](https://developers.google.com/protocol-buffers/docs/tutorials). - Generate the signature for the transaction body bytes with the Curve25519 function using sender private key bytes. The byte representation of a transaction based on the protobuf schema must not contain default values. Make sure that your protocol buffers compiler does not write the field value when serializing if it is equal to the default value for this data type, otherwise the transaction signature will be invalid. Send the signed transaction to a node: - If you use your own node and gRPC server, send the SignedTransaction object. - If you use Node REST API, compose the JSON representation of the transaction and add the base58-encoded signature to the proof array. Send the transaction to a node using POST /transactions/broadcast method. ```none message SignedTransaction { Transaction transaction = 1; repeated bytes proofs = 2; } message Transaction { int32 chain_id = 1; bytes sender_public_key = 2; Amount fee = 3; int64 timestamp = 4; int32 version = 5; oneof data { GenesisTransactionData genesis = 101; PaymentTransactionData payment = 102; IssueTransactionData issue = 103; TransferTransactionData transfer = 104; ReissueTransactionData reissue = 105; BurnTransactionData burn = 106; ExchangeTransactionData exchange = 107; LeaseTransactionData lease = 108; LeaseCancelTransactionData lease_cancel = 109; CreateAliasTransactionData create_alias = 110; MassTransferTransactionData mass_transfer = 111; DataTransactionData data_transaction = 112; SetScriptTransactionData set_script = 113; SponsorFeeTransactionData sponsor_fee = 114; SetAssetScriptTransactionData set_asset_script = 115; InvokeScriptTransactionData invoke_script = 116; UpdateAssetInfoTransactionData update_asset_info = 117; }; }; message Amount { bytes asset_id = 1; int64 amount = 2; }; ``` **Transaction Binary Format** | Field | Size | Description | | --- | --- | --- | | chain_id | 1 byte | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | sender_public_key | 32 bytes | Public key of the transaction sender. | | fee.amount | 8 bytes | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) in the minimum fraction (“cent”) of the fee asset. | | fee.asset_id | 32 bytes for the fee in a sponsored asset. 0 for the fee in DecentralCoins | ID of the token of the fee. The fee in a sponsored asset is only available for invoke script transactions and transfer transactions. See the [sponsored fee](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees) article. | | timestamp | 8 bytes | Transaction timestamp: Unix time in milliseconds. The transaction won't be added to the blockchain if the timestamp value is more than 2 hours back or 1.5 hours forward of the current block timestamp. | | version | 1 byte | Transaction version. | | proofs | Each proof up to 64 bytes,up to 8 proofs. | [Transaction proofs](https://decentralchain.io/docs/decentralchain/transaction#transaction-proofs) that are used to check the validity of the transaction. The array can contain several transaction signatures (but not limited to signatures only). | The fields that depend on the type of transaction are described in the following articles: - [Burn transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#burn-transaction-binary-format) - [Create alias transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#create-alias-transaction-binary-format) - [Data transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#data-transaction-binary-format) - [Exchange transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#exchange-transaction-binary-format) - [Genesis transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#genesis-transaction-binary-format) - [Invoke script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#invoke-script-transaction-binary-format) - [Issue transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#issue-transaction-binary-format) - [Lease cancel transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#lease-cancel-transaction-binary-format) - [Lease transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#lease-transaction-binary-format) - [Mass transfer transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#mass-transfer-transaction-binary-format) - [Reissue transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#reissue-transaction-binary-format) - [Set asset script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#set-asset-script-transaction-binary-format) - [Set script transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#set-script-transaction-binary-format) - [Sponsor fee transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#sponsor-fee-transaction-binary-format) - [Transfer transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#transfer-transaction-binary-format) - [Update asset info transaction binary format](https://decentralchain.io/docs/decentralchain/binary-format#update-asset-info-transaction-binary-format) ### Burn Transaction Binary Format Learn more about [burn transaction](https://decentralchain.io/docs/decentralchain/transaction#burn-transaction). **Version 3** ```none message BurnTransactionData { Amount asset_amount = 1; }; message Amount { bytes asset_id = 1; int64 amount = 2; }; ``` **Burn Transaction Binary Format Version 3** | Field | Size | Description | | --- | --- | --- | | asset_amount.amount | 8 bytes | Amount of token to burn, specified in the minimum fraction (“cents”). | | asset_amount.asset_id | 32 bytes | [ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id) of token to burn. | **Version 2** **Burn Transaction Binary Format Version 2** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 6. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 2. | | 4 | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | chainId | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 87 — for Mainnet. 84 — for Testnet. 83 — for Stagenet. | | 5 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6 | [ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id) of the token to burn | assetId | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 7 | Amount of tokens to burn | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 10 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 2, 3, 4, 5, 6, 7, 8 and 9 are the transaction body bytes. **JSON Representation of Transaction** ```none { "type":6, "id":"csr25XQHT1c965Fg7cY2vJ7XHYVsudPYrUbdaFqgaqL", "sender":"3P9QZNrHbyxXj8P9VrJZmVu2euodNtA11UW", "senderPublicKey":"9GaQj7gktEiiS1TTTjGbVjU9bva3AbCiawZ11qFZenBX", "fee":100000, "feeAssetId":null, "timestamp":1548660675277, "proofs": [ "61jCivdv3KTuTY6QHgxt4jaGrXcszWg3vb9TmUR26xv7mjWWwjyqs7X5VDUs9c2ksndaPogmdunHDdjWCuG1GGhh" ], "version":2, "assetId":"FVxhjrxZYTFCa9Bd4JYhRqXTjwKuhYbSAbD2DWhsGidQ", "amount":9999, "chainId":87, "height":1370971 } ``` **Version 1** **Burn Transaction Binary Format Version 1** | # | Field | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 6. | | 2 | Public key of the transaction sender | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 3 | [ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id) of the token to burn | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 4 | Amount of tokens to burn | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 5 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 6 | Transaction timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 7 | Transaction signature | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | The fields 1, 2, 3, 4, 5 and 6 are the transaction body bytes. ### Create Alias Transaction Binary Format Learn more about [create alias transaction](https://decentralchain.io/docs/decentralchain/transaction#create-alias-transaction). **Version 3** ```none message CreateAliasTransactionData { string alias = 1; }; ``` **Create Alias Transaction Binary Format Version 3** | Field | Size | Description | | --- | --- | --- | | alias | From 4 to 30 bytes | [Alias](https://decentralchain.io/docs/decentralchain/account#alias) | **Version 2** **Create Alias Transaction Binary Format Version 2** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 10. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 2. | | 4 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 5 | Alias length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | Number of characters in the alias name. | | 6 | [Alias](https://decentralchain.io/docs/decentralchain/account#alias) | alias | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | from 4 to 30 | | | 7 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 2, 3, 4, 5, 6, 7 and 8 are the transaction body bytes. **JSON Representation of Transaction** ```none { "type":10, "id":"5CZV9RouJs7uaRkZY741WDy9zV69npX1FTZqxo5fsryL", "sender":"3PNaua1fMrQm4TArqeTuakmY1u985CgMRk6", "senderPublicKey":"B3f8VFh6T2NGT26U7rHk2grAxn5zi9iLkg4V9uxG6C8q", "fee":100000, "feeAssetId":null, "timestamp":1548666019772, "proofs": [ "3cUM8Eq5KfmbS6q1qHDfzhX98YzER1ocnVjVAHG9HSkQdw86zjqxUfmsUPVwnVgwu5zatt3ETLnNFteobRMyR8bY" ], "version":2, "alias":"2.1.0a", "height":1371063 } ``` **Version 1** **Create Alias Transaction Binary Format Version 1** | # | Field | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 10. | | 2 | Public key of the transaction sender | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 3 | Alias length | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | Number of characters in the alias name. | | 4 | [Alias](https://decentralchain.io/docs/decentralchain/account#alias) | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | From 4 to 30 | | | 5 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 6 | Transaction timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 7 | Transaction signature | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | The fields 1, 2, 3, 4, 5 and 6 are the transaction body bytes. ### Data Transaction Binary Format Learn more about [data transaction](https://decentralchain.io/docs/decentralchain/transaction#data-transaction). **Version 2** **Data Transaction Binary Format Version 2** | Field | Size | Description | | --- | --- | --- | | key | Up to 400 bytes | Entry key. | | value | Up to 32,767 bytes | Entry value. If omitted, the transaction deletes the entry. | The maximum number of entries is 100. The maximum data size (keys + values) is 165,890 bytes. **JSON Representation of Transaction** ```none { "type":12, "id":"EByjQAWDRGrmc8uy7xRGy2zsQXZQq59bav7h8oTTJyHC", "sender":"3PLZcCJyYQnfWfzhKXRA4rteCQC9J1ewf5K", "senderPublicKey":"BQMVwAHwf2WEEwRsCxtMVcSLrXUhJ3XtCLmSptLx2e6L", "fee":600000, "feeAssetId":null, "timestamp":1532116120299, "proofs": [ "PZiAGq2ssi1ojh2Cc9dWrzmbuw9nJif2omsQ4dvonU31oiwsJQGbZiio3LG28otatFfFbHPfcX1JVCHwP5i4mKy" ], "version":1, "data": [ {"key":"4900","type":"integer","value":24010000},{"key":"4901","type":"integer","value":24019801}, {"key":"4902","type":"integer","value":24029604},{"key":"4903","type":"integer","value":24039409}, {"key":"4904","type":"integer","value":24049216},{"key":"4905","type":"integer","value":24059025}, {"key":"4906","type":"integer","value":24068836},{"key":"4907","type":"integer","value":24078649}, {"key":"4908","type":"integer","value":24088464},{"key":"4909","type":"integer","value":24098281}, {"key":"4910","type":"integer","value":24108100},{"key":"4911","type":"integer","value":24117921}, {"key":"4912","type":"integer","value":24127744},{"key":"4913","type":"integer","value":24137569}, {"key":"4914","type":"integer","value":24147396},{"key":"4915","type":"integer","value":24157225}, {"key":"4916","type":"integer","value":24167056},{"key":"4917","type":"integer","value":24176889}, {"key":"4918","type":"integer","value":24186724},{"key":"4919","type":"integer","value":24196561}, {"key":"4920","type":"integer","value":24206400},{"key":"4921","type":"integer","value":24216241}, {"key":"4922","type":"integer","value":24226084},{"key":"4923","type":"integer","value":24235929}, {"key":"4924","type":"integer","value":24245776},{"key":"4925","type":"integer","value":24255625}, {"key":"4926","type":"integer","value":24265476},{"key":"4927","type":"integer","value":24275329}, {"key":"4928","type":"integer","value":24285184},{"key":"4929","type":"integer","value":24295041}, {"key":"4930","type":"integer","value":24304900},{"key":"4931","type":"integer","value":24314761}, {"key":"4932","type":"integer","value":24324624},{"key":"4933","type":"integer","value":24334489}, {"key":"4934","type":"integer","value":24344356},{"key":"4935","type":"integer","value":24354225}, {"key":"4936","type":"integer","value":24364096},{"key":"4937","type":"integer","value":24373969}, {"key":"4938","type":"integer","value":24383844},{"key":"4939","type":"integer","value":24393721}, {"key":"4940","type":"integer","value":24403600},{"key":"4941","type":"integer","value":24413481}, {"key":"4942","type":"integer","value":24423364},{"key":"4943","type":"integer","value":24433249}, {"key":"4944","type":"integer","value":24443136},{"key":"4945","type":"integer","value":24453025}, {"key":"4946","type":"integer","value":24462916},{"key":"4947","type":"integer","value":24472809}, {"key":"4948","type":"integer","value":24482704},{"key":"4949","type":"integer","value":24492601}, {"key":"4950","type":"integer","value":24502500},{"key":"4951","type":"integer","value":24512401}, {"key":"4952","type":"integer","value":24522304},{"key":"4953","type":"integer","value":24532209}, {"key":"4954","type":"integer","value":24542116},{"key":"4955","type":"integer","value":24552025}, {"key":"4956","type":"integer","value":24561936},{"key":"4957","type":"integer","value":24571849}, {"key":"4958","type":"integer","value":24581764},{"key":"4959","type":"integer","value":24591681}, {"key":"4960","type":"integer","value":24601600},{"key":"4961","type":"integer","value":24611521}, {"key":"4962","type":"integer","value":24621444},{"key":"4963","type":"integer","value":24631369}, {"key":"4964","type":"integer","value":24641296},{"key":"4965","type":"integer","value":24651225}, {"key":"4966","type":"integer","value":24661156},{"key":"4967","type":"integer","value":24671089}, {"key":"4968","type":"integer","value":24681024},{"key":"4969","type":"integer","value":24690961}, {"key":"4970","type":"integer","value":24700900},{"key":"4971","type":"integer","value":24710841}, {"key":"4972","type":"integer","value":24720784},{"key":"4973","type":"integer","value":24730729}, {"key":"4974","type":"integer","value":24740676},{"key":"4975","type":"integer","value":24750625}, {"key":"4976","type":"integer","value":24760576},{"key":"4977","type":"integer","value":24770529}, {"key":"4978","type":"integer","value":24780484},{"key":"4979","type":"integer","value":24790441}, {"key":"4980","type":"integer","value":24800400},{"key":"4981","type":"integer","value":24810361}, {"key":"4982","type":"integer","value":24820324},{"key":"4983","type":"integer","value":24830289}, {"key":"4984","type":"integer","value":24840256},{"key":"4985","type":"integer","value":24850225}, {"key":"4986","type":"integer","value":24860196},{"key":"4987","type":"integer","value":24870169}, {"key":"4988","type":"integer","value":24880144},{"key":"4989","type":"integer","value":24890121}, {"key":"4990","type":"integer","value":24900100},{"key":"4991","type":"integer","value":24910081}, {"key":"4992","type":"integer","value":24920064},{"key":"4993","type":"integer","value":24930049}, {"key":"4994","type":"integer","value":24940036},{"key":"4995","type":"integer","value":24950025}, {"key":"4996","type":"integer","value":24960016},{"key":"4997","type":"integer","value":24970009}, {"key":"4998","type":"integer","value":24980004},{"key":"4999","type":"integer","value":24990001} ], "height":1091300 } ``` **Version 1** **Data Transaction Binary Format Version 1** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 12. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 1. | | 4 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 5 | Length of the data array | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 6.1 | Key 1 length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 6.2 | Key 1 | key | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Up to 400 | Maximum of 100 characters. | | 6.3 | Value 1 type | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Options are: 0 - [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 1 - [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 2 - Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]. 3 - [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). | | 6.4 | Value 1 length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | This field is present only if the value is of type of array of bytes or a string. If the value is of type of integer or a boolean, this field should not be included in the data structure. | | 6.5 | Value 1 | value | T | S | T is one of the following: 1) [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S = 8. 2) [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S = 1. 3) Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)], S ⩽ 32,767. 4) [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S ⩽ 32,767. | | 6.6 | Key 2 length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 6.7 | Key 2 | key | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Up to 400 | Maximum of 100 characters. | | 6.8 | Value 2 type | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Options are: 0 - [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 1 - [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 2 - Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]. 3 - [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). | | 6.9 | Value 2 length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | This field is present only if the value is of type of array of bytes or a string. If the value is of type of integer or a boolean, this field should not be included in the data structure. | | 6.10 | Value 2 | value | T | S | T is one of the following: 1) [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S = 8. 2) [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S = 1. 3) Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)], S ⩽ 32,767. 4) [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S ⩽ 32,767. | | ... | ... | ... | ... | ... | ... | | 6.[5 × N - 4] | N-th key length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 6.[5 × N - 3] | N-th key | key | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Up to 400 | Maximum of 100 characters. | | 6.[5 × N - 2] | N-th value type | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Options are: 0 - [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 1 - [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 2 - Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]. 3 - [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). | | 6.[5 × N - 1] | N-th value length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | This field is present only if the value is of type of array of bytes or a string. If the value is of type of integer or a boolean, this field should not be included in the data structure. | | 6.[5 × N] | N-th value | value | T | S | T is one of the following: 1) [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S = 8. 2) [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S = 1. 3) Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)], S ⩽ 32,767. 4) [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types), S ⩽ 32,767. | | 7 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 1, 2, 3, 4, 5, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 6.10, 6.[5 × N - 4], 6.[5 × N - 3], 6.[5 × N - 2], 6.[5 × N - 1], 6.[5 × N], 7 and 8 are the transaction body bytes. The maximum number of records is 100. The maximum size of transaction body bytes is 153,600 bytes. ### Exchange Transaction Binary Format Learn more about [exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction). **Version 3** Exchange transaction of version 3 can accept orders of versions 1 –4. ```none message ExchangeTransactionData { int64 amount = 1; int64 price = 2; int64 buy_matcher_fee = 3; int64 sell_matcher_fee = 4; repeated Order orders = 5; }; ``` **Exchange Transaction Binary Format Version 3** | Field | Size | Description | | --- | --- | --- | | amount | 8 bytes | Amount of the amount asset (base currency) that the buyer received from the seller, specified in the minimum fraction (“cent”) of asset. | | price | 8 bytes | Price for the amount asset (base currency) nominated in the price asset (quote currency), multiplied by 10^{8}. For more details see the [order](https://decentralchain.io/docs/decentralchain/order#order) article. | | buy_matcher_fee | 8 bytes | Buy matcher fee. The fee token ID is indicated in buy order. | | sell_matcher_fee | 8 bytes | Sell matcher fee The fee token ID is indicated in sell order. | | orders | | Buy order and sell order. See the [order binary format](https://decentralchain.io/docs/decentralchain/binary-format#order-binary-format). | **Version 2** Transaction version 2 can accept orders of version 1, 2 and 3. **Exchange Transaction Binary Format Version 2** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 7. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 2. | | 4.1 | Buy order size | | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | Size including flag 4.2. | | 4.2 | Buy order version flag | order1.version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | S | S = 1 if the order version is 1. S = 0 if the order version is 2 or 3. | | 4.3 | Buy order | order1 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | See [order binary format](https://decentralchain.io/docs/decentralchain/binary-format#order-binary-format) | | | 5.1 | Sell order size | | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | Size including flag 5.2. | | 5.2 | Sell order version flag | order2.version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | S | S = 1 if the order version is 1. S = 0 if the order version is 2 or 3. | | 5.3 | Sell order | order2 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | See order binary format | | | 6 | Deal price | price | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Price for the amount asset (base currency) nominated in the price asset (quote currency). | | 7 | Amount | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Amount of the amount asset (base currency) that the buyer received from the seller. | | 8 | Buy matcher fee | buyMatcherFee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | Sell matcher fee | sellMatcherFee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 10 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 11 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 12 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 1, 2, 3, 4.1, 4.2, 4.3, 5.1, 5.2, 5.3, 6, 6.6, 7, 8, 9, 10 and 11 are the transaction body bytes. **JSON Representation of Transaction** ```none { "type":6, "id":"csr25XQHT1c965Fg7cY2vJ7XHYVsudPYrUbdaFqgaqL", "sender":"3P9QZNrHbyxXj8P9VrJZmVu2euodNtA11UW", "senderPublicKey":"9GaQj7gktEiiS1TTTjGbVjU9bva3AbCiawZ11qFZenBX", "fee":100000, "feeAssetId":null, "timestamp":1548660675277, "proofs": [ "61jCivdv3KTuTY6QHgxt4jaGrXcszWg3vb9TmUR26xv7mjWWwjyqs7X5VDUs9c2ksndaPogmdunHDdjWCuG1GGhh" ], "version":2, "assetId":"FVxhjrxZYTFCa9Bd4JYhRqXTjwKuhYbSAbD2DWhsGidQ", "amount":9999, "chainId":87, "height":1370971 } ``` **Version 1** Transaction version 1 can accept orders of version 1 only. **Exchange Transaction Binary Format Version 1** | # | Field | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 6. | | 2 | Buy order size | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | | 3 | Sell order size | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | | 4 | Buy order | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | See [order binary format](https://decentralchain.io/docs/decentralchain/binary-format#order-binary-format) | | | 5 | Sell order | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | See order binary format | | | 6 | Deal price | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Price for the amount asset (base currency) nominated in the price asset (quote currency). | | 7 | Amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Amount of the amount asset (base currency) that the buyer received from the seller. | | 8 | Buy matcher fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | Sell matcher fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 10 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 11 | Transaction timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 12 | Transaction signature | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | The fields 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and 11 are the transaction body bytes. ### Genesis Transaction Binary Format Learn more about [genesis transaction](https://decentralchain.io/docs/decentralchain/transaction#genesis-transaction). **Genesis Transaction Binary Format** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 1. | | 2 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 3 | Address of the recipient | recipient | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 26 | | | 4 | Amount of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) that will be transferred to the account | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | **JSON Representation of Transaction** ```none { "type":1, "id":"2DVtfgXjpMeFf2PQCqvwxAiaGbiDsxDjSdNQkc5JQ74eWxjWFYgwvqzC4dn7iB1AhuM32WxEiVi1SGijsBtYQwn8", "fee":0, "timestamp":1465742577614, "signature":"2DVtfgXjpMeFf2PQCqvwxAiaGbiDsxDjSdNQkc5JQ74eWxjWFYgwvqzC4dn7iB1AhuM32WxEiVi1SGijsBtYQwn8", "recipient":"3PAWwWa6GbwcJaFzwqXQN5KQm7H96Y7SHTQ", "amount":9999999500000000, "height":1 } ``` ### Invoke Script Transaction Binary Format Learn more about [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction). **Version 2** ```none message InvokeScriptTransactionData { Recipient d_app = 1; bytes function_call = 2; repeated Amount payments = 3; }; message Recipient { oneof recipient { bytes public_key_hash = 1; string alias = 2; }; }; message Amount { bytes asset_id = 1; int64 amount = 2; }; ``` **Invoke Script Transaction Binary Format Version 2** | Field | Size | Description | | --- | --- | --- | | d_app.public_key_hash | 20 bytes | dApp account public key hash (a component of an address, see the Address binary format article). | | d_app.alias | From 4 to 30 bytes | dApp alias. | | function_call | | Function name and arguments. Binary format of function call is the same as in version 1. | | payments.asset_id | 32 bytes for asset. 0 for [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | ID of token in payment. | | payments.amount | 8 bytes | Amount of token in payment, specified in the atomic units. | The maximum size of d_app + function_call + payments is 5120 bytes. **JSON Representation of Transaction** ```none { "type":16, "id":"7CVjf5KGRRYj6UyTC2Etuu4cUxx9qQnCJox8vw9Gy9yq", "sender":"3P5rWeMzoaGBrXJDMifQDDjCMKWJGKTiVJU", "senderPublicKey":"4kKN9G7cZXGQujLQm9ss5gqB7TKX4A9jtFGt7DnHUoQ6", "fee":500000, "feeAssetId":null, "timestamp":1565537422938, "proofs": [ "28s21sisoa7yHWWmmX8U78fbNHW4KXAS9GHD8XmaN77gJxbnP2Q3DssNWpmSQ6hBq6xS985W4YiTmgvENhfWPNt5" ], "version":1, "dApp":"3PJbknfXMsJzZmksmsKSMz56tVdDqF5GdNM", "payment":[], "call": { "function":"returnSellVST", "args": [ { "type":"string", "value":"GiEBRfGhEeGqhPmLCjwJcYuakyvaz2GHGCfCzuinSKD" } ] }, "height":1656369, "stateChanges": { "data": [ { "key":"sell_GiEBRfGhEeGqhPmLCjwJcYuakyvaz2GHGCfCzuinSKD_spent", "type":"integer", "value":10000000000 } ], "transfers": [ { "address":"3P5rWeMzoaGBrXJDMifQDDjCMKWJGKTiVJU", "asset":"4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8", "amount":10000000000 } ], "issues":[], "reissues":[], "burns":[], "sponsorFees":[], "leases":[], "leaseCancels":[], "invokes":[] } } ``` **Version 1** **Invoke Script Transaction Binary Format Version 1** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 16. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 1. | | 4 | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 87 — for Mainnet. 84 — for Testnet. 83 — for Stagenet. | | 5 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6 | Address or alias | dApp | See Address Binary Format, Alias Binary Format | S | If the first byte of the field is 1, then it is followed by address. S in this case equals 26. If the first byte of the field is 2, then it is followed by alias. In this case 8 <= S <= 34. | | 7.1 | Function presence flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 0 — the default function of the dApp is invoked. 1 — function from the current transaction should be invoked in the dApp. | | 7.2 | Function call ID | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Constant. The value must be 9. | | 7.3 | Function type ID | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Constant. The value must be 1. | | 7.4 | Function name length | | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | | 7.5 | Function name | function | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Up to 255 | | | 7.6.1 | Amount of arguments of the function | | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 4 | | | 7.6.2 | ID of argument 1 type | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 0 — argument type is long. 1 — argument type is an array of bytes. 2 — argument type is a string. 6 — argument type is logical True. 7 — argument type is logical False. 11 – argument type is list. | | 7.6.3 | Argument 1 | value | Options are: 1) [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 2) Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]. 3) [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 4) Logical True. 5) Logical False. 6) List. | S | S = 8, if argument type is long. If the argument type is an array of bytes, string, or list, the field size is limited only by the total transaction size. If the type is list, then 1) its length must not exceed 1000 elements. 2) amount of its elements represents first 4 bytes of the current field. 3) each list element is serialized similarly to the function argument: the element type ID takes first place followed by the element's value. S = 0, if argument type is logical True or False. | | 7.6.4 | ID of argument 2 type | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 0 — argument type is long. 1 — argument type is an array of bytes. 2 — argument type is a string. 6 — argument type is logical True. 7 — argument type is logical False. 11 – argument type is list. | | 7.6.5 | Argument 2 | value | Options are: 1) [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 2) Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]. 3) [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 4) Logical True. 5) Logical False. 6) List. | S | S = 8, if argument type is long. If the argument type is an array of bytes, string, or list, the field size is limited only by the total transaction size. If the type is list, then 1) its length must not exceed 1000 elements. 2) amount of its elements represents first 4 bytes of the current field. 3) each list element is serialized similarly to the function argument: the element type ID takes first place followed by the element's value. S = 0, if argument type is logical True or False. | | ... | ... | ... | ... | ... | ... | | 7.6.[2 × N] | ID of argument N type | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 0 — argument type is long. 1 — argument type is an array of bytes. 2 — argument type is a string. 6 — argument type is logical True. 7 — argument type is logical False. 11 – argument type is list. | | 7.6.[2 × N + 1] | Argument N | value | Options are: 1) [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 2) Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)]. 3) [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types). 4) Logical True. 5) Logical False. 6) List. | S | S = 8, if argument type is long. If the argument type is an array of bytes, string, or list, the field size is limited only by the total transaction size. If the type is list, then 1) its length must not exceed 1000 elements. 2) amount of its elements represents first 4 bytes of the current field. 3) each list element is serialized similarly to the function argument: the element type ID takes first place followed by the element's value. S = 0, if argument type is logical True or False. | | 8.1 | Amount of payments | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 8.2 | Payment 1 length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 8.3 | Amount of token in payment 1 | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8.4 | Flag of payment 1 token | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 0 — [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). 1 — other token. | | 8.5 | ID of payment 1 token | | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | Field is applicable if the token is not [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | | ... | ... | ... | ... | ... | ... | | 8.[4 × N – 2] | Payment N length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 8.[4 × N – 1] | Amount of token in payment N | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8.[4 × N] | Flag of payment N token | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 0 — [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). 1 — other token. | | 8.[4 × N + 1] | ID of payment N token | | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | Field is applicable if the token is not [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | | 9 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 10.1 | Flag of fee token | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 0 — [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). 1 — other token. | | 10.2 | Fee token ID | feeAssetId | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | S | S = 0, if token is [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). S = 32, if it is other token. | | 11 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 12 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The maximum number of payments is 10. The maximum size of transaction including proofs is 5120 bytes. ### Issue Transaction Binary Format Learn more about [issue transaction](https://decentralchain.io/docs/decentralchain/transaction#issue-transaction). **Version 3** ```none message IssueTransactionData { string name = 1; string description = 2; int64 amount = 3; int32 decimals = 4; bool reissuable = 5; bytes script = 6; }; ``` **Issue Transaction Binary Format Version 3** | Field | Size | Description | | --- | --- | --- | | name | From 4 to 16 bytes | Token name. | | description | From 0 to 1000 bytes | Token description. | | amount | 8 bytes | Amount of token to issue, specified in the minimum fraction (“cents”). | | decimals | 1 byte | Number of decimal places. | | reissuable | 1 byte | Reissue availability flag. | | script | Up to 8192 bytes | [Asset script](https://decentralchain.io/docs/ride/script-types#asset-script). | **Version 2** **Issue Transaction Binary Format Version 2** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 0 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 0 | Value must be 3. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 0 | Value must be 2. | | 4 | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | chainId | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 0 | 87 — for Mainnet. 84 — for Testnet. 83 — for Stagenet. | | 5 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6.1 | [Token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) name length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 6.2 | Token name | name | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | From 4 to 16 | | | 7.1 | Token description length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 7.2 | Token description | description | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | From 0 to 1000 | | | 8 | Amount of the token that will be issued | quantity | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | Number of decimal places of the token | decimals | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 0 | | | 10 | Reissue flag | reissuable | [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 0 | If the value is 0, then token reissue is not possible. If the value is 1, then token reissue is possible. | | 11 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 12 | Transaction timestamp | timestamp | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 13.1 | Script existence flag | | [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 0 | If the value is 0, then the token does not have a script. If the value is 1, then the token has a script. | | 13.2 | Script length in bytes | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | S | S = 0 if the value of the script existence flag field is 0. S = 2 if the value of the script existence flag field is 1. | | 13.3 | [Asset script](https://decentralchain.io/docs/ride/script-types#asset-script) | script | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | S | S = 0 if the value of the script existence flag field is 0. 0 < S ≤ 8192, if the value of the script existence flag field is 1. | | 14 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 82. The size of each proof is 64 bytes. | The fields 2, 3, 4, 5, 6.1, 6.2, 7.1, 7.2, 8, 9, 10, 11, 12, 13.1, 13.2 and 13.3 are the transaction body bytes. **JSON Representation of Transaction** ```none { "type":3, "id":"FTQvw9zdYirRksUFCKDvor3hiu2NiUjXEPTDEcircqti", "sender":"3PPP59J1pToCk7fPs4d5EK5PoHJMeQRJCTb", "senderPublicKey":"E8Y8ywedRS9usVvvcuczn9hsSg1SNkQVBMcNeQEnjDTP", "fee":100000000, "feeAssetId":null, "timestamp":1548666518362, "proofs": [ "3X7GpKW1ztto1aJN5tQNByaGZ9jGkaxZNo4BT268obZckbXuNQHGKjAUxtqcSEes5aZNMaQi2JYBGeKpcaPTxpSC" ], "version":2, "assetId":"FTQvw9zdYirRksUFCKDvor3hiu2NiUjXEPTDEcircqti", "name":"DCVN", "quantity":990000000000000000, "reissuable":false, "decimals":8, "description":"Tài chính cho nền dân chủ", "script":null, "chainId":87, "height":1371069 } ``` **Version 1** **Issue Transaction Binary Format Version 1** | # | Field | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 3. | | 2 | Transaction signature | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | | 3 | Transaction type ID | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | This field duplicates field 1. | | 4 | Public key of the transaction sender | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 5.1 | [Token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) name length | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 5.2 | Token name | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | From 4 to 16 | | | 6.1 | Token description length | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 6.2 | Token description | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | From 0 to 1000 | | | 7 | Amount of the token that will be issued | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | Number of decimal places of the token | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | | 9 | Reissue flag | [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | | | 10 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 11 | Transaction timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | The fields 3, 4, 5.1, 5.2, 6.1, 6.2, 7, 8, 9, 10 and 11 are the transaction body bytes. ### Lease Cancel Transaction Binary Format Learn more about [lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction) **Version 3** ```none message LeaseCancelTransactionData { bytes lease_id = 1; }; ``` **Lease Cancel Transaction Binary Format Version 3** | Field | Size | Description | | --- | --- | --- | | lease_id | 32 bytes | Lease ID. | **Version 2** **Lease Cancel Transaction Binary Format Version 2** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 9. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 2. | | 4 | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | chainId | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 87 — for Mainnet. 84 — for Testnet. 83 — for Stagenet. | | 5 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 7 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | Lease ID | | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 9 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 2, 3, 4, 5, 6, 7, and 8 are the transaction body bytes. **JSON Representation of Transaction** ```none { "type":9, "id":"7siEtrJAvmVzM1WDX6v9RN4qkiCtk7qQEeD5ZhE6955E", "sender":"3PMBXG13f89pq3WyJHHKX2m5zN6kt2CEkHQ", "senderPublicKey":"BEPNBjo9Pi9hJ3hVtxpwyEfXCW3qWUNk5dMD7aFdiHsa", "fee":100000, "feeAssetId":null, "timestamp":1548660629957, "proofs": [ "3cqVVsaEDzBz367KTBFGgMXEYJ2r3yLWd4Ha8r3GzmAFsm2CZ3GeNW22wqxfK4LNRFgsM5kCWRVhf6gu2Nv6zVqW" ], "version":2, "leaseId":"BggRaeNCVmzuFGohzF4dQeYXSWr8i5zNSnGtdKc5eGrY", "chainId":87, "height":1370970, "lease": { "id":"BggRaeNCVmzuFGohzF4dQeYXSWr8i5zNSnGtdKc5eGrY", "originTransactionId":"BggRaeNCVmzuFGohzF4dQeYXSWr8i5zNSnGtdKc5eGrY", "sender":"3PMBXG13f89pq3WyJHHKX2m5zN6kt2CEkHQ", "recipient":"3PMWRsRDy882VR2viKPrXhtjAQx7ygQcnea", "amount":406813214, "height":1363095, "status":"canceled", "cancelHeight":1370970, "cancelTransactionId":"7siEtrJAvmVzM1WDX6v9RN4qkiCtk7qQEeD5ZhE6955E" } } ``` **Version 1** **Lease Cancel Transaction Binary Format Version 1** | Field order number | Field | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 9. | | 2 | Public key of the transaction sender | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 3 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 4 | Transaction timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 5 | Lease ID | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6 | Transaction signature | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | The fields 1, 2, 3, 4, and 5 are the transaction body bytes. ### Lease Transaction Binary Format Learn more about [lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction). **Version 3** ```none message LeaseTransactionData { Recipient recipient = 1; int64 amount = 2; }; message Recipient { oneof recipient { bytes public_key_hash = 1; string alias = 2; }; }; ``` **Lease Transaction Binary Format Version 3** | Field | Size | Description | | --- | --- | --- | | recipient.public_key_hash | 20 bytes | Recipient's account public key hash (a component of an [address](https://decentralchain.io/docs/decentralchain/account#address), see the [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format) article). | | recipient.alias | From 4 to 30 bytes | Recipient's [alias](https://decentralchain.io/docs/decentralchain/account#alias). | | amount | 8 bytes | Amount of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to lease (that is, amount of Decentralites multiplied by 10^{8}). | **Version 2** **Lease Transaction Binary Format Version 2** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 8. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 2. | | 4 | Reserved field | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be equal to 0. | | 5 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6 | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the recipient | recipient | See [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format), [alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) | S | If the first byte of the field is 1, then it is followed by address. S in this case equals 26. If the first byte of the field is 2, then it is followed by alias. In this case 8 <= S <= 34. | | 7 | Amount of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) that will be leased to the account | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 10 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 2, 3, 4, 5, 6, 7, 8 and 9 are the transaction body bytes. **JSON Representation of Transaction** ```none { "type":8, "id":"J6jZCzLpWJX8EDVhopKFx1mcbFizLGHVb44dvqPzH4QS", "sender":"3PMYNm8hshzCNjZ8GpPta5SyN7qBTEzS7Kw", "senderPublicKey":"GNswAY61mER5ZyUFeDBo1UyKGkPSSmmnd6yj7axN2n8f", "fee":100000, "feeAssetId":null, "timestamp":1548660916755, "proofs": [ "2opTj7mGKXLRajkJ78wN4ctSWqTeWtvisHaR8BnL2amqJ2KB313BbcpDYJKcqr7o7EpYjL5tppMz2pGjUMWbJe9b" ], "version":2, "amount":14000000000, "recipient":"3PMWRsRDy882VR2viKPrXhtjAQx7ygQcnea", "height":1370973, "status":"canceled" } ``` **Version 1** **Lease Transaction Binary Format Version 1** | # | Field | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 8. | | 2 | Public key of the transaction sender | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 3 | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the recipient | See [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format), [alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) | S | If the first byte of the field is 1, then it is followed by address. S in this case equals 26. If the first byte of the field is 2, then it is followed by alias. In this case 8 <= S <= 34. | | 4 | Amount of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) that will be leased to the account | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 5 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 6 | Transaction timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 7 | Transaction signature | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | The fields 1, 2, 3, 4, 5 and 6 are the transaction body bytes. ### Mass Transfer Transaction Binary Format Learn more about [mass transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#mass-transfer-transaction). **Version 2** ```none message MassTransferTransactionData { message Transfer { Recipient recipient = 1; int64 amount = 2; }; bytes asset_id = 1; repeated Transfer transfers = 2; bytes attachment = 3; }; message Recipient { oneof recipient { bytes public_key_hash = 1; string alias = 2; }; } ``` **Mass Transaction Binary Format Version 2** | Field | Size | Description | | --- | --- | --- | | asset_id | 32 bytes | ID of token to transfer. | | transfers.recipient.public_key_hash | 20 bytes | Recipient's account public key hash (a component of an address, see the [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format) article). | | transfers.recipient.alias | From 4 to 30 bytes | Recipient's [alias](https://decentralchain.io/docs/decentralchain/account#alias). | | transfers.amount | 8 bytes | Amount of token to transfer, specified in the minimum fraction (“cents”). | | attachment | Up to 140 bytes | Arbitrary data (typically a comment to transfer). | The maximim number of transfers is 100. **JSON Representation of Transaction** ```none { "type":11, "id":"3LRfudet7avpQcW1AdauiBGb8SSRAaoCugDzngDPLVcv", "sender":"3P2rvn2Hpz6pJcH8oPNrwLsetvYP852QQ2m", "senderPublicKey":"5DphrhGy6MM4N3yxfB2uR2oFUkp2MNMpSzhZ4uJEm3U1", "fee":5100000, "feeAssetId":null, "timestamp":1528973951321, "proofs": [ "FmGBaWABAy5bif7Qia2LWQ5B4KNmBnbXETL1mE6XEy4AAMjftt3FrxAa8x2pZ9ux391oY5c2c6ZSDEM4nzrvJDo" ], "version":1, "assetId":"Fx2rhWK36H1nfXsiD4orNpBm2QG1JrMhx3eUcPVcoZm2", "attachment":"xZBWqm9Ddt5BJVFvHUaQwB7Dsj78UQ5HatQjD8VQKj4CHG48WswJxUUeHEDZJkHgt9LycUpHBFc8ENu8TF8vvnDJCgfy1NeKaUNydqy9vkACLZjSqaVmvfaM3NQB", "transferCount":6, "totalAmount":500000000000, "transfers": [ {"recipient":"3PHnjQrdK389SbzwPEJHYKzhCqWvaoy3GQB","amount":5000000000}, {"recipient":"3PGNLwUG2GPpw74teTAxXFLxgFt3T2uQJsF","amount":5000000000}, {"recipient":"3P5kQneM9EdpVUbFLgefD385LLYTXY5J32c","amount":5000000000}, {"recipient":"3P2j9FZyygnVDCQvmSc41VCAKwwCQm8QUhA","amount":5000000000}, {"recipient":"3PNBZutLvMpjzxGAiQGqQuDyanhWyLi2Fhi","amount":5000000000}, {"recipient":"3P84vdYxzDPFbS5zj9J6yCkmKKA2QMo1DKA","amount":5000000000}, ], "height":1041197 } ``` **Version 1** **Mass Transaction Binary Format Version 1** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 11. | | 2 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 1. | | 3 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 4.1 | Flag DecentralCoins/token | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value is 0 for transferring DecentralCoins. Value is 1 for transferring other tokens. | | 4.2 | Token ID | assetId | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | S | S = 0 if the value of the flag DecentralCoins/token field is 0. S = 32 if the value of the flag DecentralCoins/token field is 1. | | 5.1 | Number of transfers | transferCount | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 5.2 | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the recipient | recipient | See [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format), [alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) | S | If the first byte of the field is 1, then it is followed by address. S in this case equals 26. If the first byte of the field is 2, then it is followed by alias. In this case 8 <= S <= 34. | | 5.3 | Amount of tokens in the transfer 1 | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 5.4 | Address or alias of the recipient | recipient | See [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format), [alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) | S | If the first byte of the field is 1, then it is followed by address. S in this case equals 26. If the first byte of the field is 2, then it is followed by alias. In this case 8 <= S <= 34. | | 5.5 | Amount of tokens in the transfer 2 | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | ... | ... | ... | ... | ... | ... | | 5.[2 × N] | Address or alias of the recipient | recipient | See [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format), [alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) | S | If the first byte of the field is 1, then it is followed by address. S in this case equals 26. If the first byte of the field is 2, then it is followed by alias. In this case 8 <= S <= 34. | | 5.[2 × N + 1] | Amount of tokens in the transferN | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 6 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 7 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8.1 | Attachment length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 8.2 | Attachment | | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 2 | Arbitrary data attached to the transaction. | | 9 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 1, 2, 3, 4.1, 4.2, 5.1, 5.2, 5.3, 5.4, 5.5, 5.[2 × N], 5.[2 × N + 1], 6, 7, 8.1 and 8.2 are the transaction body bytes. ### Reissue Transaction Binary Format Learn more about [reissue transaction](https://decentralchain.io/docs/decentralchain/transaction#reissue-transaction). **Version 3** ```none message ReissueTransactionData { Amount asset_amount = 1; bool reissuable = 2; }; message Amount { bytes asset_id = 1; int64 amount = 2; }; ``` **Reissue Transaction Binary Format Version 3** | Field | Size | Description | | --- | --- | --- | | asset_id | 32 bytes | ID of token to reissue. | | asset_amount.amount | 8 bytes | Amount of token to reissue, specified in the minimum fraction (“cents”). | | reissuable | 1 byte | Reissue availability flag. | **Version 2** **Reissue Transaction Binary Format Version 2** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 5. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 2. | | 4 | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | chainId | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 87 — for Mainnet. 84 — for Testnet. 83 — for Stagenet. | | 5 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6 | Token ID | assetId | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 7 | Amount of token that will be reissued | quantity | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | Reissue flag | reissuable | [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | If the value is 0, then token reissue is not possible. If the value is 1, then token reissue is possible. | | 9 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 10 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 11 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 2, 3, 4, 5, 6, 7, 8, 9 and 10 are the transaction body bytes. **JSON Representation of Transaction** ```none { "type":5, "id":"27ETigYaHym2Zbdp4x1gnXnZPF1VJCqQpXmhszC35Qac", "sender":"3PLJciboJqgKsZWLj7k1VariHgre6uu4S2T", "senderPublicKey":"DjYEAb3NsQiB6QdmVAzkwJh7iLgUs3yDLf7oFEeuZjfM", "fee":100000000, "feeAssetId":null, "timestamp":1548521785933, "proofs": [ "5mEveeUwBdBqe8naNoV5eAe5vj6fk8U743eHGkhxhs3v9PMsb3agHqpe4EtzpUFdpASJegXyjrGSbynZg557cnSq" ], "version":2, "assetId":"GA4gB3Lf3AQdF1vBCbqGMTeDrkUxY7L83xskRx6Z7kEH", "quantity":200000, "reissuable":true, "chainId":87, "height":1368623 } ``` **Version 1** .. csv-table:: Reissue Transaction Binary Format Version 1 :file: ../_static/02_decentralchain/tables/083_Reissue-Transaction-Binary-Format-V1.csv :header-rows: 1 :class: longtable :widths: 1 2 2 1 3 The fields 3, 4, 5, 6, 7, 8 and 9 are the transaction body bytes. ### Set Asset Script Transaction Binary Format Learn more about [set asset script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-asset-script-transaction). **Version 2** ```none message SetAssetScriptTransactionData { bytes asset_id = 1; bytes script = 2; }; ``` **Set Asset Script Transaction Binary Format Version 2** | Field | Size | Description | | --- | --- | --- | | asset_id | 32 bytes | ID of asset. | | script | Up to 8192 bytes | [Asset script](https://decentralchain.io/docs/ride/script-types#asset-script). | The maximim number of transfers is 100. **JSON Representation of Transaction** ```none { "type":15, "id":"FwYSpmVDbWQ2BA5NCBZ9z5GSjY39PSyfNZzBayDiMA88", "sender":"3P67JUW8Djit7hMjKhADmn6CWvKPbRuh2sQ", "senderPublicKey":"AwQYJRHZNd9bvF7C13uwnPiLQfTzvDFJe7DTUXxzrGQS", "fee":100000000, "feeAssetId":null, "timestamp":1547201038106, "proofs": [ "nzYhVKmRmd7BiFDDfrFVnY6Yo98xDGsKrBLWentF7ibe4P9cGWg4RtomHum2NEMBhuyZb5yjThcW7vsCLg7F8NQ" ], "version":1, "assetId":"7qJUQFxniMQx45wk12UdZwknEW9cDgvfoHuAvwDNVjYv", "script":"base64:AQa3b8tH", "chainId":87, "height":1346345 } ``` **Version 1** .. csv-table:: Set Asset Script Transaction Binary Format Version 1 :file: ../_static/02_decentralchain/tables/085_Set-Asset-Transaction-Binary-Format-V1.csv :header-rows: 1 :class: longtable :widths: 1 2 1 1 1 3 The fields 2, 3, 4, 5, 6, 7, 8, 9.1, 9.2 and 9.3 are the transaction body bytes. ### Set Script Transaction Binary Format Learn more about [set script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-script-transaction). **Version 2** ```none message SetScriptTransactionData { bytes script = 1; }; ``` **Set Script Transaction Binary Format Version 2** | Field | Size | Description | | --- | --- | --- | | script | Up to 32,768 bytes | [Account script](https://decentralchain.io/docs/ride/script-types#account-script) or [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script). | **JSON Representation of Transaction** ```none { "type":13, "id":"8Nwjd2tcQWff3S9WAhBa7vLRNpNnigWqrTbahvyfMVrU", "sender":"3PBSduYkK7GQxVFWkKWMq8GQkVdAGX71hTx", "senderPublicKey":"3LZmDK7vuSBsDmFLxJ4qihZynUz8JF9e88dNu5fsus5p", "fee":2082496, "feeAssetId":null, "timestamp":1537973512182, "proofs": [ "V45jPG1nuEnwaYb9jTKQCJpRskJQvtkBcnZ45WjZUbVdNTi1KijVikJkDfMNcEdSBF8oGDYZiWpVTdLSn76mV57" ], "version":1, "script":"base64:AQQAAAAEaW5hbAIAAAAESW5hbAQAAAAFZWxlbmECAAAAB0xlbnVza2EEAAAABGxvdmUCAAAAC0luYWxMZW51c2thCQAAAAAAAAIJAAEsAAAAAgUAAAAEaW5hbAUAAAAFZWxlbmEFAAAABGxvdmV4ZFt5", "chainId":87, "height":1190001 } ``` **Version 1** **Set Script Transaction Binary Format Version 1** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 13. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 1. | | 4 | [Chain ID](https://decentralchain.io/docs/decentralchain/mainnet-testnet-stagenet#chain-id) | chainId | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | 87 — for Mainnet. 84 — for Testnet. 83 — for Stagenet. | | 5 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 6.1 | Script existence flag | | [Boolean](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | If the value is 0, then the token does not have a script. If the value is 1, then the token has a script. | | 6.2 | Script length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | S | S = 0 if the value of the script existence flag field is 0. S = 2 if the value of the script existence flag field is 1. | | 6.3 | Script | script | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | S | S = 0 if the value of the script existence flag field is 0. 0 < S ≤ 32,768, if the value of the script existence flag field is 1. | | 7 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | ### Sponsor Fee Transaction Binary Format Learn more about [sponsor fee transaction](https://decentralchain.io/docs/decentralchain/transaction#sponsor-fee-transaction). **Version 2** ```none message SponsorFeeTransactionData { Amount min_fee = 1; }; message Amount { bytes asset_id = 1; int64 amount = 2; }; ``` **Sponsor Fee Transaction Binary Format Version 2** | Field | Size | Description | | --- | --- | --- | | min_fee.asset_id | 32 bytes | ID of asset. | | min_fee.amount | 8 bytes | Amount of asset that is equivalent to 0.001 DecentralCoins (100 000 Decentralites), specified in the minimum fraction (“cents”) of asset. See the [sponsored fee](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees) article. | **JSON Representation of Transaction** ```none { "type":14, "id":"7EL2XEGP1By427BeLcHPYeVnBzGsXen4egMAwQpWGBVR", "sender":"3PHrS6VNPRtUD8MHkfkmELavL8JnGtSq5sx", "senderPublicKey":"5v5D5pqzKGBejtvtEeyDJXG28iQwMViu1uuetEcyQp9v", "fee":100000000, "feeAssetId":null, "timestamp":1534448057070, "proofs": [ "3Q4JS4ujrGxAqp8LMXR9zZJC4tJ7YHiTo4SvMgrPhufo2UtR5x9JAaCGDjEr7qWXFDPJk7vWL8eapQkS45Dx1kcb" ], "version":1, "assetId":"FN76goSi7hQn6gQ8aezKVwyDvhkWx5ekXbP3sNLWqavN", "minSponsoredAssetFee":10, "height":1130205 } ``` **Version 1** **Sponsor Fee Transaction Binary Format Version 1** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 14. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 1. | | 4 | Transaction type ID | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | This field duplicates field 2. | | 5 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | This field duplicates field 3. | | 6 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 7 | Token ID | assetId | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 8 | Minimal sponsored asset fee | minSponsoredAssetFee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | Amount of sponsored asset that is equivalent to 0.001 DecentralCoins (100,000 Decentralites). | | 9 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 10 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 11 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | The fields 4, 5, 6, 7, 8, 9 and 10 are the transaction body bytes. ### Transfer Transaction Binary Format Learn more about [transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction). **Version 3** ```none message TransferTransactionData { Recipient recipient = 1; Amount amount = 2; bytes attachment = 3; }; message Recipient { oneof recipient { bytes public_key_hash = 1; string alias = 2; }; message Amount { bytes asset_id = 1; int64 amount = 2; }; ``` **Transfer Transaction Binary Format Version 3** | Field | Size | Description | | --- | --- | --- | | recipient.public_key_hash | 20 bytes | Recipient's account public key hash (a component of an address, see the [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format) article). | | recipient.alias | From 4 to 30 bytes | Recipient's [alias](https://decentralchain.io/docs/decentralchain/account#alias). | | amount.asset_id | 32 bytes | ID of token to transfer. | | amount.amount | 8 bytes | Amount of token to transfer, specified in the minimum fraction (“cents”). | | attachment | Up to 140 bytes | Arbitrary data (typically a comment to transfer). | **Version 2** **Transfer Transaction Binary Format Version 2** | # | Field | JSON field name | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | --- | | 1 | Version flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Indicates the transaction version is 2 or higher. Value must be 0. | | 2 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | type | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 4. | | 3 | Transaction version | version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 2. | | 4 | Public key of the transaction sender | senderPublicKey | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 5.1 | Transferring token type flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value is 0 for transferring DecentralCoins. Value is 1 for transferring other token. | | 5.2 | Transferring token ID | assetId | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | S | math:`S = 0` if the value of the flag 5.1 is 0. S = 32 if the value of the flag 5.1 is 1. | | 6.1 | Fee token type flag | | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value is 0 for fee in DecentralCoins. Value is 1 for fee in other token. | | 6.2 | Fee token ID | feeAssetId | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | S | Token to pay the fee. S = 0 if the value of the flag 6.1 is 0. S = 32 if the value of the flag 6.1 field is 1. | | 7 | Transaction timestamp | timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | Amount of token in the transfer | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 9 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 10 | Address or alias | recipient | See [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format), [alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) | S | If the first byte of the field is 1, then it is followed by address. S in this case equals 26. If the first byte of the field is 2, then it is followed by alias. In this case 8 <= S <= 34 | | 11.1 | Attachment length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 11.2 | Attachment | attachment | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | Up to 140 bytes | Arbitrary data attached to the transaction. | | 12 | Transaction proofs | proofs | See [transaction proofs binary format](https://decentralchain.io/docs/decentralchain/binary-format#transaction-proofs-binary-format) | S | If the array is empty, then S = 3. If the array is not empty, then S = 3 + 2 × N + 64 × N, where N is the number of proofs in the array. The maximum number of proofs in the array is 8. The size of each proof is 64 bytes. | **JSON Representation of Transaction** ```none { "type":4, "id":"2UMEGNXwiRzyGykG8voDgxnwHA7w5aX5gmxdcf9DZZjL", "sender":"3PCeQD3nAyHmzDSYBUnSPDWf9qxqzVU2sjh", "senderPublicKey":"6kn1XPDh2XUjVAgznxNousHq3EnKKLx7BRWyJzVFU76J", "fee":100000, "feeAssetId":null, "timestamp":1583160322998, "proofs": [ "2z5fnoigbsCBqRPWqTDeDmGJF6qJwnm2WLspen6c6qziTc73sBh9Kh81kPhUT9DGg7ANwqsXMxQauEvyw3RxNH7z" ], "version":2, "recipient":"3P45uRnyVygTnbEJNxc2CHLUiC4izQxbuuS", "assetId":"51LxAtwBXapvvTFSbbh4nLyWFxH6x8ocfNvrXxbTChze", "feeAsset":null, "amount":30077000000, "attachment":"2d6RhvQATwGbyv7dKT3L77758iJx", "height":1954598 } ``` **Version 1** **Transfer Transaction Binary Format Version 1** | # | Field | Field type | Field size in bytes | Comment | | --- | --- | --- | --- | --- | | 1 | [Transaction type ID](https://decentralchain.io/docs/decentralchain/transaction#transaction-types) | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value must be 4. | | 2 | Transaction signature | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | | 3 | Transaction type ID | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | This field duplicates field 1. | | 4 | Public key of the transaction sender | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 32 | | | 5.1 | Transferring token type flag | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value is 0 for transferring DecentralCoins. Value is 1 for transferring other token. | | 5.2 | Transferring token ID | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | S | S = 0 if the value of the flag 5.1 is 0. S = 32 if the value of the flag 5.1 is 1. | | 6.1 | Fee token type flag | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value is 0 for fee in DecentralCoins. Value is 1 for fee in other token. | | 6.2 | Fee token ID | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | S | Token to pay the fee. S = 0 if the value of the flag 6.1 is 0. S = 32 if the value of the flag 6.1 field is 1. | | 7 | Transaction timestamp | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | | 8 | Amount of token in the transfer | amount | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 9 | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees) | fee | [Long](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 8 | | 10 | Address or alias | recipient | See [address binary format](https://decentralchain.io/docs/decentralchain/binary-format#address-binary-format), [alias binary format](https://decentralchain.io/docs/decentralchain/binary-format#alias-binary-format) | S | | 11.1 | Attachment length | | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | 11.2 | Attachment | attachment | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | Up to 140 bytes. | ### Update Asset Info Transaction Binary Format Learn more about [update asset info transaction](https://decentralchain.io/docs/decentralchain/transaction#update-asset-info-transaction). **Version 1** ```none message UpdateAssetInfoTransactionData { bytes asset_id = 1; string name = 2; string description = 3; } ``` **Update Asset Info Transaction Binary Format Version 1** | Field | Size | Description | | --- | --- | --- | | asset_id | 32 bytes | Token ID. | | name | From 4 to 16 bytes | Token name. | | description | From 0 to 1000 bytes | Token description. | ## Transaction Proofs Binary Format **Transaction Proofs Binary Format** | # | Field | Type | Size in bytes | Comment | | --- | --- | --- | --- | --- | | 1 | Proofs version | [Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 1 | Value is 1. | | 2 | Proofs count | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 3 | Proof 1 length | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | Value is 64. | | 4 | Proofs 1 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | | 5 | Proof 2 length | [Short](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | 2 | | | 6 | Proof 2 | Array[[Byte](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types)] | 64 | | | ... | ... | ... | ... | ... | The maximum number of proofs is 8. --- # Syntax Basics Source: https://decentralchain.io/docs/ride/syntax-basics - [Directives](https://decentralchain.io/docs/ride/syntax-basics#directives) - [Definitions](https://decentralchain.io/docs/ride/syntax-basics#definitions) - [Expressions](https://decentralchain.io/docs/ride/syntax-basics#expressions) - [Constants](https://decentralchain.io/docs/ride/syntax-basics#constants) - [Variables](https://decentralchain.io/docs/ride/syntax-basics#variables) - [Operators](https://decentralchain.io/docs/ride/syntax-basics#operators) - [Functions](https://decentralchain.io/docs/ride/syntax-basics#functions) - [Exceptions](https://decentralchain.io/docs/ride/syntax-basics#exceptions) - [Comments](https://decentralchain.io/docs/ride/syntax-basics#comments) ## Directives Every Ride script should start with directives for the compiler. The directives define the script format and available functions, structures and variables. Directive format is as follows: ```none {-# DIRECTIVE_NAME VALUE #-} ``` ### Directive List There are three types of directives, with different possible values. ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} ``` {-# STDLIB_VERSION 5 #-} sets the version of the standard library. The latest version currently in production is 5. {-# CONTENT_TYPE DAPP #-} sets the type of the file you're working on. There are different content types, DAPP and EXPRESSION. The DAPP type allows you to define functions and finish execution with certain actions which result in account balances, asset properties, and entries in the dApp account data storage. The EXPRESSION type should always return a boolean value, since it’s used as a predicate for transaction validation. {-# SCRIPT_TYPE ACCOUNT #-} sets the entity type we want to add to the script to change its default behavior. Ride scripts can be attached to either an ACCOUNT or ASSET. **Examples** For a [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script): ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} ``` For an [account script](https://decentralchain.io/docs/ride/script-types#account-script): ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ACCOUNT #-} ``` For an [asset script](https://decentralchain.io/docs/ride/script-types#asset-script): ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ASSET #-} ``` Not all combinations of directives are correct. The example below will not work, because DAPP content type is allowed only for accounts: ```none # Wrong example, will not work {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ASSET #-} ``` ## Definitions A definition is a linking of the name to the value or to the [function](https://decentralchain.io/docs/ride/syntax-basics#functions) body. **Examples** Linking the name to the value. ```none let x = 5 + 5 ``` Linking the name to the [function](https://decentralchain.io/docs/ride/syntax-basics#functions) body. ```none func f(x: Int) = { x + 5 } ``` ## Expressions An expression is a combination of one or more [constants](https://decentralchain.io/docs/ride/syntax-basics#constants), [variables](https://decentralchain.io/docs/ride/syntax-basics#variables), [operators](https://decentralchain.io/docs/ride/syntax-basics#operators) and [function](https://decentralchain.io/docs/ride/syntax-basics#functions) calls. ### Expression Result An expression result is a value, which is obtained by the fold of the syntactic tree of the expression. Ride interprets the expression and calculates its result. ### Expression Type An expression type is a [data type](https://decentralchain.io/docs/ride/data-types#data-types) of the expression result. **Examples** The expression that consists of a single constant. ```none 7 ``` The expression that consists of a single variable. ```none 7 + x * size("apple") ``` The expression that consists of the constant 7, operators + and \*, variable x and the size function call. ```none 7 + x * size("apple") ``` ## Constants A constant is a value that cannot be changed by the program during its execution. ### Examples Below 7 and "apple" are constants. ```none 7 + x + size("apple") ``` ## Variables These are declared and initialized with the let keyword. ```none let a = "Bob" let b = 1 ``` In Ride, you can only declare a variable along with a value assignment. The = sign must be followed by an expression. The value of the variable is the expression result. Ride variables are immutable: the value of a variable cannot be changed after it is defined. Ride is strongly typed and the variable's type is inferred from the value. Ride allows you to define variables globally, inside any function, or even inside a variable definition. ```none func lazyIsGood() = { let a = "Bob" let b = { let x = 1 "Alice" } true } ``` ### Lazy Variables Let keyword defines a variable with lazy evaluation: the value of a variable is evaluated the first time it is used. Let's see an example: ```none let a = 42 # Integer variable definition let b = "Ride!" # String variable definition ``` Ride allows you to define variables globally, inside any function, or even inside a variable definition. ```none func lazyIsGood() = { let c = { let d = 1 true } c } ``` The function above returns true, but variable d won't be initialized because unused lazy variables are not evaluated. Since a function is a definition and not an expression, you can assign a function value to a variable but not the function itself. ```none let result = lazyIsGood() # result is true ``` ### Strict Variables The strict keyword defines a variable with strict (eager) evaluation. Unlike lazy variables defined with let, a strict variable is evaluated immediately when script execution reaches it, that is, before the next expression. Strict variables can only be used inside another definition, for example, inside the body of a function. A strict variable will not be evaluated if it is defined inside another definition that is not used: for example, inside a function that has not been called. Strict variables are suitable for [dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation) as they ensure executing callable functions and applying their actions in the right order. Let's see an example: ```none func foo() = { ... strict balanceBefore = decentralchainBalance(this).regular strict z = invoke(dapp2,"bar",args,[AttachedPayment(unit,100000000)]) strict balanceAfter = decentralchainBalance(this).regular if(balanceAfter < balanceBefore) then ... else... } ``` In this example, balanceBefore and balanceAfter may differ because payments to dApp2 and actions performed by the bar callable function can affect the balance. ### Built-in Variables The Standard library defines built-in variables that can be used in scripts. **Built-in Variables** | # | Name | Description | | --- | --- | --- | | 1 | Buy | [Order](https://decentralchain.io/docs/decentralchain/order#order) type. | | 2 | \1) CEILING. 2) DOWN. 3) FLOOR. 4) HALFEVEN. 5) HALFUP. | Rounding methods used in the [math functions](https://decentralchain.io/docs/ride/functions#math-functions) fraction, log, pow. | | 3 | height | Blockchain height at the script execution time. | | 4 | lastBlock | Information about the last [block](https://decentralchain.io/docs/decentralchain/block#block) of the blockchain at the script execution time. | | 5 | nil | Variable that contains an empty list. The variable is used for creating [lists](https://decentralchain.io/docs/ride/data-types#list). For example, instead of: let a = [5,6]. | | 6 | \1) NOALG. 2) MD5. 3) SHA1. 4) SHA224. 5) SHA256. 6) SHA384. 7) SHA512. 8) SHA3224. 9) SHA3256. 10) SHA3384. 11) SHA3512. | Variables that are passed as the first parameter to the rsaVerify function. | | 7 | Sell | Order type. | | 8 | this | \1) For a [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script) or an [account script](https://decentralchain.io/docs/ride/script-types#account-script): the [Address](https://decentralchain.io/docs/ride/structures#address) structure. 2) For an [asset script](https://decentralchain.io/docs/ride/script-types#asset-script): the [asset](https://decentralchain.io/docs/ride/functions#math-functions) structure. | | 9 | tx | [Transaction](https://decentralchain.io/docs/decentralchain/transaction#transaction) or order. | | 10 | unit | Variable that contains an object of Unit type. | ## Operators ### Arithmetic Operators **Arithmetic Operators** | Operator | Description | | --- | --- | | \+ | Addition | | \- | Subtraction | | \* | Multiplication | | / | Division | | % | Remainder | The / operator uses the FLOOR rounding method. ### Comparison Operators **Comparison Operators** | Operator | Description | | --- | --- | | < | Less than | | > | Greater than | | <= | Less than or equal | | >= | Greater than or equal | ### Equality Operators **Equality Operators** | Operator | Description | | --- | --- | | == | Equality | | != | Inequality | ### Local Definition Operators **Local Definition Operators** | Operator | Description | | --- | --- | | func | Function local definition. | | let | Lazy definition of a variable. | | strict | [Strict definition](https://decentralchain.io/docs/ride/syntax-basics#variables) of a variable. | ### Conditional Operators **Conditional Operators** | Operator | Description | | --- | --- | | if-then-else | Conditional statement. | | match-case | [Spot a type from union](https://decentralchain.io/docs/ride/syntax-basics#match-case). | ### List Operators **List Operators** | Operator | Description | | --- | --- | | ++ | Concatenation. | | :+ | Adding the element to the end of the list. | | \:\: | Adding the element to the beginning of the list. | See examples of the [list](https://decentralchain.io/docs/ride/data-types#list) article. ### Unary Operators **Unary Operators** | Operator | Description | | --- | --- | | \- | Unary minus | | ! | Logical negation | ### Logical Operators **Logical Operators** | Operator | Description | | --- | --- | | && | Logical AND | | \|\| | Logical OR | ### Match-Case match-case operator is used to spot a certain type from [union](https://decentralchain.io/docs/ride/data-types#union) or [any](https://decentralchain.io/docs/ride/data-types#any) type . The spotting is required to perform certain operations. Let's review the following example. ```none match tx { case _: TransferTransaction|ExchangeTransaction => t.amount > 100 && sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) case _ => false } ``` In this example, if: - The type of transaction is transfer transaction or exchange transaction. - Amount field value is greater than 100. Then it will be sent to the blockchain. If the transaction has a different type and/or amount field value is lesser than 100, then it will be rejected. #### Possible Issue Let's review the following code. ```none {-# STDLIB_VERSION 2 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ACCOUNT #-} match (tx) { case t: TransferTransaction|ExchangeTransaction|MassTransferTransaction|Order => false # Prohibit any transfer of funds from the account case _ => sigVerify(...) } ``` In this example we are using version 2 of Ride standard library, STDLIB_VERSION 2, and we want to reject any funds transfer from our account. In order to do this, we are returning false for: - TransferTransaction - ExchangeTransaction - MassTransferTransaction Transactions of other types (for example transactions that do not transfer funds) are being sent to the blockchain. But Ride is developing rapidly, and new transaction types are emerging. Features of invoke script transaction which is not supported by Ride v2 include attaching payments to transfer tokens to the account of the called dApp. This means that the InvokeScriptTransaction won't be caught by the first case. It will pass to the default branch case _ => and sent to blockchain. As a result, the funds could be transferred from the account instead of the transfers being prohibited like we wanted. #### Solution To prevent the reviewed issue, it is recommended to return false inside of the default case. Then for the entities, not listed in previous branches, sending information to the blockchain will be prohibited. Below is the sample of script which rejects any funds transfer from account, but allows all other transactions existing in Ride v2. Usage of case _ => false rejects any other transactions, not supported by the Ride v2 (i.e. invoke script transaction). ```none {-# STDLIB_VERSION 2 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ACCOUNT #-} match tx { case t: TransferTransaction|ExchangeTransaction|MassTransferTransaction|Order => false # Prohibit any transfer of funds from the account case _: Transaction => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) # Allow all other known transaction types as long as the signature is correct case _ => false # Reject all other (new, unknown) entity types, since they are not in the version of the language used at the moment } ``` ## Functions Functions in Ride can only be used after they are declared. ```none func greet(name: String) = { "Hello, " + name } func add(a: Int, b: Int) = { func m(a:Int) = a m(a) + b } ``` The type (Int, String, etc) comes after the argument’s name. As in many other languages, functions should not be overloaded. It helps to keep the code simple, readable and maintainable. ```none func calc() = { 42 } func do() = { let a = calc() true } ``` The callable function will not be called either, because variable a is unused. Unlike most languages, variable shadowing is not allowed. Declaring a variable with a name that is already used in a parent scope will result in a compilation error. Functions should be defined before they are used. Functions can be invoked in prefix and postfix order: ```none let list = [1, 2, 3] let a1 = list.size() let a2 = size(list) let b1 = getInteger(this, “key”) let b2 = this.getInteger(“key”) ``` In these examples a1 is the same as a2 and b1 is the same as b2. Learn more about [functions](https://decentralchain.io/docs/ride/functions#functions). ## Exceptions There is no exception handling in Ride: after an exception has been thrown, the script execution fails. The transaction can be either discarded or saved on the blockchain as failed, see the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation) article for details The throw function will terminate script execution immediately, with the provided text. There is no way to catch thrown exceptions. ```none throw("Here is exception text") ``` The idea of throw is to stop execution and send useful feedback to the user. ```none let a = 12 if (a != 100) then throw ("a is not 100, actual value is " + a.toString()) else throw("A is 100") ``` ## Comments To write comments use the pound sign. ```none let month = 7 # Sets the month ``` There are no multi-line comments. --- # Data Types Source: https://decentralchain.io/docs/ride/data-types **Data Types** | Data type name | Ride keyword | | --- | --- | | [Big Integer](https://decentralchain.io/docs/ride/data-types#bigint) | BigInt | | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | Boolean | | [Byte array](https://decentralchain.io/docs/ride/data-types#bytevector) | ByteVector | | [Integer](https://decentralchain.io/docs/ride/data-types#int) | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | | [String](https://decentralchain.io/docs/ride/data-types#string) | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | | [Empty value](https://decentralchain.io/docs/ride/data-types#unit) | Unit | | [List](https://decentralchain.io/docs/ride/data-types#list) | List | | [Tuple](https://decentralchain.io/docs/ride/data-types#tuple) | — | | [Union](https://decentralchain.io/docs/ride/data-types#union) | — | | [Structure](https://decentralchain.io/docs/ride/structures#structures) | — | | [Arbitrary type](https://decentralchain.io/docs/ride/data-types#any) | Any | For each value, depending on the data type, the weight is determined. The weight is used in limitations on creating and comparing values. For more information see the [data weight](https://decentralchain.io/docs/ride/dapp-to-app-invocation#data-weight). ## Any Any is an arbitrary data type. It is a common supertype of all types: an Any type value can be a string, a number, unit, a structure, a list, a tuple, etc. ```none func findString(a: Any) = { match a { case a: String => a case a: List[Any] => match a[0] { case b: String => b case _ => throw("Data is not a string") } case _ => throw("Data is not a string") } } ``` ## BigInt BigInt is a special numeric [data type](https://decentralchain.io/docs/ride/data-types#data-types) designed to handle values outside the range of [Int](https://decentralchain.io/docs/ride/data-types#int) and to perform high accuracy calculations. BigInt variable has a size of 64 bytes (512 bits) and contains an integer between –2511 to 2511–1, inclusive. The weight of the value is 64. A BigInt variable can only be used inside a script. A [callable function](https://decentralchain.io/docs/ride/functions#callable-functions) does not accept arguments of BigInt type and does not return a value of BigInt type. You can pass a big integer value as a string, then use the parseBigInt or parseBigIntValue functions. ### BigInt Operations The following operators support BigInt values: - Arithmetic operators: +, -, \*, /, %, unary minus. - Comparison operators: <, >, <=, and >=. - Equality operators: == and !=. ### BigInt Functions The following functions operate BigInt values: - [fraction(BigInt, BigInt, BigInt): BigInt](https://decentralchain.io/docs/ride/functions#fraction-bigint-bigint-bigint) - [fraction(BigInt, BigInt, BigInt, Union): BigInt](https://decentralchain.io/docs/ride/functions#fraction-bigint-bigint-bigint-union) - [log(BigInt, Int, BigInt, Int, Int, Union): BigInt](https://decentralchain.io/docs/ride/functions#log-bigint-int-bigint-int-int-union) - [max(List[BigInt]): BigInt](https://decentralchain.io/docs/ride/functions#max-list-bigint) - [median(List[BigInt]): BigInt](https://decentralchain.io/docs/ride/functions#median-list-bigint) - [min(List[BigInt]): BigInt](https://decentralchain.io/docs/ride/functions#min-list-bigint) - [pow(BigInt, Int, BigInt, Int, Int, Union): BigInt](https://decentralchain.io/docs/ride/functions#pow-bigint-int-bigint-int-int-union) - [parseBigInt(String): BigInt|Unit](https://decentralchain.io/docs/ride/functions#parsebigint-string) - [parseBigIntValue(String): BigInt](https://decentralchain.io/docs/ride/functions#parsebigintvalue-string) - [toBigInt(ByteVector): BigInt](https://decentralchain.io/docs/ride/functions#tobigint-bytevector) - [toBigInt(ByteVector, Int, Int): BigInt](https://decentralchain.io/docs/ride/functions#tobigint-bytevector-int-int) - [toInt(BigInt): Int](https://decentralchain.io/docs/ride/functions#toint-bigint) - [toString(BigInt): String](https://decentralchain.io/docs/ride/functions#tostring-bigint) ## Boolean Boolean is a [data type](https://decentralchain.io/docs/ride/data-types#data-types) that can have only the values true or false. ## ByteVector ByteVector is a [data type](https://decentralchain.io/docs/ride/data-types#data-types) for byte array. To assign a value to a ByteVector variable, you can use a string in Base16, Base58, or Base64 with the appropriate prefix: ```none let a = base16'52696465' let b = base58'8t38fWQhrYJsqxXtPpiRCEk1g5RJdq9bG5Rkr2N7mDFC' let c = base64'UmlkZQ==' ``` This method, unlike the fromBase16String, fromBase58String, and fromBase64String functions, does not increase the complexity of the script, since decoding is performed by the compiler. To convert [integer](https://decentralchain.io/docs/ride/data-types#int), [boolean](https://decentralchain.io/docs/ride/data-types#boolean) and [string](https://decentralchain.io/docs/ride/data-types#string) values to a byte array use toBytes function: ```none let a = 42.toBytes() let b = true.toBytes() let c = "Ride".toBytes() ``` For more byte array functions, see the [Built-in Functions](https://decentralchain.io/docs/ride/functions#built-in-functions). ### ByteVector Limitations The maximum size of a ByteVector variable is 32,767 bytes. Exception: the bodyBytes field of [transaction structure](https://decentralchain.io/docs/ride/structures#transaction-structures). You can pass this value as an argument to the rsaVerify и sigVerify [verification functions](https://decentralchain.io/docs/ride/functions#verification-functions) (but cannot concatenate with other byte arrays in case the limit is exceeded). ## Int Int is an integer [data type](https://decentralchain.io/docs/ride/data-types#data-types). The integer variable has the size of 8 bytes and stores an integer from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 inclusive. ```none let age = 42 let length = size("hello") ``` ## String Strings are denoted only using double quotes. They are immutable, and for that reason, the substring function is very efficient: no copying is performed and no extra allocations are required. Strings are UTF-8 encoded. ```none let name = "Bob" # use "double" quotes only ``` ### String Limitations The maximum size of a String variable is 32,767 (1 character can take up to 4 bytes). ### String Functions The built-in functions for working with strings are presented in the following articles: - String Functions - Converting Functions ## Unit Unit is an empty value [data type](https://decentralchain.io/docs/ride/data-types#data-types). The empty value data type is similar to unit in Scala or to null in C#. Usually, built-in functions return unit value of type unit instead of null. ```none "String".indexOf("substring") == unit # true ``` ## Nothing Nothing is the 'bottom type' of Ride’s type system. No value can be of type nothing, but an expression of type nothing can be used everywhere. In functional languages, this is essential for support for throwing an exception: ```none 2 + throw() # the expression compiles because # there's a defined function +(Int, Int). # The type of the second operand is Nothing, # which complies to any required type ``` ## List The list data type may contain elements of various types, including nested lists. The maximum number of list items is 1000. The nesting depth is not limited. A list doesn't have any fields, but there are functions and operators in the Standard library that make it easier to work with fields. - To prepend an element to an existing list, use the cons function or :: operator - To append an element, use the :+ operator - To concatenate 2 lists, use the ++ operator ```none let list = [16, 10, 1997, "birthday"] let last = list[(list.size() - 1)] # "birthday", postfix call of size() function let initList = [16, 10] # init value let newList = cons(1997, initList) # [1997, 16, 10] let newList2 = 1997 :: initList # [1997, 16, 10] let newList2 = initList :+ 1 # [16, 10, 1] let newList2 = [4, 8, 15, 16] ++ [23, 42] # [4 8 15 16 23 42] ``` ### List Operations Lists support concatenation as well as adding items to the beginning and the end. **List Operations** | Operation | Symbol | Complexity | | --- | --- | --- | | Concatenation | ++ | 4 | | Adding the element to the end of the list (the list is on the left, the element is on the right) | :+ | 1 | | Adding the element to the beginning of the list (the element is on the left, the list is on the right) | :: | 2 | Operation to be used: ```none nil :+ 1 :+ 2 :+ 3 ``` Result: [1, 2, 3] Operation to be used: ```none 1 :: 2 :: 3 :: nil ``` Result: [1, 2, 3] Operation to be used: ```none let intList = [1, 2] # List[Int] let strList = ["3", "4"] # List[String] let joined = intList ++ strList # List[Int|String] joined ``` Result: [1, 2, "3", "4"] Operation to be used: ```none let appended = joined :+ true # List[Boolean|Int|String] appended ``` Result: [1, 2, "3", "4", true] Operation to be used: ```none let nested = intList :: joined # List[Int|List[Int]|String] nested ``` Result: [[1, 2], 1, 2, "3", "4"] ### List Functions The built-in list functions are presented in the list functions article. Operations on a list can be implemented via the FOLD macro. The size of the list must be known in advance. ### List as Function Argument A list, including nested one, can be a function argument: ```none func foo(arg: List[String|Unit]) = { ... } foo(["Ride","DecentralCoins",unit]) ``` ```none func bar(arg: List[List[Int]]) = { ... } bar([[1],[],[5,7]]) ``` A callable function can take a list as an argument, but nested lists are not allowed. Here’s an example: ```none @Callable(i) func join(strings: List[String|Int]) = { let a = match strings[0] { case n:Int => toString(n) case s:String => s } let b = match strings[1] { case n:Int => toString(n) case s:String => s } let c = match strings[2] { case n:Int => toString(n) case t:String => t } [ StringEntry(toBase58String(i.caller.bytes), a + "_" + b + "_" + c) ] } ``` Invoke Script transaction example: ```none { "type": 16, ... "call": { "function": "join", "args": [ { "type": "list", "value": [ { "type": "string", "value": "Ride" }, { "type": "integer", "value": 5 }, { "type": "string", "value": "DecentralCoins" } ] } ] }, ... } ``` ## Tuple A tuple is an ordered collection of elements. Elements can be of any type. The tuple can contain from 2 to 22 elements. Let's see some tuples: ```none let x=("Hello DecentralChain",42,true) x._2 ``` Result: 42 And this one also: ```none let (a,b,c)=x c ``` Result: true ## Union Union is a data type that unites 2 or more data types. Union can combine primitive types, [lists](https://decentralchain.io/docs/ride/data-types#list), [tuples](https://decentralchain.io/docs/ride/data-types#tuple), [structures](https://decentralchain.io/docs/ride/structures#structures). This type is a very convenient way to work with abstractions. Union(String | Unit) shows that the value is an intersection of these types. To get a value of a particular type from a Union, you can use: - [Union functions](https://decentralchain.io/docs/ride/functions#union-functions) - [match-case operator](https://decentralchain.io/docs/ride/syntax-basics#match-case) ```none let valueFromBlockchain = getString("3PHHD7dsVqBFnZfUuDPLwbayJiQudQJ9Ngf", "someKey") # Union(String | Unit) ``` The simplest example of Union types is given below (please bear in mind that defining custom user types in dApp code will be supported in future versions): ```none type Human : { firstName: String, lastName: String, age: Int} type Cat : {name: String, age: Int } ``` Let's see anoter example where each element of a List[Int|String] is a string or an integer. ```none let aList = [1, 2, "DecentralCoins"] # List[Int|String] let bList = [true,false] # List[Boolean] let joined = aList ++ bList # List[Boolean|Int|String] ``` ## Pattern Matching Let’s revisit the example above: ```none type Human : { firstName: String, lastName: String, age: Int} type Cat : {name: String, age: Int } Union(Human | Cat) is an object with one field, age, but we can use pattern matching like this: ``` ```none Human | Cat => { age: Int } ``` This is designed to check a value against value type: ```none let t = ... # Cat | Human t.age # OK t.name # Compiler error let name = match t { # OK case h: Human => h.firstName case c: Cat => c.name } ``` ## Type matching This is a mechanism for knowing the type of a transaction: ```none let amount = match tx { # tx is a current outgoing transaction case t: TransferTransaction => t.amount case m: MassTransferTransaction => m.totalAmount case _ => 0 } ``` There are different types of transactions, if a transaction is TransferTransaction or MassTransferTransaction we use the corresponding field, while in all other cases, we will get 0. --- # Functions Source: https://decentralchain.io/docs/ride/functions Functions in Ride are declared with func, function must be declared above the place of its usage. When declaring a function to the right of the "=" sign must be an [expression](https://decentralchain.io/docs/ride/syntax-basics#expressions). The value of the function is the expression result. Definition of the function with no parameters that returns an integer: ```none func main() = { 3 } ``` Definition of a function with two parameters: ```none func main(amount: Int, name: String) = { throw() } ``` Functions do have return types, this is inferred automatically by the compiler, so you don't have to declare them. There is no return statement in the language because Ride is expression-based (everything is an expression), and the last statement is a result of the function. ```none func greet(name: String) = { "Hello, " + name } func add(a: Int, b: Int) = { func m(a:Int) = a m(a) + b } ``` The type (Int, String, etc) comes after the argument’s name. As in many other languages, functions should not be overloaded. It helps to keep the code simple, readable and maintainable. Functions can be invoked in prefix and postfix order: ```none let list = [1, 2, 3] let a1 = list.size() let a2 = size(list) let b1 = getInteger(this, "key") let b2 = this.getInteger("key") ``` ## Annotations Functions can be without annotations, but they can also be with @Callable or @Verifier annotations. Annotated functions are used only in scripts of type DAPP. Here’s an example of @Callable: ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} func getPayment(i: Invocation) = { if (size(i.payments) == 0) then throw("Payment must be attached") else { let pmt = i.payments[0] if (isDefined(pmt.assetId)) then throw("This function accepts DecentralCoin tokens only") else pmt.amount } } @Callable(i) func pay() = { let amount = getPayment(i) ( [ IntegerEntry(toBase58String(i.caller.bytes), amount) ], unit ) } ``` Annotations can bind some values to the function. In the example above, variable i was bound to the function pay and stored some fields of the invocation (the caller’s public key, address, payments attached to the invocation, fee, transaction ID etc.). Functions without annotations are not available from the outside. You can call them only inside other functions. Here’s an example of @Verifier: ```none @Verifier(tx) func verifier() = { match tx { case m: TransferTransaction => tx.amount <= 100 # can send up to 100 tokens case _ => false } } ``` A function with the @Verifier annotation sets the rules for outgoing transactions of a decentralized application (dApp). Verifier functions cannot be called from the outside, but they are executed every time an attempt is made to send a transaction from a dApp. Verifier functions should always return a Boolean value as a result, depending on whether a transaction will be recorded to the blockchain or not. Expression scripts (with directive {-# CONTENT_TYPE EXPRESSION #-} along with functions annotated by @Verifier should always return a boolean value. Depending on that value the transaction will be accepted (in case of true) or rejected (in case of false) by the blockchain. ```none @Verifier(tx) func verifier() = { sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) } ``` The Verifier function binds variable tx, which is an object with all fields of the current outgoing transaction. A maximum of one @Verifier() function can be defined in each dApp script. ## Callable Functions The functions with the @Callable annotation become callable functions, since they can be called (or invoked) from other accounts: by an Invoke Script transaction or by a dApp. A callable function can perform actions: write data to the dApp data storage, transfer tokens from the dApp to other accounts, issue/release/burn tokens, and others. The result of a callable function is a tuple of two elements: a list of structures describing script actions and a value passed to the parent function in case of the [dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation). ```none @Callable(i) func giveAway(age: Int) = { ( [ ScriptTransfer(i.caller, age, unit), IntegerEntry(toBase58String(i.caller.bytes), age) ], unit ) } ``` Every caller of giveAway function will receive as many Decentralites as their age. The ScriptTransfer structure sets the parameters of the token transfer. dApp also will store information about the fact of the transfer in its data storage. The IntegerEntry structure sets the parameters of the entry: key and value. ## Built-in Functions A built-in function is a function of the standard library . ### Account Data Storage Functions Learn more about [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage). **Account Data Storage Functions** | Name | Description | Complexity | | --- | --- | --- | | [getBinary(Address\|Alias, String): ByteVector\|Unit](https://decentralchain.io/docs/ride/functions#getbinary-address-alias-string) | Gets an array of bytes by key | 10 | | [getBinary(String): ByteVector\|Unit](https://decentralchain.io/docs/ride/functions#getbinary-string) | Gets an array of bytes by key from dApp's own data storage | 10 | | [getBinaryValue(Address\|Alias, String): ByteVector](https://decentralchain.io/docs/ride/functions#getbinaryvalue-address-alias-string) | Gets an array of bytes by key. Fails if there is no data | 10 | | [getBinaryValue(String): ByteVector](https://decentralchain.io/docs/ride/functions#getbinaryvalue-string) | Gets an array of bytes by key from dApp's own data storage. Fails if there is no data | 10 | | [getBoolean(Address\|Alias, String): Boolean\|Unit](https://decentralchain.io/docs/ride/functions#getboolean-address-alias-string) | Gets a boolean value by key | 10 | | [getBoolean(String): Boolean\|Unit](https://decentralchain.io/docs/ride/functions#getboolean-string) | Gets a boolean value by key from dApp's own data storage | 10 | | [getBooleanValue(Address\|Alias, String): Boolean](https://decentralchain.io/docs/ride/functions#getbooleanvalue-address-alias-string) | Gets a boolean value by key. Fails if there is no data | 10 | | [getBooleanValue(String): Boolean](https://decentralchain.io/docs/ride/functions#getbooleanvalue-string) | Gets a boolean value by key from dApp's own data storage. Fails if there is no data | 10 | | [getInteger(Address\|Alias, String): Int\|Unit](https://decentralchain.io/docs/ride/functions#getinteger-address-alias-string) | Gets an integer by key | 10 | | [getInteger(String): Int\|Unit](https://decentralchain.io/docs/ride/functions#getinteger-string) | Gets an integer by key from dApp's own data storage | 10 | | [getIntegerValue(Address\|Alias, String): Int](https://decentralchain.io/docs/ride/functions#getintegervalue-address-alias-string) | Gets an integer by key. Fails if there is no data | 10 | | [getIntegerValue(String): Int](https://decentralchain.io/docs/ride/functions#getintegervalue-string) | Gets an integer by key from dApp's own data storage. Fails if there is no data | 10 | | [getString(Address\|Alias, String): String\|Unit](https://decentralchain.io/docs/ride/functions#getstring-address-alias-string) | Gets a string by key | 10 | | [getString(String): String\|Unit](https://decentralchain.io/docs/ride/functions#getstring-string) | Gets a string by key from dApp's own data storage | 10 | | [getStringValue(Address\|Alias, String): String](https://decentralchain.io/docs/ride/functions#getstringvalue-address-alias-string) | Gets a string by key. Fails if there is no data | 10 | | [getStringValue(String): String](https://decentralchain.io/docs/ride/functions#getstringvalue-string) | Gets a string by key from dApp's own data storage. Fails if there is no data | 10 | | [isDataStorageUntouched(Address\|Alias): Boolean](https://decentralchain.io/docs/ride/functions#isdatastorageuntouched-address-alias) | Checks if the data storage of a given account never contained any entries | 10 | #### getBinary(Address|Alias, String): ByteVector|Unit Gets an array of bytes by key. ```none getBinary(addressOrAlias: Address|Alias, key: String): ByteVector|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getBinary(String): ByteVector|Unit Gets an array of bytes by key from the dApp's own data storage. ```none getBinary(key: String): ByteVector|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getBinaryValue(Address|Alias, String): ByteVector Gets an array of bytes by key. Fails if there is no data. ```none getBinaryValue(addressOrAlias: Address|Alias, key: String): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getBinaryValue(String): ByteVector Gets an array of bytes by key from the dApp's own data storage. ```none getBinaryValue(key: String): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getBoolean(Address|Alias, String): Boolean|Unit Gets a boolean value by key. ```none getBoolean(addressOrAlias: Address|Alias, key: String): Boolean|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getBoolean(String): Boolean|Unit Gets a boolean value by key by key from the dApp's own data storage. ```none getBoolean(key: String): Boolean|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getBooleanValue(Address|Alias, String): Boolean Gets a boolean value by key. Fails if there is no data. ```none getBooleanValue(addressOrAlias: Address|Alias, key: String): Boolean ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getBooleanValue(String): Boolean Gets a boolean value by key from the dApp's own data storage. ```none getBooleanValue(key: String): Boolean ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getInteger(Address|Alias, String): Int|Unit Gets an integer by key. ```none getInteger(addressOrAlias: Address|Alias, key: String): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getInteger(String): Int|Unit Gets an integer by key from the dApp's own data storage. ```none getInteger(key: String): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getIntegerValue(Address|Alias, String): Int Gets an integer by key. Fails if there is no data. ```none getIntegerValue(addressOrAlias: Address|Alias, key: String): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getIntegerValue(String): Int Gets an integer by key from the dApp's own data storage. ```none getIntegerValue(key: String): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getString(Address|Alias, String): String|Unit Gets a string by key. ```none getString(addressOrAlias: Address|Alias, key: String): String|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getString(String): String|Unit Gets a string by key from the dApp's own data storage. ```none getString(key: String): String|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getStringValue(Address|Alias, String): String Gets a string by key. Fails if there is no data. ```none getStringValue(addressOrAlias: Address|Alias, key: String): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### getStringValue(String): String Gets a string by key from the dApp's own data storage. ```none getString(key: String): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. | #### isDataStorageUntouched(Address|Alias): Boolean Checks if the data storage of a given account never contained any entries. Returns false if there was at least one entry in the account data storage even if the entry was deleted. ```none isDataStorageUntouched(addressOrAlias: Address|Alias): Boolean ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | **Example** ```none let addr = Address(base58'3N4iKL6ikwxiL7yNvWQmw7rg3wGna8uL6LU') isDataStorageUntouched(addr) # Returns false ``` ### Blockchain Functions **Blockchain Functions** | Name | Description | Complexity | | --- | --- | --- | | [addressFromRecipient(Address\|Alias): Address](https://decentralchain.io/docs/ride/functions#addressfromrecipient-address-alias) | Gets the corresponding [address](https://decentralchain.io/docs/decentralchain/account#address) of the [alias](https://decentralchain.io/docs/decentralchain/account#alias) | 5 | | [assetBalance(Address\|Alias, ByteVector): Int](https://decentralchain.io/docs/ride/functions#assetbalance-address-alias-bytevector) | Gets account balance by token ID | 10 | | [assetInfo(ByteVector): Asset\|Unit](https://decentralchain.io/docs/ride/functions#assetinfo-bytevector) | Gets the information about a [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) | 15 | | [blockInfoByHeight(Int): BlockInfo\|Unit](https://decentralchain.io/docs/ride/functions#blockinfobyheight-int) | Gets the information about a [block](https://decentralchain.io/docs/decentralchain/block#block) by the block height | 5 | | [calculateAssetId(Issue): ByteVector](https://decentralchain.io/docs/ride/functions#calculateassetid-issue) | Calculates ID of the token formed by the [Issue](https://decentralchain.io/docs/ride/structures#issue) structure when executing the callable function | 10 | | [calculateLeaseId(Lease): ByteVector](https://decentralchain.io/docs/ride/functions#calculateleaseid-lease) | Calculates ID of the lease formed by the [Lease](https://decentralchain.io/docs/ride/structures#lease) structure when executing the callable function | 1 | | [scriptHash(Address\|Alias): ByteVector\|Unit](https://decentralchain.io/docs/ride/functions#scripthash-address-alias) | Returns BLAKE2b-256 hash of the script assigned to a given account | 200 | | [transactionHeightById(ByteVector): Int\|Unit](https://decentralchain.io/docs/ride/functions#transactionheightbyid-bytevector) | Gets the block height of a transaction | 20 | | [transferTransactionById(ByteVector): TransferTransaction\|Unit](https://decentralchain.io/docs/ride/functions#transfertransactionbyid-bytevector) | Gets the data of a [transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction) | 60 | | [decentralchainBalance(Address\|Alias): BalanceDetails](https://decentralchain.io/docs/ride/functions#decentralchainbalance-address-alias) | Gets account balance in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) | 10 | #### addressFromRecipient(Address|Alias): Address Gets the corresponding [address](https://decentralchain.io/docs/decentralchain/account#address) of the [alias](https://decentralchain.io/docs/decentralchain/account#alias). ```none addressFromRecipient(AddressOrAlias: Address|Alias): Address ``` For a description of the return value, see the [Address](https://decentralchain.io/docs/ride/structures#address) structure article. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | Address or alias, usually tx.recipient | | **Example** ```none let address = Address(base58'3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF') addressFromRecipient(address) ``` #### assetBalance(Address|Alias, ByteVector): Int Gets account balance by token ID. ```none assetBalance(addressOrAlias: Address|Alias, assetId: ByteVector): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | | assetId: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id) | #### assetInfo(ByteVector): Asset|Unit Gets the information about a [token (asset)](https://decentralchain.io/docs/decentralchain/token-asset#token-asset). ```none assetInfo(id: ByteVector): Asset|Unit ``` For a description of the return value, see the [BlockInfo](https://decentralchain.io/docs/ride/structures#blockinfo) structure article. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | id: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id) | **Example** ```none let bitcoinId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS' let x = match assetInfo(bitcoinId) { case asset:Asset => asset.decimals # 8 case _ => throw("Can't find asset") } ``` #### blockInfoByHeight(Int): BlockInfo|Unit Gets the information about a [block](https://decentralchain.io/docs/decentralchain/block#block) by the [block height](https://decentralchain.io/docs/decentralchain/block#block-height). ```none blockInfoByHeight(height: Int): BlockInfo|Unit ``` For a description of the return value, see the [BlockInfo](https://decentralchain.io/docs/ride/structures#blockinfo) structure article. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | height: [Int](https://decentralchain.io/docs/ride/data-types#int) | [block height](https://decentralchain.io/docs/decentralchain/block#block-height) | **Example** ```none let x = match blockInfoByHeight(1234567) { case block:BlockInfo => block.generator.toString() # "3P38Z9aMhGKAWnCiyMW4T3PcHcRaTAmTztH" case _ => throw("Can't find block") } ``` #### calculateAssetId(Issue): ByteVector Calculates ID of the token formed by the [Issue](https://decentralchain.io/docs/ride/structures#issue) structure when executing the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions). ```none calculateAssetId(issue: Issue): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | issue: [Issue](https://decentralchain.io/docs/ride/structures#issue) | Structure that sets the parameters of the token issue. | **Example** ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(inv) func issueAndId() = { let issue = Issue("CryptoRouble", "Description", 1000, 2, true) let id = calculateAssetId(issue) ( [ issue, BinaryEntry("id", id) ], unit ) } ``` #### calculateLeaseId(Lease): ByteVector Calculates ID of the lease formed by the [Lease](https://decentralchain.io/docs/ride/structures#lease) structure when executing the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions). ```none calculateLeaseId(lease: Lease): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | lease: [Lease](https://decentralchain.io/docs/ride/structures#lease) | Structure that sets the lease parameters. | **Example** ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(i) func foo() = { let lease = Lease(Alias("merry"),100000000) let id = calculateLeaseId(lease) ( [ lease, BinaryEntry("lease", id) ], unit ) } ``` #### scriptHash(Address|Alias): ByteVector|Unit Returns BLAKE2b-256 hash of the script assigned to a given account. Returns unit if there is no script. The function can be used to verify that the script is exactly the same as expected. ```none scriptHash(addressOrAlias: Address|Alias): ByteVector|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | **Example** ```none let addr = Address(base58'3MxBZbnN8Z8sbYjjL5N3oG5C8nWq9NMeCEm') scriptHash(addr) # Returns base58'G6ihnWN5mMedauCgNa8TDrSKWACPJKGQyYagmMQhPuja' ``` #### transactionHeightById(ByteVector): Int|Unit Gets the [block height](https://decentralchain.io/docs/decentralchain/block#block-height) of a transaction. ```none transactionHeightById(id: ByteVector): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | id: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | ID of the transaction. | **Example** ```none let bitcoinId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS' let x = match transactionHeightById(bitcoinId) { case h:Int => h # 257457 case _ => throw("Can't find transaction") } ``` #### transferTransactionById(ByteVector): TransferTransaction|Unit Gets the data of a [transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction). ```none transferTransactionById(id: ByteVector): TransferTransaction|Unit ``` For a description of the return value, see the [TransferTransaction](https://decentralchain.io/docs/ride/structures#transfertransaction) structure article. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | id: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | ID of the transfer transaction. | **Example** ```none let transferId = base58'J2rcMzCWCZ1P3SFZzvz9PR2NtBjomDh57HTcqptaAJHK' let x = match transferTransactionById(transferId) { case ttx:TransferTransaction => ttx.amount # 3500000000 case _ => throw("Can't find transaction") } ``` #### decentralchainBalance(Address|Alias): BalanceDetails Gets all types of [DecentralCoin](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) balances. For description of balance types, see the [account balance](https://decentralchain.io/docs/decentralchain/account#account-balance) article. ```none decentralchainBalance(addressOrAlias: Address|Alias): BalanceDetails ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addressOrAlias: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account. | ### Byte Array Functions **Byte Array Functions** | Name | Description | Complexity | | --- | --- | --- | | [drop(ByteVector, Int): ByteVector](https://decentralchain.io/docs/ride/functions#drop-bytevector-int) | Returns the byte array without the first N bytes | 6 | | [dropRight(ByteVector, Int): ByteVector](https://decentralchain.io/docs/ride/functions#dropright-bytevector-int) | Returns the byte array without the last N bytes | 6 | | [size(ByteVector): Int](https://decentralchain.io/docs/ride/functions#size-bytevector) | Returns the number of bytes in the byte array | 1 | | [take(ByteVector, Int): ByteVector](https://decentralchain.io/docs/ride/functions#take-bytevector-int) | Returns the first N bytes of the byte array | 6 | | [takeRight(ByteVector, Int): ByteVector](https://decentralchain.io/docs/ride/functions#takeright-bytevector-int) | Returns the last N bytes of the byte array | 6 | #### drop(ByteVector, Int): ByteVector Returns the byte array without the first N bytes. ```none drop(xs: ByteVector, number: Int): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Byte array. | | number: [Int](https://decentralchain.io/docs/ride/data-types#int) | N bytes. | **Example** ```none drop("Ride".toBytes(), 2) # Returns the byte array without the first 2 bytes drop(125.toBytes(), 2) # Returns the byte array without the first 2 bytes drop(base16'52696465', 3) # Returns the byte array without the first 3 bytes drop(base58'37BPKA', 3) # Returns the byte array without the first 3 bytes drop(base64'UmlkZQ==', 3) # Returns the byte array without the first 3 bytes ``` #### dropRight(ByteVector, Int): ByteVector Returns the byte array without the last N bytes. ```none dropRight(xs: ByteVector, number: Int): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Byte array. | | number: [Int](https://decentralchain.io/docs/ride/data-types#int) | N bytes. | **Example** ```none dropRight("Ride".toBytes(), 2) # Returns the byte array without the last 2 bytes dropRight(125.toBytes(), 2) # Returns the byte array without the last 2 bytes dropRight(base16'52696465', 3) # Returns the byte array without the last 3 bytes dropRight(base58'37BPKA', 3) # Returns the byte array without the last 3 bytes dropRight(base64'UmlkZQ==', 3) # Returns the byte array without the last 3 bytes ``` #### size(ByteVector): Int Returns the number of bytes in the byte array. ```none size(byteVector: ByteVector): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Byte array. | **Example** ```none size("Hello".toBytes()) # Returns 5 size("Hello world".toBytes()) # Returns 11 size(64.toBytes()) # Returns 8 because all integers in Ride take 8 bytes size(200000.toBytes()) # Returns 8 because all integers in Ride take 8 bytes size(base58'37BPKA') # Returns 4 ``` #### take(ByteVector, Int): ByteVector Returns the first N bytes of the byte array. ```none take(xs: ByteVector, number: Int): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Byte array. | | number: [Int](https://decentralchain.io/docs/ride/data-types#int) | N bytes. | **Example** ```none take(base58'37BPKA', 0) # Returns the empty byte array take(base58'37BPKA', 1) # Returns the byte array consisting of first byte of initial byte array take(base58'37BPKA', 15) # Returns whole byte array take(base58'37BPKA', -10) # Returns the empty byte array ``` #### takeRight(ByteVector, Int): ByteVector Returns the last N bytes of the byte array. ```none takeRight(xs: ByteVector, number: Int): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Byte array. | | number: [Int](https://decentralchain.io/docs/ride/data-types#int) | N bytes. | **Example** ```none takeRight(base58'37BPKA', 2) # Returns the last 2 bytes of the byte array ``` ### Converting Functions **Converting Functions** | Name | Description | Complexity | | --- | --- | --- | | [addressFromPublicKey(ByteVector): Address](https://decentralchain.io/docs/ride/functions#addressfrompublickey-bytevector) | Gets the corresponding [address](https://decentralchain.io/docs/decentralchain/account#address) of the account public key ` | 63 | | [parseBigInt(String): BigInt\|Unit](https://decentralchain.io/docs/ride/functions#parsebigint-string) | Converts the string representation of a number to its [big integer](https://decentralchain.io/docs/ride/data-types#bigint) equivalent | 65 | | [parseBigIntValue(String): BigInt](https://decentralchain.io/docs/ride/functions#parsebigintvalue-string) | Converts the string representation of a number to its big integer equivalent. Fails if the string cannot be parsed | 65 | | [parseInt(String): Int\|Unit](https://decentralchain.io/docs/ride/functions#parseint-string) | Converts the string representation of a number to its integer equivalent | 2 | | [parseIntValue(String): Int](https://decentralchain.io/docs/ride/functions#parseintvalue-string) | Converts the string representation of a number to its integer equivalent. Fails if the string cannot be parsed | 2 | | [toBigInt(ByteVector): BigInt](https://decentralchain.io/docs/ride/functions#tobigint-bytevector) | Converts an array of bytes to a big integer | 65 | | [toBigInt(ByteVector, Int, Int): BigInt](https://decentralchain.io/docs/ride/functions#tobigint-bytevector-int-int) | Converts an array of bytes starting from a certain index to a big integer | 65 | | [toBigInt(Int): BigInt](https://decentralchain.io/docs/ride/functions#tobigint-int) | Converts an integer to a big integer | 1 | | [toBytes(Boolean): ByteVector](https://decentralchain.io/docs/ride/functions#tobytes-boolean) | Converts a boolean to an array of bytes | 1 | | [toBytes(Int): ByteVector](https://decentralchain.io/docs/ride/functions#tobytes-int) | Converts an integer to an array of bytes | 1 | | [toBytes(String): ByteVector](https://decentralchain.io/docs/ride/functions#tobytes-string) | Converts a string to an array of bytes | 8 | | [toBytes(BigInt): ByteVector](https://decentralchain.io/docs/ride/functions#tobytes-bigint) | Converts a big integer to an array of bytes | 65 | | [toInt(BigInt): Int](https://decentralchain.io/docs/ride/functions#toint-bigint) | Converts a big integer to an integer. Fails if the number cannot be converted | 1 | | [toInt(ByteVector): Int](https://decentralchain.io/docs/ride/functions#toint-bytevector) | Converts an array of bytes to an integer | 1 | | [toInt(ByteVector, Int): Int](https://decentralchain.io/docs/ride/functions#toint-bytevector-int) | Converts an array of bytes to an integer starting from a certain index | 1 | | [toString(Address): String](https://decentralchain.io/docs/ride/functions#tostring-address) | Converts an address to a string | 10 | | [toString(Boolean): String](https://decentralchain.io/docs/ride/functions#tostring-boolean) | Converts a boolean to a string | 1 | | [toString(Int): String](https://decentralchain.io/docs/ride/functions#tostring-int) | Converts an integer to a string | 1 | | [toString(BigInt): String](https://decentralchain.io/docs/ride/functions#tostring-bigint) | Converts a big integer to a string | 65 | | [toUtf8String(ByteVector): String](https://decentralchain.io/docs/ride/functions#toutf8string-bytevector) | Converts an array of bytes to a UTF-8 string | 7 | | [transferTransactionFromProto(ByteVector): TransferTransaction\|Unit](https://decentralchain.io/docs/ride/functions#transfertransactionfromproto-bytevector) | Deserializes transfer transaction | 5 | #### addressFromPublicKey(ByteVector): Address Gets the corresponding [address](https://decentralchain.io/docs/decentralchain/account#address) of the account public key. ```none addressFromPublicKey(publicKey: ByteVector): Address ``` For a description of the return value, see the [Address](https://decentralchain.io/docs/ride/structures#address) structure article. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | publicKey: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key. | **Example** ```none let address = addressFromPublicKey(base58'J1t6NBs5Hd588Dn7mAPytqkhgeBshzv3zecScfFJWE2D') ``` #### parseBigInt(String): BigInt|Unit Converts the string representation of a number to its [big integer](https://decentralchain.io/docs/ride/data-types#bigint) equivalent. ```none parseBigInt(str: String): BigInt|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | String to parse. | #### parseBigIntValue(String): BigInt Converts the string representation of a number to its [big integer](https://decentralchain.io/docs/ride/data-types#bigint) equivalent. Fails if the string cannot be parsed. ```none parseBigIntValue(str: String): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | String to parse. | #### parseInt(String): Int|Unit Converts the string representation of a number to its integer equivalent. ```none parseInt(str: String): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | String to parse. | **Example** ```none parseInt("10") # Returns 10 parseInt("010") # Returns 10 parseInt("Ride") # Returns Unit parseInt("10.30") # Returns Unit ``` #### parseIntValue(String): Int Converts the string representation of a number to its integer equivalent. Fails if the string cannot be parsed. ```none parseIntValue(str: String): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | String to parse. | **Example** ```none parseIntValue("10") # Returns 10 parseIntValue("010") # Returns 10 parseIntValue("Ride") # Error while parsing string to integer parseIntValue("10.30") # Error while parsing string to integer parseIntValue("20 DecentralCoins") # Error while parsing string to integer ``` #### toBigInt(ByteVector): BigInt Converts an array of bytes to a [big integer](https://decentralchain.io/docs/ride/data-types#bigint) using the big-endian byte order. ```none toBigInt(bin: ByteVector): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bin: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes to convert. | #### toBigInt(ByteVector, Int, Int): BigInt Converts an array of bytes starting from a certain index to a [big integer](https://decentralchain.io/docs/ride/data-types#bigint) using the big-endian byte order. ```none toBigInt(bin: ByteVector, offset: Int, size: Int): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bin: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes to convert. | | offset: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index to start from. | | size: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of bytes (subarray length) to convert. | #### toBigInt(Int): BigInt Converts an integer to a [big integer](https://decentralchain.io/docs/ride/data-types#bigint). ```none toBigInt(n: Int): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | n: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer to convert. | #### toBytes(Boolean): ByteVector Converts a boolean value to an array of bytes. ```none toBytes(b: Boolean): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | b: [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | Boolean to convert. | **Example** ```none toBytes(true) # Returns base58'2' toBytes(false) # Returns base58'1' ``` #### toBytes(Int): ByteVector Converts an integer to an array of bytes using the big-endian byte order. ```none toBytes(n: Int): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | n: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer to convert. | **Example** ```none toBytes(10) # Returns base58'1111111B' ``` #### toBytes(String): ByteVector Converts a string to an array of bytes. ```none toBytes(s: String): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | String to convert. | **Example** ```none toBytes("Ride") # Returns base58'37BPKA' ``` #### toBytes(BigInt): ByteVector Converts a [big integer](https://decentralchain.io/docs/ride/data-types#bigint) to an array of bytes using the big-endian byte order. ```none toBytes(n: BigInt): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | n: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer to convert. | #### toInt(BigInt): Int Converts a [big integer](https://decentralchain.io/docs/ride/data-types#bigint) to an integer. Fails if the number cannot be converted. ```none toInt(n: BigInt): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | n: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer to convert. | #### toInt(ByteVector): Int Converts an array of bytes to an integer using the big-endian byte order. ```none toInt(bin: ByteVector) : Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bin: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes to convert. | **Example** ```none toInt(base58'1111111B') # Returns 10 ``` #### toInt(ByteVector, Int): Int Converts an array of bytes to an integer starting from a certain index using the big-endian byte order. ```none toInt(bin: ByteVector, offset: Int): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bin: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes to convert. | | offset: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index to start from. | **Example** ```none let bytes = toBytes("Ride") toInt(bytes, 2) # Returns 7234224039401641825 toInt(bytes, 6) # Index out of bounds ``` #### toString(Address): String Converts an array of bytes of an [address](https://decentralchain.io/docs/decentralchain/account#address) to a string. ```none toString(addr: Address): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | addr: [Address](https://decentralchain.io/docs/ride/structures#address) | Address to convert. | **Example** ```none let address = Address(base58'3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF') toString(address) # Returns "3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF" ``` #### toString(Boolean): String Converts a boolean value to a string. ```none toString(b: Boolean): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | b: [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | Boolean to convert. | **Example** ```none toString(true) # Returns "true" toString(false) # Returns "false" ``` #### toString(Int): String Converts an integer to a string. ```none toString(n: Int): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | n: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer to convert. | **Example** ```none toString(10) # Returns "10" ``` #### toString(BigInt): String Converts a [big integer](https://decentralchain.io/docs/ride/data-types#bigint) to a string. ```none toString(n: BigInt): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | n: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer to convert. | #### toUtf8String(ByteVector): String Converts an array of bytes to a UTF-8 string. Fails if the array of bytes cotains an invalid UTF-8 sequence. ```none toUtf8String(u: ByteVector): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | u: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes to convert. | **Example** ```none let bytes = toBytes("Ride") toUtf8String(bytes) # Returns "Ride" ``` #### transferTransactionFromProto(ByteVector): TransferTransaction|Unit Deserializes transfer transaction: converts protobuf-encoded [binary format](https://decentralchain.io/docs/decentralchain/binary-format#transfer-transaction-binary-format) specified in transaction.proto to a TransferTransaction structure. Returns unit if deserialization failed. ```none transferTransactionFromProto(b: ByteVector): TransferTransaction|Unit ``` For a description of the return value, see the [TransferTransaction](https://decentralchain.io/docs/ride/structures#transfertransaction) structure article. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | b: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transfer transaction in protobuf-encoded binary format. | **Example** ```none let transfer = base64'Cr4BCFQSIA7SdnwUqEBY+k4jUf9sCV5+xj0Ry/GYuwmDMCdKTdl3GgQQoI0GIPLIyqL6LSgDwgaHAQoWChT+/s+ZWeOWzh1eRnhdRL3Qh9bxGRIkCiBO/wEBhwH/f/+bAWBRMv+A2yiAOUeBc9rY+UR/a4DxKBBkGkcaRYCcAQAB//9/AX9//0695P8EiICAfxgBgIkefwHYuDmA//83/4ABJgEBAf8d9N+8AAERyo1/j3kAGn/SAb7YIH8y/4CAXg==' let x = match transferTransactionFromProto(transfer) { case ttx:TransferTransaction => ttx.amount # 3500000000 case _ => throw("Can't find transaction") } ``` ### dApp-to-dApp Invocation Functions **dApp-to-dApp Invocation Functions** | Name | Description | Complexity | | --- | --- | --- | | [invoke(Address\|Alias, String, List[Any], List[AttachedPayments]): Any](https://decentralchain.io/docs/ride/functions#invoke-address-alias-string-list-any-list-attachedpayments) | Invokes a dApp callable function, with [reentrancy restriction](https://decentralchain.io/docs/ride/functions#dapp-to-dapp-invocation-functions) | 75 | | [reentrantInvoke(Address\|Alias, String, List[Any], List[AttachedPayments]): Any](https://decentralchain.io/docs/ride/functions#reentrantinvoke-address-alias-string-list-any-list-attachedpayments) | Invokes a dApp callable function, without reentrancy restriction | 75 | #### invoke(Address|Alias, String, List[Any], List[AttachedPayments]): Any Invokes a dApp [callable function](https://decentralchain.io/docs/ride/functions#callable-functions), with reentrancy restriction. ```none invoke(dApp: Address|Alias, function: String, arguments: List[Any], payments: List[AttachedPayments]): Any ``` Any means any valid type. You can extract a particular type from it using as[T] and exactAs[T] macros or the match ... case operator, see the [any](https://decentralchain.io/docs/ride/data-types#any) article. The invoke function can be used by a callable function of a [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script), but not by a verifier function, [account script](https://decentralchain.io/docs/ride/script-types#account-script) or [asset script](https://decentralchain.io/docs/ride/script-types#asset-script). Via the invoke function, the callable function can invoke a callable function of another dApp, or another callable function of the same dApp, or even itself, and then use the invocation results in subsequent operations. For details, see the [dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation) article. To ensure executing callable functions and applying their actions in the right order, initialize a [strict variable](https://decentralchain.io/docs/ride/syntax-basics#strict-variables) by the return value of an invoke function. The invocation can contain payments that will be transferred from the balance of the parent dApp to the balance of the invoked dApp. Payments are forbidden if the dApp invokes itself. If a payment token is a smart asset, the asset script verifies the invoke as if it was [InvokeScriptTransaction](https://decentralchain.io/docs/ride/structures#invokescripttransaction) structure with the following fields: - DApp, payments, function, args indicated in the invoke function. - Sender, senderPublicKey of the dApp that performs the invocation. - Id, timestamp, fee, feeAssetId indicated in the original invoke script transaction. - Version = 0; If the asset script denies the action, the Invoke Script transaction is either discarded or saved on the blockchain as failed, see the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation) article. **Reentrancy Restriction** The invocation stack generated by the invoke function must not contain invocations of the parent dApp after invocation of another dApp. Let the parent dApp A invokes dApp B using the invoke function. Regardless of whether dApp B uses invoke or reentrantInvoke, the following invocation stacks will fail: ```none → dApp A → dapp B → dApp A ``` ```none → dApp A → dapp B → dApp C → dApp A ``` The following invocation stacks are valid: ```none → dApp A → dapp A → dapp A ``` ```none → dApp N → dapp A → dApp A ``` ```none → dapp N → dapp A → dapp B → dapp B → dapp A → dapp C ``` **Parameters** | Parameter | Description | | --- | --- | | dApp: [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of a dApp to invoke. | | function: [String](https://decentralchain.io/docs/ride/data-types#string) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | Name of a callable function. Unit for a default function invocation. | | arguments: [List](https://decentralchain.io/docs/ride/data-types#list) [[Any](https://decentralchain.io/docs/ride/data-types#any)] | Parameters of a callable function. | | payments: [List](https://decentralchain.io/docs/ride/data-types#list) [[AttachedPayment](https://decentralchain.io/docs/ride/structures#attachedpayment)] | Payments to transfer from the parent dApp to the invoked dApp, up to 10. | **Example** A user sends an invoke script transaction that invokes the callable function foo of dApp1. The foo function invokes the bar function of dApp2 passing the number a and attaching a payment of 1 USDN. The bar function transfers 1 [DecentralCoin](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to dApp1 and returns the doubled number a. The foo function writes to dApp1 data storage: - The value returned by bar. - The new balance of dApp2 (reduced by 1 DecentralCoin transferred to dApp1). dApp1: ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(i) func foo(dapp2: String, a: Int, key1: String, key2: String) = { strict res = invoke(addressFromStringValue(dapp2),"bar",[a],[AttachedPayment(base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p',1000000)]) match res { case r : Int => ( [ IntegerEntry(key1, r), IntegerEntry(key2, decentralchainBalance(addressFromStringValue(dapp2)).regular) ], unit ) case _ => throw("Incorrect invoke result") } } ``` dApp2: ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(i) func bar(a: Int) = { ( [ ScriptTransfer(i.caller, 100000000, unit) ], a*2 ) } ``` #### reentrantInvoke(Address|Alias, String, List[Any], List[AttachedPayments]): Any Invokes a dApp [callable function](https://decentralchain.io/docs/ride/functions#callable-functions). The only difference from the invoke function above is that there is no reentrancy restriction for the parent dApp that uses reentrantInvoke. However, if the parent dApp is invoked again and this time uses the invoke function, the parent dApp cannot be invoked again in this invocation stack. For example, the invocation stack: ```none → dApp A → dapp B → dApp A → dApp C → dApp A ``` - Is valid if dApp A invokes both dApp B and dApp C via the reentrantInvoke function; - Fails if dApp A invokes dApp B via the reentrantInvoke function and invokes dApp C via the invoke function. ```none reentrantInvoke(dApp: Address|Alias, function: String, arguments: List[Any], payments: List[AttachedPayments]): Any ``` ### Data Transaction Functions The functions listed below retrieve data by key from the [DataTransaction](https://decentralchain.io/docs/ride/structures#datatransaction) structure or from any list of data entries. **Data Transaction Functions** | Name | Description | Complexity | | --- | --- | --- | | [getBinary(List[], String): ByteVector\|Unit](https://decentralchain.io/docs/ride/functions#getbinary-list-string) | Gets a binary value from a list of data entires by key | 10 | | [getBinary(List[], Int): ByteVector\|Unit](https://decentralchain.io/docs/ride/functions#getbinary-list-int) | Gets a binary value from a list of data entires by index | 4 | | [getBinaryValue(List[], String): ByteVector](https://decentralchain.io/docs/ride/functions#getbinaryvalue-list-string) | Gets a binary value from a list of data entires by key. Fails if there is no data | 10 | | [getBinaryValue(List[], Int): ByteVector](https://decentralchain.io/docs/ride/functions#getbinaryvalue-list-int) | Gets a binary value from a list of data entires by index. Fails if there is no data | 4 | | [getBoolean(List[], String): Boolean\|Unit](https://decentralchain.io/docs/ride/functions#getboolean-list-string) | Gets a boolean value from a list of data entires by key | 10 | | [getBoolean(List[], Int): Boolean\|Unit](https://decentralchain.io/docs/ride/functions#getboolean-list-int) | Gets a boolean value from a list of data entires by index | 4 | | [getBooleanValue(List[], String): Boolean](https://decentralchain.io/docs/ride/functions#getbooleanvalue-list-string) | Gets a boolean value from a list of data entires by key. Fails if there is no data | 10 | | [getBooleanValue(List[], Int): Boolean](https://decentralchain.io/docs/ride/functions#getbooleanvalue-list-int) | Gets a boolean value from a list of data entires by index. Fails if there is no data | 4 | | [getInteger(List[], String): Int\|Unit](https://decentralchain.io/docs/ride/functions#getinteger-list-string) | Gets an integer value from a list of data entires by key | 10 | | [getInteger(List[], Int): Int\|Unit](https://decentralchain.io/docs/ride/functions#getinteger-list-int) | Gets an integer value from a list of data entires by index | 4 | | [getIntegerValue(List[], String): Int](https://decentralchain.io/docs/ride/functions#getintegervalue-list-string) | Gets an integer value from a list of data entires by key. Fails if there is no data | 10 | | [getIntegerValue(List[], Int): Int](https://decentralchain.io/docs/ride/functions#getintegervalue-list-int) | Gets an integer value from a list of data entires by index. Fails if there is no data | 4 | | [getString(List[], String): String\|Unit](https://decentralchain.io/docs/ride/functions#getstring-list-string) | Gets a string value from a list of data entires by key | 10 | | [getString(List[], Int): String\|Unit](https://decentralchain.io/docs/ride/functions#getstring-list-int) | Gets a string value from a list of data entires by index | 4 | | [getStringValue(List[], String): String](https://decentralchain.io/docs/ride/functions#getstringvalue-list-string) | Gets a string value from a list of data entires by key. Fails if there is no data | 10 | | [getStringValue(List[], Int): String](https://decentralchain.io/docs/ride/functions#getstringvalue-list-int) | Gets a string value from a list of data entires by index. Fails if there is no data | 4 | #### getBinary(List[], String): ByteVector|Unit Gets a binary value from a list of data entires by key. ```none getBinary(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): ByteVector|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Key. | #### getBinary(List[], Int): ByteVector|Unit Gets a binary value from a list of data entires by index. ```none getBinary(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): ByteVector|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index. | #### getBinaryValue(List[], String): ByteVector Gets a binary value from a list of data entires by key. Fails if there is no data. ```none getBinaryValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Key. | #### getBinaryValue(List[], Int): ByteVector Gets a binary value from a list of data entires by index. Fails if there is no data. ```none getBinaryValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index. | #### getBoolean(List[], String): Boolean|Unit Gets a boolean value from a list of data entires by key. ```none getBoolean(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): Boolean|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Key. | #### getBoolean(List[], Int): Boolean|Unit Gets a boolean value from a list of data entires by index. ```none getBoolean(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): Boolean|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index. | #### getBooleanValue(List[], String): Boolean Gets a boolean value from a list of data entires by key. Fails if there is no data. ```none getBooleanValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): Boolean ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Key. | #### getBooleanValue(List[], Int): Boolean Gets a boolean value from a list of data entires by index. Fails if there is no data. ```none getBooleanValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): Boolean ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index. | #### getInteger(List[], String): Int|Unit Gets integer from a list of data entires by key. ```none getInteger(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Key. | #### getInteger(List[], Int): Int|Unit Gets an integer value from a list of data entires by index. ```none getInteger(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index. | #### getIntegerValue(List[], String): Int Gets an integer value from a list of data entires by key. Fails if there is no data. ```none getIntegerValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Key. | #### getIntegerValue(List[], Int): Int Gets an integer value from a list of data entires by index. Fails if there is no data. ```none getIntegerValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index. | #### getString(List[], String): String|Unit Gets a string value from a list of data entires by key. ```none getString(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): String|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Key. | #### getString(List[], Int): String|Unit Gets a string value from a list of data entires by key. ```none getString(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): String|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index. | #### getStringValue(List[], String): String Gets a string value from a list of data entires by key. Fails if there is no data. ```none getStringValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | key: [String](https://decentralchain.io/docs/ride/data-types#string) | Key. | #### getStringValue(List[], Int): String Gets a string value from a list of data entires by index. Fails if there is no data. ```none getStringValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | data: [List](https://decentralchain.io/docs/ride/data-types#list) [] | List of data entries, usually tx.data. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index. | ### Decoding Functions **Decoding Functions** | Name | Description | Complexity | | --- | --- | --- | | [addressFromString(String): Address\|Unit](https://decentralchain.io/docs/ride/functions#addressfromstring-string) | Decodes address from base58 string | 1 | | [addressFromStringValue(String): Address](https://decentralchain.io/docs/ride/functions#addressfromstringvalue-string) | Decodes address from base58 string. Fails if the address cannot be decoded | 1 | | [fromBase16String(String): ByteVector](https://decentralchain.io/docs/ride/functions#frombase16string-string) | Decodes base16 string to an array of bytes | 10 | | [fromBase58String(String): ByteVector](https://decentralchain.io/docs/ride/functions#frombase58string-string) | Decodes base58 string to an array of bytes | 1 | | [fromBase64String(String): ByteVector](https://decentralchain.io/docs/ride/functions#frombase64string-string) | Decodes base64 string to an array of bytes | 40 | #### addressFromString(String): Address|Unit Decodes address from base58 string. ```none addressFromString(string: String): Address|Unit ``` For a description of the return value, see the [Address](https://decentralchain.io/docs/ride/structures#address) structure article. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | string: [string](https://decentralchain.io/docs/ride/data-types#string) | String to decode. | **Example** ```none let address = addressFromString("3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF") ``` #### addressFromStringValue(String): Address Decodes address from base58 string. Fails if the address cannot be decoded. ```none addressFromStringValue(string: String): Address ``` For a description of the return value, see the [Address](https://decentralchain.io/docs/ride/structures#address) structure article. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | string: [string](https://decentralchain.io/docs/ride/data-types#string) | String to decode. | **Example** ```none let address = addressFromStringValue("3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF") ``` #### fromBase16String(String): ByteVector Decodes a base16 string to an array of bytes. ```none fromBase16String(str: String): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | string: [string](https://decentralchain.io/docs/ride/data-types#string) | String to decode. | **Example** ```none let bytes = fromBase16String("52696465") ``` #### fromBase58String(String): ByteVector Decodes a base58 string to an array of bytes. ```none fromBase58String(str: String): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | string: [string](https://decentralchain.io/docs/ride/data-types#string) | String to decode. | **Example** ```none let bytes = fromBase58String("37BPKA") ``` #### fromBase64String(String): ByteVector Decodes a base64 string to an array of bytes. ```none fromBase64String(str: String): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | string: [string](https://decentralchain.io/docs/ride/data-types#string) | String to decode. | **Example** ```none let bytes = fromBase64String("UmlkZQ==") ``` ### Encoding Functions **Encoding Functions** | Name | Description | Complexity | | --- | --- | --- | | [toBase16String(ByteVector): String](https://decentralchain.io/docs/ride/functions#tobase16string-bytevector) | Encodes array of bytes to base16 string | 10 | | [toBase58String(ByteVector): String](https://decentralchain.io/docs/ride/functions#tobase58string-bytevector) | Encodes array of bytes to base58 string | 3 | | [toBase64String(ByteVector): String](https://decentralchain.io/docs/ride/functions#tobase64string-bytevector) | Encodes array of bytes to base64 string | 35 | #### toBase16String(ByteVector): String Encodes an array of bytes to a base16 string. ```none toBase16String(bytes: ByteVector): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bytes: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes to encode. | **Example** ```none toBase16String("Ride".toBytes()) # Returns "52696465" toBase16String(base16'52696465') # Returns "52696465" ``` #### toBase58String(ByteVector): String Encodes an array of bytes to a base58 string. ```none toBase58String(bytes: ByteVector): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bytes: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes to encode. | **Example** ```none toBase58String("Ride".toBytes()) # Returns "37BPKA" toBase58String(base58'37BPKA') # Returns "37BPKA ``` #### toBase64String(ByteVector): String Encodes an array of bytes to a base64 string. ```none toBase64String(bytes: ByteVector): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bytes: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes to encode. | **Example** ```none toBase64String("Ride".toBytes()) # Returns "UmlkZQ==" toBase64String(base64'UmlkZQ==') # Returns "UmlkZQ==" ``` ### Exception Functions **Exception Functions** | Name | Description | Complexity | | --- | --- | --- | | [throw()](https://decentralchain.io/docs/ride/functions#throw) | Raises an exception | 1 | | [throw(String)](https://decentralchain.io/docs/ride/functions#throw-string) | Raises an exception with a message | 1 | The return type of throw is nothing. There is no exception handling in Ride: after an exception has been thrown, the script execution fails. The transaction can be either discarded or saved on the blockchain as failed, see the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation) article for details. #### throw() Raises an exception. #### throw(String) Raises an exception with a message. ```none throw(err: String) ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | err: [String](https://decentralchain.io/docs/ride/data-types#string) | The exception message. | ### Hashing Functions **Hashing Functions** | Name | Description | Complexity | | --- | --- | --- | | [blake2b256(ByteVector): ByteVector](https://decentralchain.io/docs/ride/functions#blake2b256-bytevector) | Range of functions. Hash an array of bytes using BLAKE2b-256 | 10–200 | | [keccak256(ByteVector): ByteVector](https://decentralchain.io/docs/ride/functions#keccak256-bytevector) | Range of functions. Hash an array of bytes using Keccak-256 | 10–200 | | [sha256(ByteVector): ByteVector](https://decentralchain.io/docs/ride/functions#sha256-bytevector) | Range of functions. Hash an array of bytes using SHA-256 | 10–200 | #### blake2b256(ByteVector): ByteVector Range of functions that hash an array of bytes using BLAKE2b-256. **blake2b256** | Name | Max data size | Complexity | | --- | --- | --- | | blake2b256(bytes: ByteVector): ByteVector | 150 kB | 200 | | blake2b256_16Kb(bytes: ByteVector): ByteVector | 16 kB | 10 | | blake2b256_32Kb(bytes: ByteVector): ByteVector | 32 kB | 25 | | blake2b256_64Kb(bytes: ByteVector): ByteVector | 64 kB | 50 | | blake2b256_128Kb(bytes: ByteVector): ByteVector | 128 kB | 100 | **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bytes: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | The array of bytes to encode. Maximum size: 1) For blake2b256_Kb functions — N kB. 2) For blake2b256 function — 150 kB. | **Example** ```none blake2b256("Ride".toBytes()) # Returns 6NSWRz5XthhFVm9uVQHuisdaseQJfc4WMGajN435v3f4 blake2b256(125.toBytes())  # Returns H9emWhyMuyyjDmNkgx7jAfHRuy9icXK3uYJuVw6R1uuK blake2b256(base16'52696465') # Returns 6NSWRz5XthhFVm9uVQHuisdaseQJfc4WMGajN435v3f4 blake2b256(base58'37BPKA')  # Returns 6NSWRz5XthhFVm9uVQHuisdaseQJfc4WMGajN435v3f4 blake2b256(base64'UmlkZQ==') # Returns 6NSWRz5XthhFVm9uVQHuisdaseQJfc4WMGajN435v3f4 ``` #### keccak256(ByteVector): ByteVector Range of functions that hash an array of bytes using Keccak-256. **keccak256** | Name | Max data size | Complexity | | --- | --- | --- | | keccak256(bytes: ByteVector): ByteVector, 150 kB, 200 | | keccak256_16Kb(bytes: ByteVector): ByteVector, 16 kB, 10 | | keccak256_32Kb(bytes: ByteVector): ByteVector, 32 kB, 25 | | keccak256_64Kb(bytes: ByteVector): ByteVector, 64 kB, 50 | | keccak256_128Kb(bytes: ByteVector): ByteVector, 128 kB, 100 | **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bytes: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | The array of bytes to encode. Maximum size: 1) For keccak256_Kb functions — N kB. 2) For keccak256 function — 150 kB. | **Example** ```none keccak256("Ride".toBytes()) # Returns 4qa5wNk4961VwJAjCKBzXiEvBQ2gBJoqDcLFRJTiSKpv keccak256(125.toBytes())  # Returns 5UUkcH6Fp2E3mk7NSqSTs3JBP33zL3SB3yg4b2sR5gpF keccak256(base16'52696465') # Returns 4qa5wNk4961VwJAjCKBzXiEvBQ2gBJoqDcLFRJTiSKpv keccak256(base58'37BPKA')  # Returns 4qa5wNk4961VwJAjCKBzXiEvBQ2gBJoqDcLFRJTiSKpv keccak256(base64'UmlkZQ==') # Returns 4qa5wNk4961VwJAjCKBzXiEvBQ2gBJoqDcLFRJTiSKpv ``` #### sha256(ByteVector): ByteVector Range of functions that hash an array of bytes using SHA-256. **sha256** | Name | Max data size | Complexity | | --- | --- | --- | | sha256(bytes: ByteVector): ByteVector, 150 kB, 200 | | sha256_16Kb(bytes: ByteVector): ByteVector, 16 kB, 10 | | sha256_32Kb(bytes: ByteVector): ByteVector, 32 kB, 25 | | sha256_64Kb(bytes: ByteVector): ByteVector, 64 kB, 50 | | sha256_128Kb(bytes: ByteVector): ByteVector, 128 kB, 100 | **Parameters** **Parameters** | Parameter | Description | | --- | --- | | bytes: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | The array of bytes to encode. Maximum size: 1) For sha256_Kb functions — N kB. 2) For sha256 function — 150 kB. | **Example** ```none sha256("Ride".toBytes()) # Returns 5YxvrKsjJtq4G325gRVxbXpkox1sWdHUGVJLnRFqTWD3 sha256(125.toBytes())  # Returns A56kbJjy7A4B9Pa5tUgRNvtCHSsZ7pZVJuPsLT2vtPSU sha256(base16'52696465') # Returns 5YxvrKsjJtq4G325gRVxbXpkox1sWdHUGVJLnRFqTWD3 sha256(base58'37BPKA')  # Returns 5YxvrKsjJtq4G325gRVxbXpkox1sWdHUGVJLnRFqTWD3 sha256(base64'UmlkZQ==') # Returns 5YxvrKsjJtq4G325gRVxbXpkox1sWdHUGVJLnRFqTWD3 ``` ### List Functions **List Functions** | Name | Description | Complexity | | --- | --- | --- | | [cons(A, List[B]): List[A\|B]](https://decentralchain.io/docs/ride/functions#cons-a-list-b) | Inserts element to the beginning of the list | 1 | | [containsElement(List[T], T): Boolean](https://decentralchain.io/docs/ride/functions#containselement-list-t-t) | Check if the element is in the list | 5 | | [getElement(List[T], Int): T](https://decentralchain.io/docs/ride/functions#getelement-list-t-int) | Gets element from the list | 2 | | [indexOf(List[T], T): Int\|Unit](https://decentralchain.io/docs/ride/functions#indexof-list-t-t) | Returns the index of the first occurrence of the element in the list | 5 | | [lastIndexOf(List[T], T): Int\|Unit](https://decentralchain.io/docs/ride/functions#lastindexof-list-t-t) | Returns the index of the last occurrence of the element in the list | 5 | | [max(List[Int]): Int](https://decentralchain.io/docs/ride/functions#max-list-int) | Returns the largest element in the list of integers | 3 | | [max(List[BigInt]): BigInt](https://decentralchain.io/docs/ride/functions#max-list-bigint) | Returns the largest element in the list of big integers | 192 | | [min(List[Int]): Int](https://decentralchain.io/docs/ride/functions#min-list-int) | Returns the smallest element in the list of integers | 3 | | [min(List[BigInt]): BigInt](https://decentralchain.io/docs/ride/functions#min-list-bigint) | Returns the smallest element in the list of big integers | 192 | | [removeByIndex(List[T], Int): List[T]](https://decentralchain.io/docs/ride/functions#removebyindex-list-t-int) | Removes an element from the list by index | 7 | | [size(List[T]): Int](https://decentralchain.io/docs/ride/functions#size-list-t) | Returns the size of the list | 2 | A, B, T means any valid type. #### cons(A, List[B]): List[A|B] Inserts element to the beginning of the [list](https://decentralchain.io/docs/ride/data-types#list). ```none cons(head:T, tail: List[T]): List[T] ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | head: T | Element | | tail: [List](https://decentralchain.io/docs/ride/data-types#list) [T] | List | **Example** ```none cons("Hello", ["World", "."]) # Returns ["Hello", "World", "."] cons(1, [2, 3, 4, 5]) # Returns [1, 2, 3, 4, 5] ``` #### containsElement(List[T], T): Boolean Check if the element is in the [list](https://decentralchain.io/docs/ride/data-types#list). ```none containsElement(list: List[T], element: T): Boolean ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | list: [List](https://decentralchain.io/docs/ride/data-types#list) [T] | List | | element: T | Element to search for | #### getElement(List[T], Int): T Gets the element from the [list](https://decentralchain.io/docs/ride/data-types#list) by index. ```none getElement(arr: List[T], pos: Int): T ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | arr: [List](https://decentralchain.io/docs/ride/data-types#list) [T] | List | | pos: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index of the element | **Example** ```none getElement(["Hello", "World", "."], 0) # Returns "Hello" getElement([false, true], 1) # Returns true ``` #### indexOf(List[T], T): Int|Unit Returns the index of the first occurrence of the element in the [list](https://decentralchain.io/docs/ride/data-types#list) or unit if the element is missing. ```none indexOf(list: List[T], element: T): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | list: [List](https://decentralchain.io/docs/ride/data-types#list) [T] | List | | element: T | Element to locate | **Example** ```none let stringList = ["a","b","a","c"] indexOf("a", stringList) # Returns 0 ``` #### lastIndexOf(List[T], T): Int|Unit Returns the index of the last occurrence of the element in the [list](https://decentralchain.io/docs/ride/data-types#list) or unit if the element is missing. ```none lastIndexOf(list: List[T], element: T): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | list: [List](https://decentralchain.io/docs/ride/data-types#list) [T] | List | | element: T | Element to locate | **Example** ```none let stringList = ["a","b","a","c"] lastIndexOf("a", stringList) # Returns 2 ``` #### max(List[Int]): Int Returns the largest element in the [list](https://decentralchain.io/docs/ride/data-types#list) of integers. Fails if the list is empty. ```none max(List[Int]): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | list: [List](https://decentralchain.io/docs/ride/data-types#list) [[Int](https://decentralchain.io/docs/ride/data-types#int)] | List | #### max(List[BigInt]): BigInt Returns the largest element in the list of [big integers](https://decentralchain.io/docs/ride/data-types#bigint). Fails if the list is empty. ```none max(List[BigInt]): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | list: [List](https://decentralchain.io/docs/ride/data-types#list) [[BigInt](https://decentralchain.io/docs/ride/data-types#bigint)] | List | #### min(List[Int]): Int Returns the smallest element in the [list](https://decentralchain.io/docs/ride/data-types#list) of integers. Fails if the list is empty. ```none min(List[Int]): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | list: [List](https://decentralchain.io/docs/ride/data-types#list) [[Int](https://decentralchain.io/docs/ride/data-types#int)] | List | #### min(List[BigInt]): BigInt Returns the smallest element in the list of [big integers](https://decentralchain.io/docs/ride/data-types#bigint). Fails if the list is empty. ```none min(List[BigInt]): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | list: [List](https://decentralchain.io/docs/ride/data-types#list) [[BigInt](https://decentralchain.io/docs/ride/data-types#bigint)] | List | #### removeByIndex(List[T], Int): List[T] Removes an element from the [list](https://decentralchain.io/docs/ride/data-types#list) by index. ```none removeByIndex(list: List[T], index: Int): List[T] ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | list: [List](https://decentralchain.io/docs/ride/data-types#list) [T] | List | | index: T | Index of the element | **Example** ```none removeByIndex(["Ride", 42, true], 1) # Returns ["Ride", true] ``` #### size(List[T]): Int Returns the size of the [list](https://decentralchain.io/docs/ride/data-types#list). ```none size(arr: List[T]): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | arr: [List](https://decentralchain.io/docs/ride/data-types#list) [T] | List | **Example** ```none size(["Hello", "World", "."]) # Returns 3 ``` ### Math Functions **Math Functions** | Name | Description | Complexity | | --- | --- | --- | | [fraction(Int, Int, Int): Int](https://decentralchain.io/docs/ride/functions#fraction-int-int-int) | Multiplies and divides integers to avoid overflow | 14 | | [fraction(Int, Int, Int, Union): Int](https://decentralchain.io/docs/ride/functions#fraction-int-int-int-union) | Multiplies and divides integers to avoid overflow, applying the specified rounding method | 17 | | [fraction(BigInt, BigInt, BigInt): BigInt](https://decentralchain.io/docs/ride/functions#fraction-bigint-bigint-bigint) | Multiplies and divides bid integers to avoid overflow | 128 | | [fraction(BigInt, BigInt, BigInt, Union): BigInt](https://decentralchain.io/docs/ride/functions#fraction-bigint-bigint-bigint-union) | Multiplies and divides big integers to avoid overflow, applying the specified rounding method | 128 | | [log(Int, Int, Int, Int, Int, Union): Int](https://decentralchain.io/docs/ride/functions#log-int-int-int-int-int-union) | Calculates logarithm of a number with a base | 100 | | [log(BigInt, Int, BigInt, Int, Int, Union): BigInt](https://decentralchain.io/docs/ride/functions#log-bigint-int-bigint-int-int-union) | Calculates logarithm of a number to a given base with high accuracy | 200 | | [median(List[Int]): Int](https://decentralchain.io/docs/ride/functions#median-list-int) | Returns the median of a list of integers | 20 | | [median(List[BigInt]): BigInt](https://decentralchain.io/docs/ride/functions#median-list-bigint) | Returns the median of a list of big integers | 160 | | [pow(Int, Int, Int, Int, Int, Union): Int](https://decentralchain.io/docs/ride/functions#pow-int-int-int-int-int-union) | Raises a number to a given power | 100 | | [pow(BigInt, Int, BigInt, Int, Int, Union): BigInt](https://decentralchain.io/docs/ride/functions#pow-bigint-int-bigint-int-int-union) | Raises a number to a given power with high accuracy | 200 | #### fraction(Int, Int, Int): Int Multiplies [integers](https://decentralchain.io/docs/ride/data-types#int) a, b and divides the result by the integer c to avoid overflow. Fraction a × b / c should not exceed the maximum value of the integer type 9,223,372,036,854,755,807. The rounding method is DOWN, see rounding variables below. ```none fraction(a: Int, b: Int, c: Int): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | a: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer a | | b: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer b | | c: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer c | **Example** Lets assume that: a = 100,000,000,000, b = 50,000,000,000,000, c = 2,500,000. The following formula, with [operators](https://decentralchain.io/docs/ride/syntax-basics#operators) \* and /, fails due to overflow: ```none a * b / c # overflow, because a × b exceeds max integer value ``` The fraction function with no overflow: ```none fraction(a, b, c) # Result: 2,000,000,000,000,000,000 ``` #### fraction(Int, Int, Int, Union): Int Multiplies [integers](https://decentralchain.io/docs/ride/data-types#int) a, b and divides the result by the integer c to avoid overflow, applying the specified rounding method. Fraction a × b / c should not exceed the maximum value of the integer type 9,223,372,036,854,755,807. ```none fraction(a: Int, b: Int, c: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | a: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer a | | b: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer b | | c: [Int](https://decentralchain.io/docs/ride/data-types#int) | Integer c | | round: DOWN\|CEILING\|FLOOR\|HALFUP\|HALFEVEN | One of the rounding variables | #### fraction(BigInt, BigInt, BigInt): BigInt Multiplies [integers](https://decentralchain.io/docs/ride/data-types#int) a, b and divides the result by the integer c to avoid overflow, applying the specified rounding method. Fraction a × b / c should not exceed the maximum value of the integer type 9,223,372,036,854,755,807. ```none fraction(a: BigInt, b: BigInt, c: BigInt): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | a: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer a | | b: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer b | | c: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer c | #### fraction(BigInt, BigInt, BigInt, Union): BigInt Multiplies [integers](https://decentralchain.io/docs/ride/data-types#int) a, b and divides the result by the integer c to avoid overflow, applying the specified rounding method. Fraction a × b / c should not exceed the maximum value of the integer type 9,223,372,036,854,755,807. ```none fraction(a: BigInt, b: BigInt, c: BigInt, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | a: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer a | | b: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer b | | c: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Big integer c | | round: DOWN\|CEILING\|FLOOR\|HALFUP\|HALFEVEN | One of the rounding variables | #### log(Int, Int, Int, Int, Int, Union): Int Calculates log_b a. ```none log(value: Int, vp: Int, base: Int, bp: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int ``` In Ride, there is no [data type](https://decentralchain.io/docs/ride/data-types#data-types) with the floating point. That is why, for example, when you need to calculate log_{2.7} 16.25 then the number value = 1625, vp = 2 and the base = 27, bp = 1. If the log function returns, for example, 2807035420964590265, and the parameter rp = 18, then the result is 2.807035420964590265; in the number 2807035420964590265 the last 18 digits is a fractional part. **Parameters** **Parameters** | Parameter | Description | | --- | --- | | value: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number a without decimal point. | | vp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals of a. | | base: [Int](https://decentralchain.io/docs/ride/data-types#int) | Logarithm base b without decimal point. | | bp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals of b. | | rp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals in the resulting value, from 0 to 8 inclusive. Specifies the accuracy of the calculated result. | | round: DOWN\|CEILING\|FLOOR\|HALFUP\|HALFEVEN | One of the rounding variables. | **Example** log_{2.7} 16.25 = 2.807035421... ```none log(1625, 2, 27, 1, 2, HALFUP) # Function returns 281, so the result is: 2.81 log(1625, 2, 27, 1, 5, HALFUP) # Function returns 280703542, so the result is: 2.80704 log(0, 0, 2, 0, 0, HALFUP) # Result: -Infinity ``` #### log(BigInt, Int, BigInt, Int, Int, Union): BigInt Calculates log_b a with high accuracy. ```none log(value: BigInt, ep: Int, base: BigInt, bp: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | value: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Number a without decimal point. | | vp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals of a. | | base: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Logarithm base b without decimal point. | | bp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals of b. | | rp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals in the resulting value, from 0 to 18 inclusive. Specifies the accuracy of the calculated result. | | round: DOWN\|CEILING\|FLOOR\|HALFUP\|HALFEVEN | One of the rounding variables. | #### median(List[Int]): Int Returns the median of the [list](https://decentralchain.io/docs/ride/data-types#list) of integers. Fails if the list is empty. ```none median(arr: List[Int]): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | arr: [List](https://decentralchain.io/docs/ride/data-types#list) [[Int](https://decentralchain.io/docs/ride/data-types#int)] | List of integers | **Example** ```none median([1, 2, 3]) # Returns 2 median([2, 4, 9, 20]) # Returns 6 median([-2, -4, -9, -20]) # Returns -7 ``` #### median(List[BigInt]): BigInt Returns the median of a [list](https://decentralchain.io/docs/ride/data-types#list) of [big integers](https://decentralchain.io/docs/ride/data-types#bigint). Fails if the list is empty or contains more than 100 elements. ```none median(arr: List[BigInt]): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | arr: [List](https://decentralchain.io/docs/ride/data-types#list) [[BigInt](https://decentralchain.io/docs/ride/data-types#bigint)] | List of big integers | #### pow(Int, Int, Int, Int, Int, Union): Int Calculates a^{b}. ```none pow(base: Int, bp: Int, exponent: Int, ep: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | base: [Int](https://decentralchain.io/docs/ride/data-types#int) | Logarithm base b without decimal point. | | bp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals of a. | | exponent: [Int](https://decentralchain.io/docs/ride/data-types#int) | Exponent b without decimal point. | | ep: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals of b. | | rp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals in the resulting value, from 0 to 8 inclusive. Specifies the accuracy of the calculated result. | | round: DOWN\|CEILING\|FLOOR\|HALFUP\|HALFEVEN | One of the rounding variables. | **Example** 16.25^{2.7} = 1859,1057168... ```none pow(1625, 2, 27, 1, 2, HALFUP) # function returns 185911, so the result is: 1859.11 pow(1625, 2, 27, 1, 5, HALFUP) # function returns 185910572, so, the result is: 1859.10572 ``` #### pow(BigInt, Int, BigInt, Int, Int, Union): BigInt Calculates a^{b} with high accuracy. ```none pow(base: BigInt, bp: Int, exponent: BigInt, ep: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | base: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Logarithm base b without decimal point. | | bp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals of a. | | exponent: [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | Exponent b without decimal point. | | ep: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals of b. | | rp: [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimals in the resulting value, from 0 to 18 inclusive. Specifies the accuracy of the calculated result. | | round: DOWN\|CEILING\|FLOOR\|HALFUP\|HALFEVEN | One of the rounding variables. | #### Rounding Variables Below is the list of built-in rounding variables. The rounding variables are only used as the parameters of functions fraction, log, pow. **Parameters** **Rounding Variables** | Name | Description | | --- | --- | | DOWN | Rounds towards zero. | | CEILING | Rounds towards positive infinity. | | FLOOR | Rounds towards negative infinity. | | HALFUP | Rounds towards the nearest integer; if the integers are equidistant, then rounds away from zero. | | HALFEVEN | Rounds towards the nearest integer; if the integers are equidistant, then rounds towards the nearest even integer. | **Example** **Parameters** | Input number/Rounding method | DOWN | CEILING | FLOOR | HALFUP | HALFEVEN | | --- | --- | --- | --- | --- | --- | | 5.5 | 5 | 6 | 5 | 6 | 6 | | 2.5 | 2 | 3 | 2 | 3 | 2 | | 1.6 | 1 | 2 | 1 | 2 | 2 | | 1.1 | 1 | 2 | 1 | 1 | 1 | | 1.0 | 1 | 1 | 1 | 1 | 1 | | -1.0 | -1 | -1 | -1 | -1 | -1 | | -1.1 | -1 | -1 | -2 | -1 | -1 | | -1.6 | -1 | -1 | -2 | -2 | -2 | | -2.5 | -2 | -2 | -3 | -3 | -2 | | -5.5 | -5 | -5 | -6 | -6 | -6 | ### String Functions **String Functions** | Name | Description | Complexity | | --- | --- | --- | | [contains(String, String): Boolean](https://decentralchain.io/docs/ride/functions#contains-string-string) | Checks whether the string contains substring | 3 | | [drop(String, Int): String](https://decentralchain.io/docs/ride/functions#drop-string-int) | Drops the first n characters of a string | 20 | | [dropRight(String, Int): String](https://decentralchain.io/docs/ride/functions#dropright-string-int) | Drops the last n characters of a string | 20 | | [indexOf(String, String): Int\|Unit](https://decentralchain.io/docs/ride/functions#indexof-string-string) | Returns the index of the first occurrence of a substring | 3 | | [indexOf(String, String, Int): Int\|Unit](https://decentralchain.io/docs/ride/functions#indexof-string-string-int) | Returns the index of the first occurrence of a substring after a certain index | 3 | | [lastIndexOf(String, String): Int\|Unit](https://decentralchain.io/docs/ride/functions#lastindexof-string-string) | Returns the index of the last occurrence of a substring | 3 | | [lastindexOf(String, String, Int): Int\|Unit](https://decentralchain.io/docs/ride/functions#lastindexof-string-string-int) | Returns the index of the last occurrence of a substring before a certain index | 3 | | [makeString(List[String], String): String](https://decentralchain.io/docs/ride/functions#makestring-list-string-string) | Concatenates list strings adding a separator | 30 | | [size(String): Int](https://decentralchain.io/docs/ride/functions#size-string) | Returns the size of a string | 1 | | [split(String, String): List[String]](https://decentralchain.io/docs/ride/functions#split-string-string) | Splits a string delimited by a separator into a list of substrings. | 75 | | [take(String, Int): String](https://decentralchain.io/docs/ride/functions#take-string-int) | Takes the first n characters from a string | 20 | | [takeRight(String, Int): String](https://decentralchain.io/docs/ride/functions#takeright-string-int) | Takes the last n characters from a string | 20 | #### contains(String, String): Boolean Checks whether the string contains substring. ```none contains(haystack: String, needle: String): Boolean ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | haystack: [String](https://decentralchain.io/docs/ride/data-types#string) | String to search in. | | needle: [String](https://decentralchain.io/docs/ride/data-types#string) | String to search for. | **Example** ```none "hello".contains("hell") # Returns true "hello".contains("world") # Returns false ``` #### drop(String, Int): String Drops the first n characters of a string. ```none drop(xs: String, number: Int): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | number: [Int](https://decentralchain.io/docs/ride/data-types#int) | The number n. | **Example** ```none drop("Apple", 0) # Returns "Apple" drop("Apple", 1) # Returns "pple" drop("Apple", 3) # Returns "le" drop("Apple", 5) # Returns an empty string drop("Apple", 15) # Returns an empty string ``` #### dropRight(String, Int): String Drops the last n characters of a string. ```none dropRight(xs: String, number: Int): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | number: [Int](https://decentralchain.io/docs/ride/data-types#int) | The number n. | **Example** ```none dropRight("Apple", 0) # Returns "Apple" dropRight("Apple", 1) # Returns "Appl" dropRight("Apple", 3) # Returns "Ap" dropRight("Apple", 5) # Returns an empty string dropRight("Apple", 15) # Returns an empty string ``` #### indexOf(String, String): Int|Unit Returns the index of the first occurrence of a substring. ```none indexOf(str: String, substr: String): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | substr: [String](https://decentralchain.io/docs/ride/data-types#string) | The substring. | **Example** ```none indexOf("Apple","ple") # Returns 3 indexOf("Apple","le") # Returns 4 indexOf("Apple","e") # Returns 5 ``` #### indexOf(String, String, Int): Int|Unit Returns the index of the first occurrence of a substring after a certain index. ```none indexOf(str: String, substr: String, offset: Int): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | substr: [String](https://decentralchain.io/docs/ride/data-types#string) | The substring. | | offset: [Int](https://decentralchain.io/docs/ride/data-types#int) | The index. | **Example** ```none indexOf("Apple","ple", 1) # Returns 2 indexOf("Apple","le", 2) # Returns 3 indexOf("Apple","e", 3) # Returns 4 ``` #### lastIndexOf(String, String): Int|Unit Returns the index of the last occurrence of a substring. ```none lastIndexOf(str: String, substr: String): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | substr: [String](https://decentralchain.io/docs/ride/data-types#string) | The substring. | **Example** ```none lastIndexOf("Apple","pp") # Returns 1 lastIndexOf("Apple","p") # Returns 2 lastIndexOf("Apple","s") # Returns unit ``` #### lastIndexOf(String, String, Int): Int|Unit Returns the index of the last occurrence of a substring before a certain index. ```none lastIndexOf(str: String, substr: String, offset: Int): Int|Unit ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | substr: [String](https://decentralchain.io/docs/ride/data-types#string) | The substring. | | offset: [Int](https://decentralchain.io/docs/ride/data-types#int) | The index. | **Example** ```none lastIndexOf("mamamama","ma",4) # Returns 4 lastIndexOf("mamamama","ma",3) # Returns 2 ``` #### makeString(List[String], String): String Concatenates list strings adding a separator. ```none makeString(arr: List[String], separator: String): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | arr: [List](https://decentralchain.io/docs/ride/data-types#list) [[String](https://decentralchain.io/docs/ride/data-types#string)] | List of strings to concatenate. | | separator: [String](https://decentralchain.io/docs/ride/data-types#string) | Separator. | **Example** ```none makeString(["Apple","Orange","Mango"], " & ") # Returns "Apple & Orange & Mango" ``` #### size(String): Int Returns the size of a string. ```none size(xs: String): Int ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | **Example** ```none size("Ap") # Returns 2 size("Appl") # Returns 4 size("Apple") # Returns 5 ``` #### split(String, String): List[String] Splits a string delimited by a separator into a list of substrings. ```none split(str: String, separator: String): List[String] ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | str: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | separator: [String](https://decentralchain.io/docs/ride/data-types#string) | The separator. | **Example** ```none split("A.p.p.l.e", ".") # Returns ["A", "p", "p", "l", "e"] split("Apple", ".") # Returns ["Apple"] split("Apple", "") # Returns ["A", "p", "p", "l", "e"] split("Ap.ple", ".") # Returns ["Ap","ple"] ``` #### take(String, Int): String Takes the first n characters from a string. ```none take(xs: String, number: Int): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | number: [Int](https://decentralchain.io/docs/ride/data-types#int) | The number n. | **Example** ```none take("Apple", 0) # Returns an empty string take("Apple", 1) # Returns "A" take("Apple", 3) # Returns "App" take("Apple", 5) # Returns "Apple" take("Apple", 15) # Returns "Apple" take("Apple", -10) # Returns an empty string ``` #### takeRight(String, Int): String Takes the last n characters from a string. ```none takeRight(xs: String, number: Int): String ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | xs: [String](https://decentralchain.io/docs/ride/data-types#string) | The string. | | number: [Int](https://decentralchain.io/docs/ride/data-types#int) | The number n. | **Example** ```none takeRight("Apple", 0) # Returns an empty string takeRight("Apple", 1) # Returns "A" takeRight("Apple", 3) # Returns "ple" takeRight("Apple", 5) # Returns "Apple" takeRight("Apple", 15) # Returns "Apple" ``` ### Union Functions **Union Functions** | Name | Description | Complexity | | --- | --- | --- | | [isDefined(T\|Unit): Boolean](https://decentralchain.io/docs/ride/functions#isdefined-t-unit) | Checks if an argument is not unit | 1 | | [value(T\|Unit): T](https://decentralchain.io/docs/ride/functions#value-t-unit) | Gets a value from a union type argument. Fails if it is unit | 2 | | [valueOrElse(T\|Unit, T): T](https://decentralchain.io/docs/ride/functions#valueorelse-t-unit-t) | Returns a value from a union type argument if it's not unit. Otherwise, returns the second argument | 2 | | [valueOrErrorMessage(T\|Unit, String): T](https://decentralchain.io/docs/ride/functions#valueorerrormessage-t-unit-string) | Gets a value from a union type argument if it's not unit. Otherwise, fails with the message specified in the second argument | 2 | #### isDefined(T|Unit): Boolean Checks if an argument is not unit. ```none isDefined(a: T|Unit): Boolean ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | a: T\|Unit | Argument to check. | #### value(T|Unit): T Gets a value from a [union](https://decentralchain.io/docs/ride/data-types#union) type argument. Fails if it is [unit](https://decentralchain.io/docs/ride/data-types#unit). ```none value(a: T|Unit): T ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | a: T\|Unit | Argument to return value from. | #### valueOrElse(T|Unit, T): T Returns a value from a [union](https://decentralchain.io/docs/ride/data-types#union) type argument if it's not [unit](https://decentralchain.io/docs/ride/data-types#unit). Otherwise, returns the second argument. ```none valueOrElse(t: T|Unit, t0: T): T ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | a: T\|Unit | Argument to return value from. | | t0: T | Returned if t is unit. | #### valueOrErrorMessage(T|Unit, String): T Returns a value from a [union](https://decentralchain.io/docs/ride/data-types#union) type argument if it's not [unit](https://decentralchain.io/docs/ride/data-types#unit). Otherwise, fails with the message specified in the second argument. ```none valueOrErrorMessage(a: T|Unit, msg: String): T ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | a: T\|Unit | Argument to return value from. | | msg: [String](https://decentralchain.io/docs/ride/data-types#string) | Error message. | ### Verification Functions **Verification Functions** | Name | Description | Complexity | | --- | --- | --- | | [bn256groth16Verify(ByteVector, ByteVector, ByteVector): Boolean](https://decentralchain.io/docs/ride/functions#bn256groth16verify-bytevector-bytevector-bytevector) | Range of functions. Check zk-SNARK by groth16 protocol on the bn254 curve | 800–1650 | | [createMerkleRoot(List[ByteVector], ByteVector, Int) : ByteVector](https://decentralchain.io/docs/ride/functions#createmerkleroot-list-bytevector-bytevector-int) | Calculates the Merkle root hash for transactions of block | 30 | | [ecrecover(messageHash: ByteVector, signature: ByteVector)](https://decentralchain.io/docs/ride/functions#ecrecover-messagehash) | Recovers public key from the message hash and the ECDSA digital signature | 70 | | [groth16Verify(ByteVector, ByteVector, ByteVector): Boolean](https://decentralchain.io/docs/ride/functions#groth16verify-bytevector-bytevector-bytevector) | Range of functions. Check zk-SNARK by groth16 protocol on the bls12-381 curve | 1200–2700 | | [rsaVerify(digestAlgorithmType, ByteVector, ByteVector, ByteVector): Boolean](https://decentralchain.io/docs/ride/functions#rsaverify-digestalgorithmtype-bytevector-bytevector-bytevector) | Range of functions. Check that the RSA digital signature is valid, i.e. it was created by the owner of the public key | 500–1000 | | [sigVerify(ByteVector, ByteVector, ByteVector): Boolean](https://decentralchain.io/docs/ride/functions#sigverify-bytevector-bytevector-bytevector) | Range of functions. Check that the Curve25519 digital signature is valid, i.e. it was created by the owner of the public key | 47–200 | #### bn256groth16Verify(ByteVector, ByteVector, ByteVector): Boolean Range of functions. Check zk-SNARK by groth16 protocol on the bn254 curve. (Although the curve is called bn254 in the scientific literature, it is commonly referred to as bn256 in the code.) **bn256groth16Verify** | Name | Max number of inputs | Complexity | | --- | --- | --- | | bn256groth16Verify(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 16 | 1650 | | bn256groth16Verify_1inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 1 | 800 | | bn256groth16Verify_2inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 2 | 850 | | bn256groth16Verify_3inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 3 | 950 | | bn256groth16Verify_4inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 4 | 1000 | | bn256groth16Verify_5inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 5 | 1050 | | bn256groth16Verify_6inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 6 | 1100 | | bn256groth16Verify_7inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 7 | 1150 | | bn256groth16Verify_8inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 8 | 1200 | | bn256groth16Verify_9inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 9 | 1250 | | bn256groth16Verify_10inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 10 | 1300 | | bn256groth16Verify_11inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 11 | 1350 | | bn256groth16Verify_12inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 12 | 1400 | | bn256groth16Verify_13inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 13 | 1450 | | bn256groth16Verify_14inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 14 | 1550 | | bn256groth16Verify_15inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 15 | 1600 | **Parameters** **Parameters** | Parameter | Description | | --- | --- | | vk: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Key for the check. Maximum size: 1) For bn256groth16Verify_inputs function — 256 + 32 × N bytes. 2) For bn256groth16Verify function — 256 + 32 × 16 = 768 bytes. | | proof: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Zero-knowledge proof. Fixed size: 128 bytes. | | inputs: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Zero-knowledge proof's public inputs array. For example, array of UTXO hashes in case of shielded transactions. Maximum size: 1) For bn256groth16Verify_inputs function – 32 × N bytes. 2) For bn256groth16Verify function – 512 bytes. | #### createMerkleRoot(List[ByteVector], ByteVector, Int) : ByteVector Calculates the Merkle root hash for transactions of block on the basis of the transaction hash and the sibling hashes of the Merkle tree. BLAKE2b-256 algorithm is used for hashing. To check for the transaction in the block, you need to compare the calculated hash with the transactionsRoot field in the block header. For more informtion see the [transactions root hash](https://decentralchain.io/docs/decentralchain/block#transactions-root-hash). ```none createMerkleRoot(merkleProofs: List[ByteVector], valueBytes: ByteVector, index: Int): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | merkleProofs: [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of sibling hashes of the Merkle tree. Up to 16 items, 32 bytes each. | | valueBytes: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Hash of transaction. Fixed size: 32 bytes. You can use blake2b256 function. The transaction must be hashed together with the signature. | | index: [Int](https://decentralchain.io/docs/ride/data-types#int) | Index of the transaction in the block. | #### ecrecover(messageHash: ByteVector, signature: ByteVector) Recovers public key from the message hash and the ECDSA digital signature based on the secp256k1 elliptic curve. Fails if the recovery failed. The public key is returned in uncompressed format (64 bytes). The function can be used to verify the digital signature of a message by comparing the recovered public key with the sender’s key. ```none ecrecover(messageHash: ByteVector, signature: ByteVector): ByteVector ``` **Parameters** **Parameters** | Parameter | Description | | --- | --- | | messageHash: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Keccak-256 hash of the message. Fixed size: 32. | | signature: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | ECDSA digital signature. Fixed size: 65 bytes. | **Example** Verify the transaction of the Ethereum blockchain using the following data: - The transaction. - The signature that is generated by the ecsign functions (r, s, and v bytes concatenation). - Sender public key. ```none func check(t: ByteVector, signature: ByteVector, publicKey: ByteVector) = { ecrecover(keccak256(t), signature) == publicKey } ``` #### groth16Verify(ByteVector, ByteVector, ByteVector): Boolean Range of functions. Check zk-SNARK by groth16 protocol. **groth16Verify** | Name | Max number of inputs | Complexity | | --- | --- | --- | | groth16Verify(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 16 | 2700 | | groth16Verify_1inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 1 | 1200 | | groth16Verify_2inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 2 | 1300 | | groth16Verify_3inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 3 | 1400 | | groth16Verify_4inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 4 | 1500 | | groth16Verify_5inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 5 | 1600 | | groth16Verify_6inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 6 | 1700 | | groth16Verify_7inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 7 | 1800 | | groth16Verify_8inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 8 | 1900 | | groth16Verify_9inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 9 | 2000 | | groth16Verify_10inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 10 | 2100 | | groth16Verify_11inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 11 | 2200 | | groth16Verify_12inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 12 | 2300 | | groth16Verify_13inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 13 | 2400 | | groth16Verify_14inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 14 | 2500 | | groth16Verify_15inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean | 15 | 2600 | **Parameters** **Parameters** | Parameter | Description | | --- | --- | | vk: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Key for the check. Maximum size: 1) For groth16Verify_inputs function — 384 + 48 × N bytes. 2) For groth16Verify function — 384 + 48 × 16 = 1152 bytes. | | proof: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Zero-knowledge proof. Fixed size: 192 bytes. | | inputs: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Zero-knowledge proof's public inputs array. For example, array of UTXO hashes in case of shielded transactions. Maximum size: 1) For groth16Verify_inputs function – 32 × N bytes. 2) For groth16Verify function – 512 bytes. | **Example** ```none groth16Verify(vk, proof, inputs) ``` #### rsaVerify(digestAlgorithmType, ByteVector, ByteVector, ByteVector): Boolean Range of functions. Check that the RSA digital signature is valid, i.e. it was created by the owner of the public key. **rsaVerify** | Name | Max message size | Complexity | | --- | --- | --- | | rsaVerify(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 150 kB | 1000 | | rsaVerify_16Kb(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 16 kB | 500 | | rsaVerify_32Kb(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 32 kB | 550 | | rsaVerify_64Kb(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 64 kB | 625 | | rsaVerify_128Kb(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 128 kB | 750 | The recommended RSA key module length is at least 2048 bits. Data can be hashed before signing using one of the following algorithms: - MD5 - SHA-1 - SHA-224 - SHA-256 - SHA-384 - SHA-512 - SHA3-224 - SHA3-256 - SHA3-384 - SHA3-512 **Parameters** **Parameters** | Parameter | Description | | --- | --- | | digest: digestAlgorithmType | The hashing algorithm applied to the data before signing. Acceptable values: 1) NOALG — data is not hashed. 2) MD5. 3) SHA1. 4) SHA224. 5) SHA256. 6) SHA384. 7) SHA512. 8) SHA3224. 9) SHA3256. 10) SHA3384. 11) SHA3512. | | message: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Signed data. Maximum size: 1) For rsaVerify_Kb functions — N bytes. 2) For rsaVerify function — 150 bytes. | | sig: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Digital signature. Fixed size: 25 bytes. | | pub: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Binary public key. Fixed size: 294 bytes. | #### sigVerify(ByteVector, ByteVector, ByteVector): Boolean Range of functions. Check that the Curve25519 digital signature is valid, i.e. it was created by the owner of the public key. **sigVerify** | Name | Max message size | Complexity | | --- | --- | --- | | sigVerify(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 150 kB | 200 | | sigVerify_8Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 8 kB | 47 | | sigVerify_16Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 16 kB | 57 | | sigVerify_32Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 32 kB | 70 | | sigVerify_64Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 64 kB | 102 | | sigVerify_128Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean | 128 kB | 172 | **Parameters** **Parameters** | Parameter | Description | | --- | --- | | message: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Signed data. Maximum size: 1) For sigVerify_Kb functions — N bytes. 2) For sigVerify function — 150 bytes. | | sig: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Digital signature. Fixed size: 25 bytes. | | pub: [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Binary public key. Fixed size: 294 bytes. | --- # Script Types Source: https://decentralchain.io/docs/ride/script-types There are three types of scripts: - [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script) enables you to define [сallable functions](https://decentralchain.io/docs/ride/functions#callable-functions) that can be called from other accounts, accept payments to the dApp, and perform various actions on the blockchain. Also dApp script can comprise a verifier function that allows or denies transactions and orders that are sent on behalf of the dApp account. - [Account script](https://decentralchain.io/docs/ride/script-types#account-script) allows or denies transactions and orders that are sent on behalf of the account (like a verifier function of a dApp script). - [Asset script](https://decentralchain.io/docs/ride/script-types#asset-script) allows or denies transactions involving the asset. Features of each script type are described in the table. **Script Types** | # | dApp script | Account script | Asset script | | --- | --- | --- | --- | | Directives | {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} | {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ACCOUNT #-} | {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ASSET #-} | | Content | Set of definitions | Boolean expression | Boolean expression | | this variable | [Address](https://decentralchain.io/docs/ride/structures#address) structure containing dApp address | Address structure containing smart account address | [Asset](https://decentralchain.io/docs/ride/functions#math-functions) structure | | Transaction or order that is checked | Check is performed by the verifier function only. Annotation of the function sets the name of the variable that contains the outgoing transaction or the order, for example: @Verifier(tx) | Built-in variable tx: Transaction\|Order contains the outgoing transaction or the order | Build-in variable tx: Transaction contains the transaction involving the asset. Order check is not supported. | | Proofs accessibility | \1) Proofs of the outgoing transaction or the order are accessible to the verifier function. 2) Proofs of the invoke script transaction are inaccessible to the callable function | Accessible | Inaccessible | | Blockchain data | \1) Accessible to the callable function. 2) Accessible to the verifier function when checking a transaction. 3) Inaccessible to the verifier function when checking an order | \1) Accessible when checking a transaction. 2) Inaccessible when checking an order | Accessible | ## dApp Script dApp script enables you to define callable functions that can be called from other accounts by sending an [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) or by a [dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation). Callable functions can accept payments to the dApp and perform various actions on the blockchain. Also dApp script can comprise a verifier function that allows or denies transactions and orders that are sent on behalf of the dApp account. An account with a dApp script assigned to it is called a dApp. ### dApp Script Format The script code is composed of the following parts: - [Directives](https://decentralchain.io/docs/ride/script-types#directives) - [Auxiliary definitions](https://decentralchain.io/docs/ride/script-types#auxiliary-definitions) - [Callable function](https://decentralchain.io/docs/ride/script-types#callable-function) - [Verifier function](https://decentralchain.io/docs/ride/script-types#verifier-function) ![](https://decentralchain.io/docs/01_dApp-Script-Format.png) #### Directives The dApp script should start with directives: ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} ``` The above directives tell the compiler that: - The script uses the standard library version 5. - The script contains a set of definitions. - The script will be assigned to an account (not asset). #### Auxiliary definitions After the directives, you can define auxiliary variables and functions. These variables and functions are accessible within the entire script. Please note that functions without annotations cannot be called from other accounts. Let's see an exaxmple: ```none let someConstant = 42 func doSomething() = { 1+1 } ``` #### Callable Functions (dApp Script) The callable function should be marked with the @Callable(i) annotation, where i is an [Invocation](https://decentralchain.io/docs/ride/structures#invocation) structure that contains fields of the script invocation that are accessible to the callable function. The variable name in the annotation is required even if the function does not use it. Callable function result is a set of [script actions](https://decentralchain.io/docs/ride/structures#script-actions) that are performed on the blockchain: adding/deleting/modifying entries to the account data storages, token transfers, issue/reissue/burning, and others. The result format and the available actions depend on the Standard library version used. For a detailed description, see the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions) article. In the example below the callable function transfers 1 DecentralCoin to an account that called it and records the request information in the account data storage. If the same account tries to call the function again, the callable function throws an exception. ```none @Callable(i) func faucet () = { let isKnownCaller = match getBoolean(this, toBase58String(i.caller.bytes)) { case hist: Boolean => hist case _ => false } if (!isKnownCaller) then ( [ BooleanEntry(toBase58String(i.caller.bytes), true), ScriptTransfer(i.caller, 100000000, unit) ], unit ) else throw("Can be used only once") } ``` #### Verifier Function Verifier function checks transactions and orders that are sent on behalf of the dApp account for compliance with the specified conditions (in other words it works similar to the account script). The verifier function should be marked with the @Verifier(tx) annotation, where tx is the transaction or the order that the function is currently checking. The variable name in the annotation is required even if the function does not use it. The verifier function has no arguments.Possible results of the verifier function are: - True (the transaction or the order is allowed), - False (the transaction or the order is denied), - An error (the transaction or the order is denied). For a detailed description, see verifier function the article. Using the [match ... case](https://decentralchain.io/docs/ride/syntax-basics#match-case) operator, you can set up different conditions depending on the type of the transaction/order. For example, the following function allows [transfer transactions](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction) and denies orders and other types of transactions. ```none @Verifier(tx) func verify() = { match tx { case ttx:TransferTransaction => sigVerify(ttx.bodyBytes, ttx.proofs[0], ttx.senderPublicKey) case _ => false } } ``` dApp script that has no verifier function performs default verification, that is, checking that the transaction or the order is indeed signed by this account. ### Failed Transactions If the callable function failed or threw an [exception](https://decentralchain.io/docs/ride/syntax-basics#exceptions) when a block generator adds the transaction to a block, such a transaction is saved on the blockchain and marked with the attribute "applicationStatus": "script_execution_failed", provided that: There are two annotations: @Callable(i) and @Verifier(tx). The variable name in the annotation is required even if the function does not use it. An annotated function cannot be called inside a dApp script. - The [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) passed the sender signature verification or the account script verification. - The complexity of performed computations exceeded the [threshold for saving failed transactions](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations). The transaction sender is charged a fee. The transaction doesn't entail any other changes on the blockchain. ### Data Accessible to dApp Script Data accessible to the callable function: - Particular fields of the invocation, including payments, fee, sender address and public key. See the [Invocation](https://decentralchain.io/docs/ride/structures#invocation) structure article for the fields description. Proofs are inaccessible. - Blockchain data: current height, account balances, entries in account data storages, parameters of tokens, etc. Data accessible to the verifier function: - Fields of the current verified transaction/order, including proofs. The built-in variable tx contains this transaction or order. The set of fields depends on the type of transaction/order, see the [transaction structures](https://decentralchain.io/docs/ride/structures#transaction-structures) chapter and [Order](https://decentralchain.io/docs/ride/structures#order) structure article. - Blockchain data: current height, account balances, entries in account data storages, parameters of tokens, etc. ### Annotations Annotation is a form of metadata that is added to a [function](https://decentralchain.io/docs/ride/functions#functions) of a [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script). At the present moment, there are two annotations: @Callable(i) and @Verifier(tx). The variable name in the annotation is required even if the function does not use it. An annotated function cannot be called inside a dApp script. #### @Callable(i) Annotation of a [callable function](https://decentralchain.io/docs/ride/functions#callable-functions). Variable i contains an [Invocation](https://decentralchain.io/docs/ride/structures#invocation) structure representing certain fields of the invocation. #### @Verifier(tx) Annotation of a verifier function. Variable tx contains a structure of transaction or order sent from a dApp's account. ### Callable Function Callable function is a [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script) function which can be invoked by a [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction) or an invoke or reentrantInvoke functions (see details in the [dApp-to-dApp invocation functions](https://decentralchain.io/docs/ride/functions#dapp-to-dapp-invocation-functions) article). - Add, modify, delete dApp [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage) entries. - Transfer tokens. - Add, modify, delete dApp. - Issue tokens on behalf of the dApp, reissue and burn tokens. - Setup [sponsorship](https://decentralchain.io/docs/decentralchain/transaction#how-to-enable-sponsorship). - Lease, cancel lease. The callable function can return a value that is passed to the invoking function in case of the [dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation). The invocation can contain payments to dApp. Tokens obtained in these payments can be used in script actions performed by the callable function and in payments attached to nested invocations. #### Annotation The callable function should be marked with the @Callable(i) annotation, where i is an [Invocation](https://decentralchain.io/docs/ride/structures#invocation) structure that contains invocation fields that are available to the callable function. The variable name in the annotation is required even if the callable function does not use it. #### Arguments The callable function can have arguments of the following types: - The script uses the standard library version 5. - [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) - [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) - [Int](https://decentralchain.io/docs/ride/data-types#int) - [String](https://decentralchain.io/docs/ride/data-types#string) - [Union](https://decentralchain.io/docs/ride/data-types#union) with elements having types listed above. - [List](https://decentralchain.io/docs/ride/data-types#list) with elements having types listed above. #### Invocation Result The callable function invocation result is a [tuple](https://decentralchain.io/docs/ride/data-types#tuple) of two elements: List of script actions. Actions are executed in the same order as the elements in the list. Return value that is passed to the invoking function in case of the [dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation). Let's see an example of invocation of an invocation result: ```none ( [ BooleanEntry("key1", true), IntegerEntry("key2", 42), StringEntry("key3", "some string"), BinaryEntry("key4", base58'encoded'), DeleteEntry("key5"), ScriptTransfer(Address(base58'3Ms8fSfAxBLDjKvNVgACRzQoBLCtCWxtawu'), 100, base58'someAssetid'), Issue("RegularToken", "This is an ordinary token", 10000, 2, true), Reissue("4ZzED8WJXsvuo2MEm2BmZ87Azw8Sx7TVC6ufSUA5LyTV", 1000, true), Burn("4ZzED8WJXsvuo2MEm2BmZ87Azw8Sx7TVC6ufSUA5LyTV", 1000)] SponsorFee("4ZzED8WJXsvuo2MEm2BmZ87Azw8Sx7TVC6ufSUA5LyTV", 300), Lease(Address(base58'3Mn5hzck8nYd52Ytd2ZjzoiQLVoMcn1VAs9',1000), LeaseCancel(base58'Pxaf8pGKHS5ufGhqjmwRRcHQtC9T3h4d1XaJMnkhR1Vt') ], 42 ) ``` #### Script Actions (Callable Function) Script actions performed by the callable function are set by Ride structures. **Script Actions (Callable Function)** | Ride structure that sets action | Description | | --- | --- | | [BinaryEntry](https://decentralchain.io/docs/ride/structures#binaryentry), [BooleanEntry](https://decentralchain.io/docs/ride/structures#booleanentry), [IntegerEntry](https://decentralchain.io/docs/ride/structures#integerentry), [StringEntry](https://decentralchain.io/docs/ride/structures#stringentry) | Adding/modifying the entry. The type of structure must match the type of entry to be added/changed. 1) If there is no entry in the account data storage with the key specified in the structure, the entry will be added. 2) If the entry is present in the [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage), it will be modified. | | [DeleteEntry](https://decentralchain.io/docs/ride/structures#deleteentry) | Entry deletion | | [Issue](https://decentralchain.io/docs/ride/structures#issue) | Token issue | | [Reissue](https://decentralchain.io/docs/ride/structures#reissue) | Token reissue | | [Burn](https://decentralchain.io/docs/ride/structures#burn) | Token burn | | [SponsorFee](https://decentralchain.io/docs/ride/structures#sponsorfee) | Sponsorship setup | | [ScriptTransfer](https://decentralchain.io/docs/ride/structures#scripttransfer) | Token transfer | | [Lease](https://decentralchain.io/docs/ride/structures#lease) | Lease | | [LeaseCancel](https://decentralchain.io/docs/ride/structures#leasecancel) | Lease cancellation | #### Limitations (Callable Function) - The maximum total number of Issue, Reissue, Burn, SponsorFee, ScriptTransfer, Lease, LeaseCancelscript actions executed by all callable functions in a single transaction is 30. - The maximum total number of BinaryEntry, BooleanEntry, IntegerEntry, StringEntry, DeleteEntryscript actions executed by all callable functions in a single transaction is 100. - The maximum number of the payments to dApp in invocation is 10. See also the [limitations](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations) article. #### Threshold for Saving Failed Transactions The Invoke Script transaction is saved on the blockchain and a fee is charged for it even if the dApp script or the asset script fails when a block generator adds the transaction to a block, provided that the sender's signature or account script verification passed. However, if the callable function failed or [threw an exception](https://decentralchain.io/docs/ride/syntax-basics#exceptions) before the [complexity](https://decentralchain.io/docs/ride/dapp-to-app-invocation#script-complexity) of performed calculations exceeded the [threshold for saving failed transactions](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations), the transaction is discarded and the fee is not charged. #### Example The example listed below is a wallet application which allows sending DecentralCoins to a certain address and withdrawing them (withdrawing others' DecentralCoins is prevented). There are two callable functions in the example(deposit and withdraw): ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(i) func deposit() = { let pmt = if i.payments.size() == 1 then i.payments[0] else throw("Attached payment is required") if (isDefined(pmt.assetId)) then throw("Works with DecentralCoins only") else { let currentKey = toBase58String(i.caller.bytes) let currentAmount = match getInteger(this, currentKey) { case a:Int => a case _ => 0 } let newAmount = currentAmount + pmt.amount ( [ IntegerEntry(currentKey, newAmount) ], unit ) } } @Callable(i) func withdraw(amount: Int) = { let currentKey = toBase58String(i.caller.bytes) let currentAmount = match getInteger(this, currentKey) { case a:Int => a case _ => 0 } let newAmount = currentAmount - amount if (amount < 0) then throw("Can't withdraw negative amount") else if (newAmount < 0) then throw("Not enough balance") else ( [ IntegerEntry(currentKey, newAmount), ScriptTransfer(i.caller, amount, unit) ], unit ) } @Verifier(tx) func verify() = false ``` ### Verifier Function Verifier function is a function of [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script) that is responsible for [verification of transactions](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation) and orders sent from a [dApp](https://decentralchain.io/docs/decentralchain/account#dapp-and-smart-account) account. The verifier function does the same as an [account script](https://decentralchain.io/docs/ride/script-types#account-script). dApp script can have only one verifier function. The verifier function should be adorned with the @Verifier(tx) annotation, where tx: Transaction|Order is the transaction or the order that the function is currently checking. Verifier function has no arguments. Verifier function can have one of the following execution results: - True (the transaction or the order is allowed). - False (the transaction or the order is denied). - an error (the transaction or the order is denied). dApp that has no verifier function performs default verification, that is, checking that the first proof of the transaction/order has the correct sender's signature. The following function does the same as the default implementation: ```none @Verifier(tx) func verify() = { sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) } ``` If the verifier function is defined, only verification by this function is performed, proofs are not checked additionally. #### Example dApp with the verifier function listed below only allows [transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction) with an amount of token lower than 100. Orders and other transactions are denied. The match operator is used to specify verification rules depending on the type of the transaction/order. ```none @Verifier(tx) func verify() = { match tx { case ttx:TransferTransaction => ttx.amount < 100 && sigVerify(ttx.bodyBytes, ttx.proofs[0], ttx.senderPublicKey) case _ => false } } ``` See available fields for each transaction type in the [transaction structures](https://decentralchain.io/docs/ride/structures#transaction-structures) article. ## Account Script Account script verifies transactions and orders that are sent on behalf of the account. That is, the account script allows or denies the transaction or the order depending on whether it meets the specified conditions. ### Account Script Format The script code is composed of the following parts: - Directives - Auxiliary definitions - Boolean expression ![](https://decentralchain.io/docs/02_Account-Script-Format.png) #### Directives The account script should start with directives: ```none {- # STDLIB_VERSION 5 # -} {- # CONTENT_TYPE EXPRESSION # -} {- # SCRIPT_TYPE ACCOUNT # -} ``` The above directives tell the compiler that: - The script uses the standard library version 5. - The script contains a boolean expression. - The script will be assigned to an account (not asset). #### Auxiliary Definitions After the directives, you can define auxiliary variables and functions. Let's see an example: ```none let someConstant = 42 func doSomething () = { height + someConstant } ``` #### Boolean Expression The expression checks transactions and orders that are sent on behalf of the account for compliance with the specified conditions. If the conditions are not met, the transaction/order is denied. Possible results of evaluating the expression are: - True (the transaction or the order is allowed), - False (the transaction or the order is denied), - An error (the transaction or the order is denied). Using the [match ... case](https://decentralchain.io/docs/ride/syntax-basics#match-case), you can set up different conditions depending on the type of the transaction/order. For example, the following expression prohibits sending orders and changing the account script, and allows other transactions, provided that the array of confirmations (proofs) contains the correct signature of the account at position 0: ```none match tx { case t: Order | SetScriptTransaction => false case _ => sigVerify (tx.bodyBytes, tx.proofs [0], tx.senderPublicKey) } ``` ### Data Accessible to Account Script The following data can be used for checks: - Fields of the current verified transaction/order, including proofs. The built-in variable tx contains this transaction or order. The set of fields depends on the type of transaction/order, see the [transaction structures](https://decentralchain.io/docs/ride/structures#transaction-structures) chapter and [Order](https://decentralchain.io/docs/ride/structures#order) structure article. - Blockchain data: current height, account balances, entries in account data storages, parameters of tokens, etc. ## Asset Script Asset script verifies transactions within the [asset (token)](https://decentralchain.io/docs/decentralchain/token-asset#token-asset), that is, allows or denies the transaction depending on the specified conditions. Asset with a script assigned to it is called a [smart asset](https://decentralchain.io/docs/decentralchain/token-asset#smart-asset). Keep the following in mind: - The asset script can only verify transactions, but not orders. - If a token is issued without a script, then the script cannot be added later. - The script cannot be removed, so it is impossible to turn a smart asset into a regular one. - Smart asset cannot be a sponsored asset. ### Asset Script Format The script code is composed of the following parts: - Directives - Auxiliary definitions - Boolean expression ![](https://decentralchain.io/docs/03_Asset-Script-Format.png) #### Directives The asset script should start with directives: ```none {- # STDLIB_VERSION 5 # -} {- # CONTENT_TYPE EXPRESSION # -} {- # SCRIPT_TYPE ACCOUNT # -} ``` The above directives tell the compiler that: - The script uses the standard library version 5. - The script contains a boolean expression. - The script will be assigned to an asset. #### Auxiliary Definitions After the directives, you can define auxiliary variables and functions. Let's see an example: ```none let someConstant = 42 func doSomething () = { height + someConstant } ``` #### Boolean Expression The expression checks transactions and orders that are sent on behalf of the account for compliance with the specified conditions. If the conditions are not met, the transaction/order is denied. Possible results of evaluating the expression are: - True (the transaction or the order is allowed), - False (the transaction or the order is denied), - An error (the transaction or the order is denied). Using the [match ... case](https://decentralchain.io/docs/ride/syntax-basics#match-case), you can set up different conditions depending on the type of the transaction/order. For example, the following expression prohibits sending orders and changing the account script, and allows other transactions, provided that the array of confirmations (proofs) contains the correct signature of the account at position 0: ```none match tx { case t : SetAssetScriptTransaction => false case _ => true } ``` ### Failed Transactions If the asset script denies the Exchange transaction when a block generator adds the transaction to a block (provided that the sender signature verification or the account script verification passed), the transaction is saved on the blockchain but marked as failed ("applicationStatus": "script_execution_failed"). The sender of the transaction (matcher) is charged a fee. The transaction doesn't entail any other changes in balances, in particular, the order senders don't pay the matcher fee. If the asset script denies the Invoke Script transaction when a block generator adds the transaction to a block (provided that the sender signature verification or the account script verification passed and the complexity of calculations performed by dApp script exceeded the [threshold for saving failed transactions](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations)), the transaction is saved on the blockchain but marked as failed ("applicationStatus": script_execution_failed"). The transaction sender is charged a fee. The transaction doesn't entail any other changes on the blockchain. ### Data Accessible to Asset Script The following data can be used for checks: - Fields of the current verified transaction, excluding proofs. The built-in variable tx contains this transaction. The set of fields depends on the type of transaction, see the [transaction structures](https://decentralchain.io/docs/ride/structures#transaction-structures) chapter. - Blockchain data: current height, account balances, entries in account data storages, parameters of tokens, etc. --- # Structures Source: https://decentralchain.io/docs/ride/structures All structures in Ride are built-in — you cannot create your own structures. All structures have constructors. Let's see an example of a code that creates an instance of the IntegerEntry structure and reads its key and value: ```none let data = IntegerEntry("Age", 33) let key = data.key let val = data.value ``` ## Script Actions Script actions are executed, that is, they make changes on the blockchain only if they are included in the resulting expression of the callable function. See more details in the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions) article. **Script Actions** | Action | Description | | --- | --- | | [BinaryEntry](https://decentralchain.io/docs/ride/structures#binaryentry) | Add or modify a binary entry of the [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage). | | [BooleanEntry](https://decentralchain.io/docs/ride/structures#booleanentry) | Add or modify a boolean entry. | | [Burn](https://decentralchain.io/docs/ride/structures#burn) | Burn a token. | | [DeleteEntry](https://decentralchain.io/docs/ride/structures#deleteentry) | Delete an entry. | | [IntegerEntry](https://decentralchain.io/docs/ride/structures#integerentry) | Add or modify an integer entry. | | [Issue](https://decentralchain.io/docs/ride/structures#issue) | Issue a token. | | [Lease](https://decentralchain.io/docs/ride/structures#lease) | Lease. | | [LeaseCancel](https://decentralchain.io/docs/ride/structures#leasecancel) | Cancel lease. | | [Reissue](https://decentralchain.io/docs/ride/structures#reissue) | Reissue a token. | | [ScriptTransfer](https://decentralchain.io/docs/ride/structures#scripttransfer) | Transfer a token. | | [SponsorFee](https://decentralchain.io/docs/ride/structures#sponsorfee) | Set up a sponsorship. | | [StringEntry](https://decentralchain.io/docs/ride/structures#stringentry) | Add or modify a string entry. | Available script actions depend on the standard library version used. ### BinaryEntry BinaryEntry is a structure that sets key and value of binary entry [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage). Adding or changing an entry is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. **Constructor** ```none BinaryEntry(key: String, value: ByteVector) ``` **Fields** **BinaryEntry Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | key | [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. The maximum size is 400 bytes. | | 2 | value | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Entry value. The maximum size is 5 Kbytes. | ### BooleanEntry BooleanEntry is a structure that sets the key and value of the [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage) boolean entry. Adding or changing an entry is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. **Constructor** ```none BooleanEntry(key: String, value: Boolean) ``` **Fields** **BooleanEntry Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | key | [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. The maximum size is 400 bytes. | | 2 | value | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | Entry value. | ### Burn Burn is a structure that sets the parameters of the token burning. The token burning is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. If the token is a smart asset, the asset script verifies the Burn action as if it were [BurnTransaction](https://decentralchain.io/docs/ride/structures#burntransaction) with the fee of 0 and the version of 0. If the asset script denies the action, then the transaction that invoked the dApp script is either denied or saved on the blockchain as failed, see the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation). **Constructor** ```none Burn(assetId: ByteVector, quantity: Int) ``` **Fields** **Burn Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [ID of the token](https://decentralchain.io/docs/decentralchain/token-asset#token-id) to burn. | | 2 | quantity | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the token. | ### DeleteEntry DeleteEntry is a structure that sets the parameters of deletion of entry from the [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage). Deleting an entry is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. **Constructor** ```none DeleteEntry(key: String) ``` **Fields** **DeleteEntry Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | key | [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. The maximum size is 400 bytes. | **Example** ```none {-# STDLIB_VERSION 5 #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(inv) func default() = { ( [ DeleteEntry(inv.caller.toString()) ], unit ) } ``` ### IntegerEntry IntegerEntry is a structure that sets the key and value of [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage) integer entry. Adding or changing an entry is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. **Constructor** ```none IntegerEntry(key: String, value: Int) ``` **Fields** **IntegerEntry Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | key | [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. The maximum size is 400 bytes. | | 2 | value | [Int](https://decentralchain.io/docs/ride/data-types#int) | Entry value. | ### Issue Issue is a structure that sets the parameters of the token issue. The token issue is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. The minimum fee for an invoke script transaction is increased by 1 DecentralCoin for each issued asset that is not [NFT](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token). You can get the ID of the issued token using the [calculateAssetId](https://decentralchain.io/docs/ride/functions#blockchain-functions) function. **Constructor** ```none Issue(name: String, description: String, quantity: Int, decimals: Int, isReissuable: Boolean, compiledScript: Script|Unit, nonce: Int) ``` or ```none Issue(name: String, description: String, quantity: Int, decimals: Int, isReissuable: Boolean) ``` In the second case, compiledScript = unit and nonce = 0 values are inserted automatically. **Fields** **Issue Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | name | [String](https://decentralchain.io/docs/ride/data-types#string) | [Token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) name. | | 2 | description | [String](https://decentralchain.io/docs/ride/data-types#string) | Token description. | | 3 | quantity | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the token. Set to 1 for [NFT](https://decentralchain.io/docs/decentralchain/token-asset#non-fungible-token). | | 4 | decimals | [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of digits in decimal part. Set to 0 for NFT. | | 5 | isReissuable | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | Reissue ability flag. Set to 0 for NFT. | | 6 | compiledScript | [Script](https://decentralchain.io/docs/ride/script-types#script-types) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | Set it to unit. Smart asset issue is currently unavailable. | | 7 | nonce | [Int](https://decentralchain.io/docs/ride/data-types#int) | Nonce that is used for token ID generation. If the callable function issues several tokens with the same parameters, you should use different nonce. | **Example** **Regular Token Issue** ```none Issue("RegularToken", "This is an ordinary token", 10000, 2, true) ``` The structure sets the following parameters of token: - Name: RegularToken - Description: This is an ordinary token - Amount of tokens to issue: 100 (value of 10 000 is specified in the minimum fraction — “cents”) - Amount of decimals: 2 - Reissue ability: yes **Multiple Token Issue** ```none ( [ Issue("RegularToken", "This is an ordinary token", 10000, 2, true, unit, 0), Issue("RegularToken", "This is an ordinary token", 10000, 2, true, unit, 1) ], unit ) ``` **NFT Issue** ```none Issue("UberToken", "The ultimate token.", 1, 0, false) ``` The structure sets the following parameters of token: - Name: UberToken - Description: The ultimate token. - Amount of tokens to issue: 1 - Amount of decimals: 0 - Reissue ability: no ### Lease Lease is a structure that sets the lease parameters. The lease is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. More about [lease](https://decentralchain.io/docs/decentralchain/node#leased-proof-of-stake). You can get the lease ID using the [calculateLeaseId](https://decentralchain.io/docs/ride/functions#blockchain-functions) function. **Constructor** ```none Lease(recipient: Address|Alias, amount: Int, nonce: Int) ``` or ```none Lease(recipient: Address|Alias, amount: Int) ``` In the second case, nonce = 0 is inserted automatically. **Fields** **Lease Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | recipient | [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | Lessee [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias). | | 2 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) to lease (that is, amount of Decentralites multiplied by 10^{8}). | | 7 | nonce | [Int](https://decentralchain.io/docs/ride/data-types#int) | Nonce that is used for lease ID generation. If the callable function creates several leases with the same parameters, you should use different nonces. | **Example** ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(i) func foo() = { let lease = Lease(Alias("merry"),100000000) let id = calculateLeaseId(lease) ( [ lease, BinaryEntry("lease", id) ], unit ) } ``` ### LeaseCancel LeaseCancel is a structure that sets the lease cancellation parameters. The lease cancellation is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. **Constructor** ```none LeaseCancel(leaseId: ByteVector) ``` **Fields** **LeaseCancel Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | leaseId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Lease ID | ### Reissue Reissue is a structure that sets the parameters of the token reissue. The token reissue is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. The token reissue is only available for an asset that is issued by a dApp account. If the token is a smart asset, the asset script verifies the Reissue action as if it were [ReissueTransaction](https://decentralchain.io/docs/ride/structures#reissuetransaction) with the fee of 0 and the version of 0. If the asset script denies the action, then the transaction that invoked the dApp script is either denied or saved on the blockchain as failed, see the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation). **Constructor** ```none Reissue(assetId: ByteVector, quantity: Int, isReissuable: Boolean) ``` **Fields** **Reissue Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [ID of the token](https://decentralchain.io/docs/decentralchain/token-asset#token-id) to reissue. | | 2 | quantity | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the token. | | 3 | isReissuable | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | Reissue ability flag. | ### ScriptTransfer ScriptTransfer is a structure that sets the parameters of the token transfer. The token transfer is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. If the token is a smart asset, the asset script verifies the ScriptTransfer action as if it were [TransferTransaction](https://decentralchain.io/docs/ride/structures#transfertransaction) with the fee of 0 and the version of 0. If the asset script denies the action, then the transaction that invoked the dApp script is either denied or saved on the blockchain as failed, see the [transaction validation](https://decentralchain.io/docs/decentralchain/transaction#transaction-validation). **Constructor** ```none ScriptTransfer(recipient: Address|Alias, amount: Int, asset: ByteVector|Unit) ``` **Fields** **ScriptTransfer Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | recipient | [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or the [alias](https://decentralchain.io/docs/decentralchain/account#alias) of a recipient of tokens. | | 2 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of tokens. | | 3 | asset | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | [ID of the token](https://decentralchain.io/docs/decentralchain/token-asset#token-id). | ### SponsorFee SponsorFee is a structure that sets up sponsorship. For information about sponsorship, see the [sponsored fee](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees) article. The sponsorship setup is performed only if the structure is included in the resulting expression of the callable function. See details in the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions) article. The sponsorship setup is only available if the asset is issued by a dApp account (by the same script invocation as well) and is not a smart asset. **Constructor** ```none SponsorFee(assetId: ByteVector, minSponsoredAssetFee: Int|Unit) ``` **Fields** **SponsorFee Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Asset ID | | 2 | minSponsoredAssetFee | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | Amount of sponsored asset that is equivalent to 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin), specified in the minimum fraction (“cent”) of the sponsored asset. unit — disable the sponsorship. | **Example** ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(i) func issueAndSponsor() = { let issue = Issue("Spring", "", 100000, 2, true, unit, 0) let id = calculateAssetId(issue) ( [ issue, SponsorFee(id, 300) ], unit ) } ``` The issueAndSponsor callable function issues an asset and enables sponsorship. The minimum fee in sponsored assets is 3 Spring. ### StringEntry StringEntry is a structure that sets key and value of [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage) string entry. Adding or changing an entry is performed only if the structure is included in the [callable function result](https://decentralchain.io/docs/ride/functions#callable-functions)>`. **Constructor** ```none BinaryEntry(key: String, value: String) ``` **Fields** **StringEntry Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | key | [String](https://decentralchain.io/docs/ride/data-types#string) | Entry key. The maximum size is 400 bytes. | | 2 | value | [String](https://decentralchain.io/docs/ride/data-types#string) | Entry value. The maximum size is 5 Kbytes. | ## Common Structures **Common Structures** | Name | Description | | --- | --- | | [Address](https://decentralchain.io/docs/ride/structures#address) | [Account address](https://decentralchain.io/docs/decentralchain/account#address). | | [Alias](https://decentralchain.io/docs/ride/structures#alias) | [Alias](https://decentralchain.io/docs/decentralchain/account#alias). | | [Asset](https://decentralchain.io/docs/ride/functions#math-functions) | [Token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) info. | | [AssetPair](https://decentralchain.io/docs/ride/structures#assetpair) | Pair of tokens of an order within the order structure. | | [AttachedPayment](https://decentralchain.io/docs/ride/structures#attachedpayment) | Payment attached to the script invocation and available to the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions). | | [BalanceDetails](https://decentralchain.io/docs/ride/structures#balancedetails) | Account balance in [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | | [BlockInfo](https://decentralchain.io/docs/ride/structures#blockinfo) | [Block](https://decentralchain.io/docs/decentralchain/block#block) header. | | [Invocation](https://decentralchain.io/docs/ride/structures#invocation) | Script invocation fields that the callable function can use. | | [Order](https://decentralchain.io/docs/ride/structures#order) | Order | | [Transfer](https://decentralchain.io/docs/ride/structures#transfer) | Transfer within the [MassTransferTransaction](https://decentralchain.io/docs/ride/structures#masstransfertransaction) structure. | ### Address Structure of an [address](https://decentralchain.io/docs/decentralchain/account#address). **Constructor** ```none Address(bytes: ByteVector) ``` **Fields** **Address Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | bytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes of the address. | **Example** Get all types of balance in DecentralCoins for the current account (in a dApp script or an account script): ```none decentralchainBalance(this) ``` For any account: ```none let address=base58'3N4iKL6ikwxiL7yNvWQmw7rg3wGna8uL6LU' decentralchainBalance(Address(address)) ``` Get an entry value by key from the account data storage: ```none let address2=base58'3N6dFJ6XBQsWz1VV1i5aW4CyYpVKc39MUGZ' getBoolean(Address(address2),"allow_orders") ``` Convert the address that invoked the function to a base58 string: ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @Callable(i) func foo(question: String) = { let callerAddress = toBase58String(i.caller.bytes) ... } ``` Check the recipient's address in the transfer transaction: ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ACCOUNT #-} # Bank dApp address let BANK = base58'3MpFRn3X9ZqcLimFoqNeZwPBnwP7Br5Fmgs' match (tx) { case t: TransferTransaction => addressFromRecipient(t.recipient).bytes == BANK case _ => false } ``` ### Alias Structure of an [alias](https://decentralchain.io/docs/decentralchain/account#alias). **Constructor** ```none Alias(alias: String) ``` **Fields** **Alias Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | alias | [String](https://decentralchain.io/docs/ride/data-types#string) | [Alias](https://decentralchain.io/docs/decentralchain/account#alias) | **Example** ```none let alias = Alias("merry") addressFromRecipient(alias) ``` ### Asset Structure of a [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset). The structure is returned by the [assetInfo](https://decentralchain.io/docs/ride/functions#blockchain-functions) built-in function. **Constructor** ```none Asset(id: ByteVector, quantity: Int, decimals: Int, issuer: Address, issuerPublicKey: ByteVector, reissuable: Boolean, scripted: Boolean, minSponsoredFee: Int|Unit, name: String, description: String) ``` **Fields** **Asset Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id). | | 2 | quantity | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of issued token, multiplied by 10^{decimals}. Up to 9 223 372 036 854 775 806. | | 3 | decimals | [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of decimal places, 0 to 8. | | 4 | issuer | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the [account](https://decentralchain.io/docs/decentralchain/account#account) that issued a token. | | 5 | issuerPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the account that issued a token. | | 6 | reissuable | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | true — token can be reissued, false — cannot be reissued. | | 7 | scripted | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | true — smart asset, false — regular token. | | 8 | minSponsoredFee | [Int](https://decentralchain.io/docs/ride/data-types#int) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | Amount of asset that is equivalent to 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) (100,000 Decentralites), specified in the minimum fraction (“cents”) of asset. See the [Sponsored fee](https://decentralchain.io/docs/decentralchain/transaction#sponsored-fees) article. unit: sponsorship is disabled. | | 9 | name | [String](https://decentralchain.io/docs/ride/data-types#string) | Token name, up to 16 characters. | | 10 | description | [String](https://decentralchain.io/docs/ride/data-types#string) | Token description, up to 1000 characters. | **Example** Get the account balance in a given asset: ```none let address=base58'3Mw48B85LvkBUhhDDmUvLhF9koAzfsPekDb' let assetId=base58'GpxmxorKXLz1V7xootrvGyFgqP2tTTBib5HEm8QGZTHX' assetBalance(Address(address), assetId) ``` ### AssetPair Structure of a pair of [tokens](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) of an order within the [Order](https://decentralchain.io/docs/ride/structures#order) structure. **Constructor** ```none AssetPair(amountAsset: ByteVector|Unit, priceAsset: ByteVector|Unit) ``` **Fields** **AssetPair Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | amountAsset | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | The first token of a pair. | | 2 | priceAsset | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | The second token of a pair. | **Example** Get the account balance in a given asset: ```none let address=base58'3Mw48B85LvkBUhhDDmUvLhF9koAzfsPekDb' let assetId=base58'GpxmxorKXLz1V7xootrvGyFgqP2tTTBib5HEm8QGZTHX' assetBalance(Address(address), assetId) ``` ### AttachedPayment Structure of a payment attached to the script invocation and available to the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions). The structure is used in: - [Invocation](https://decentralchain.io/docs/ride/structures#invocation) structure. - [InvokeScriptTransaction](https://decentralchain.io/docs/ride/structures#invokescripttransaction) structure. - [Invoke](https://decentralchain.io/docs/ride/functions#dapp-to-dapp-invocation-functions) and [reentrantInvoke](https://decentralchain.io/docs/ride/functions#dapp-to-dapp-invocation-functions) functions. **Constructor** ```none AttachedPayment(assetId: ByteVector|Unit, amount: Int) ``` **Fields** **AttachedPayment Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | ID of a [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset). | | 2 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Payment amount. | ### BalanceDetails Structure that contains DecentralCoins balances of account. The structure is returned by the decentralchainBalance built-in function. For description of balance types, see the [account balance](https://decentralchain.io/docs/decentralchain/account#account-balance) article. **Constructor** ```none BalanceDetails(available: Int, regular: Int, generating: Int, effective: Int) ``` **Fields** **BalanceDetails Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | available | [Int](https://decentralchain.io/docs/ride/data-types#int) | Available balance. | | 2 | regular | [Int](https://decentralchain.io/docs/ride/data-types#int) | Regular balance. | | 3 | generating | [Int](https://decentralchain.io/docs/ride/data-types#int) | Generating balance. | | 4 | effective | [Int](https://decentralchain.io/docs/ride/data-types#int) | Effective balance. | All balances are given in Decentralites. ### BlockInfo Structure containing block headers. The structure is returned by the blockInfoByHeight built-in function. **Constructor** ```none BlockInfo(timestamp: Int, height: Int, baseTarget: Int, generationSignature: ByteVector, generator: Address, generatorPublicKey: ByteVector, vrf: ByteVector|Unit) ``` **Fields** **BlockInfo Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Block timestamp](https://decentralchain.io/docs/decentralchain/block#block-timestamp). | | 2 | height | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Block height](https://decentralchain.io/docs/decentralchain/block#block-height). | | 3 | baseTarget | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Base target](https://decentralchain.io/docs/decentralchain/block#base-target). | | 4 | generationSignature | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [Generation signature](https://decentralchain.io/docs/decentralchain/block#block-generation). | | 5 | generator | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the [account](https://decentralchain.io/docs/decentralchain/account#account) that created a block. | | 6 | generatorPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the account that created a block. | | 7 | vrf | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | VRF for block version 5, unit otherwise. | ### Invocation Structure that contains the fields of the script invocation that the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions) can use. **Constructor** ```none Invocation(caller: Address, callerPublicKey: ByteVector, originCaller: Address, originCallerPublicKey: ByteVector, payments: List[AttachedPayment], transactionId: ByteVector, fee: Int, feeAssetId: ByteVector|Unit) ``` **Fields** The field values depend on how the callable function is invoked. If the callable function is invoked by an [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction): **Invocation Fields 1** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | caller | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the account that sent the invoke script transaction. | | 2 | callerPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the account that sent the invoke script transaction. | | 3 | originCaller | Address | Duplicates the caller field. | | 4 | originCallerPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Duplicates the callerPublicKey field. | | 5 | payments | [List](https://decentralchain.io/docs/ride/data-types#list) [[AttachedPayment](https://decentralchain.io/docs/ride/structures#attachedpayment)] | Payments indicated in the invoke script transaction. | | 6 | transactionId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | ID of the invoke script transaction. | | 7 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 8 | feeAssetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | ID of the fee token. | If the callable function is invoked by the invoke or reentrantInvoke function (see the [dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation) article): **Invocation Fields 2** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | caller | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the dApp that invokes the callable function. | | 2 | callerPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the dApp that invokes the callable function. | | 3 | originCaller | Address | Address of the account that sent the Invoke Script transaction. | | 4 | originCallerPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the account that sent the Invoke Script transaction. | | 5 | payments | [List](https://decentralchain.io/docs/ride/data-types#list) [[AttachedPayment](https://decentralchain.io/docs/ride/structures#attachedpayment)] | Payments indicated in the invoke or reentrantInvoke function. | | 6 | transactionId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | ID of the Invoke Script transaction. | | 7 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 8 | feeAssetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | ID of the fee token. | The originCaller, originCallerPublicKey, transactionId, fee, and feeAssetId values are the same for all dApp-to-dApp invocations within a single Invoke Script transaction. **Example** The following function checks that the first payment in the Invoke Script transaction is at least 1 DecentralCoin or 5 in the specified asset. ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} func isPaymentOk(i: Invocation) = { let acceptableAssetId = base58'3JmaWyFqWo8YSA8x3DXCBUW7veesxacvKx19dMv7wTMg' if (size(i.payments) == 0) then { throw("Payment not attached") } else { let p = i.payments[0] match p.assetId { case assetId: ByteVector => assetId == acceptableAssetId && p.amount >= 500000000 case _ => p.amount >= 100000000 } } } @Callable(i) func foo() = { if isPaymentOk(i) then ([],unit) else throw("Wrong payment amount or asset") } ``` ### Order Structure of an order [dApp-to-dApp invocation](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation). The structure is used: - When checking an outgoing order by the [account script](https://decentralchain.io/docs/ride/script-types#account-script) or the verifier function of the [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script). - In the [InvokeScriptTransaction](https://decentralchain.io/docs/ride/structures#invokescripttransaction) structure. **Constructor** ```none Order(id: ByteVector, matcherPublicKey: ByteVector, assetPair: AssetPair, orderType: Buy|Sell, price: Int, amount: Int, timestamp: Int, expiration: Int, matcherFee: Int, matcherFeeAssetId: ByteVector|Unit, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **Order Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | ID of an order. | | 2 | matcherPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of a matcher. | | 3 | assetPair | [AssetPair](https://decentralchain.io/docs/ride/structures#assetpair) | Pair of [tokens](https://decentralchain.io/docs/decentralchain/token-asset#token-asset). | | 4 | orderType | Buy\|Sell | Type of an order — selling or buying. | | 5 | price | [Int](https://decentralchain.io/docs/ride/data-types#int) | Price of a token to exchange. | | 6 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of tokens to exchange. | | 7 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Unix time of the validation of an order by a matcher. | | 8 | expiration | [Int](https://decentralchain.io/docs/ride/data-types#int) | Unix time when an uncompleted order will be cancelled. | | 9 | matcherFee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 10 | matcherFeeAssetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | Token of a transaction fee. It can only be [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin). | | 11 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the sender of an order. | | 12 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the sender of an order. | | 13 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Array of bytes of an order. | | 14 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | **Example** The script below enables buying from a sender's account: - Only the specified asset. - Only at a given price. - Only for DecentralCoins. ```none {-# STDLIB_VERSION 5 #-} {-# CONTENT_TYPE EXPRESSION #-} {-# SCRIPT_TYPE ACCOUNT #-} let myAssetId = base58'8LLpj6yQLUu37KUt3rVo1S69j2gWMbgbM6qqgt2ac1Vb' match tx { case o: Order => let isDecentralChainPriceAsset = !isDefined(o.assetPair.priceAsset) let rightPair = (o.assetPair.amountAsset == myAssetId) && isDecentralChainPriceAsset sigVerify(o.bodyBytes, o.proofs[0], o.senderPublicKey) && rightPair && o.price == 500000 && o.orderType == Buy case _ => false } ``` ### Transfer Structure of a single transfer within the [MassTransferTransaction](https://decentralchain.io/docs/ride/structures#masstransfertransaction) structure. **Constructor** ```none Transfer(recipient: Address|Alias, amount: Int) ``` **Fields** **Transfer Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | recipient | [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) of a recipient of tokens. | | 2 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of tokens. | ## Transaction Structures ### Tokenization **Tokenization** | Transaction type ID | Name | Description | | --- | --- | --- | | 3 | [IssueTransaction](https://decentralchain.io/docs/ride/structures#issuetransaction) | Structure of [issue transaction](https://decentralchain.io/docs/decentralchain/transaction#issue-transaction). | | 5 | [ReissueTransaction](https://decentralchain.io/docs/ride/structures#reissuetransaction) | Structure of [reissue transaction](https://decentralchain.io/docs/decentralchain/transaction#reissue-transaction). | | 6 | [BurnTransaction](https://decentralchain.io/docs/ride/structures#burntransaction) | Structure of [burn transaction](https://decentralchain.io/docs/decentralchain/transaction#burn-transaction). | | 15 | [SetAssetScriptTransaction](https://decentralchain.io/docs/ride/structures#setassetscripttransaction) | Structure of [set asset script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-asset-script-transaction). | | 17 | [UpdateAssetInfoTransaction](https://decentralchain.io/docs/ride/structures#updateassetinfotransaction) | Structure of [update asset info transaction](https://decentralchain.io/docs/decentralchain/transaction#update-asset-info-transaction). | #### IssueTransaction Structure of an [issue transaction](https://decentralchain.io/docs/decentralchain/transaction#issue-transaction). **Constructor** ```none IssueTransaction(quantity: Int, name: String, description: String, reissuable: Boolean, decimals: Int, script: ByteVector|Unit, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **IssueTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | quantity | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset). | | 2 | name | [String](https://decentralchain.io/docs/ride/data-types#string) | Token name. | | 3 | description | [String](https://decentralchain.io/docs/ride/data-types#string) | Token description. | | 4 | reissuable | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | Reissue ability flag. | | 5 | decimals | [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of digits in decimal part. | | 6 | script | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | [Script](https://decentralchain.io/docs/ride/script-types#script-types) that must be set for the generated token. | | 7 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 8 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 9 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 10 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 11 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 12 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Account public key of the transaction sender. | | 13 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 14 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | #### ReissueTransaction Structure of a [reissue transaction](https://decentralchain.io/docs/decentralchain/transaction#reissue-transaction). **Constructor** ```none ReissueTransaction(quantity: Int, assetId: ByteVector, reissuable: Boolean, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **ReissueTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | quantity | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset). | | 2 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id). | | 3 | reissuable | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | Reissue flag. | | 4 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 5 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 6 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 7 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 8 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 9 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the transaction sender. | | 10 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 11 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Proofs. | #### BurnTransaction Structure of an [burn transaction](https://decentralchain.io/docs/decentralchain/transaction#burn-transaction). **Constructor** ```none BurnTransaction(quantity: Int, assetId: ByteVector, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **BurnTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | quantity | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) to burn. | | 2 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | ID of the token to burn. | | 3 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 4 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 5 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 6 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 7 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 8 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the transaction sender. | | 9 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 10 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | #### SetAssetScriptTransaction Structure of an [set asset script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-asset-script-transaction). **Constructor** ```none SetAssetScriptTransaction(script: ByteVector|Unit, assetId: ByteVector, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **SetAssetScriptTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | script | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | [Asset script](https://decentralchain.io/docs/ride/script-types#asset-script). | | 2 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id). | | 3 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 4 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 5 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 6 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 7 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 8 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the transaction sender. | | 9 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 10 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Proofs. | #### UpdateAssetInfoTransaction Structure of an [update asset info transaction](https://decentralchain.io/docs/decentralchain/transaction#update-asset-info-transaction). **Constructor** ```none UpdateAssetInfoTransaction(name: String, assetId: ByteVector, description: String, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **UpdateAssetInfoTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | name | [String](https://decentralchain.io/docs/ride/data-types#string) | Name of the token. | | 2 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id). | | 3 | description | [String](https://decentralchain.io/docs/ride/data-types#string) | Description of the token. | | 4 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 5 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 6 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 7 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 8 | sender | Address | Address of a transaction sender. | | 9 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Account public key of a sender. | | 10 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 11 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | ### Usage **Usage** | Transaction type ID | Name | Description | | --- | --- | --- | | 4 | [TransferTransaction](https://decentralchain.io/docs/ride/structures#transfertransaction) | Structure of [transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction). | | 7 | [ExchangeTransaction](https://decentralchain.io/docs/ride/structures#exchangetransaction) | Structure of [exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction). | | 10 | [CreateAliasTransaction](https://decentralchain.io/docs/ride/structures#createaliastransaction) | Structure of [create alias transaction](https://decentralchain.io/docs/decentralchain/transaction#create-alias-transaction). | | 11 | [MassTransferTransaction](https://decentralchain.io/docs/ride/structures#masstransfertransaction) | Structure of [mass transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#mass-transfer-transaction). | | 12 | [DataTransaction](https://decentralchain.io/docs/ride/structures#datatransaction) | Structure of [data transaction](https://decentralchain.io/docs/decentralchain/transaction#data-transaction). | | 13 | [SetScriptTransaction](https://decentralchain.io/docs/ride/structures#setscripttransaction) | Structure of [set script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-script-transaction). | | 16 | [InvokeScriptTransaction](https://decentralchain.io/docs/ride/structures#invokescripttransaction) | Structure of [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction). | #### TransferTransaction Structure of an [transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#transfer-transaction). **Constructor** ```none TransferTransaction(feeAssetId: ByteVector|Unit, amount: Int, assetId: ByteVector|Unit, recipient: Address|Alias, attachment: ByteVector, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **TransferTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | feeAssetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | Token to pay the commission. | | 2 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of tokens to transfer. | | 3 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | ID of a token. | | 4 | recipient | [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | Address or alias of the recipient. | | 5 | attachment | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Arbitrary data attached to transfer. The maximum data size is 140 bytes. | | 6 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 7 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 8 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 9 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 10 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of a transaction sender. | | 11 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Account public key of a sender. | | 12 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 13 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | #### ExchangeTransaction Structure of an [exchange transaction](https://decentralchain.io/docs/decentralchain/transaction#exchange-transaction). **Constructor** ```none ExchangeTransaction(buyOrder: Order, sellOrder: Order, price: Int, amount: Int, buyMatcherFee: Int, sellMatcherFee: Int, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **ExchangeTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | buyOrder | Order | Token purchase order. | | 2 | sellOrder | Order | Token sell order. | | 3 | price | [Int](https://decentralchain.io/docs/ride/data-types#int) | Price of exchanging token. | | 4 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of exchanging tokens. | | 5 | buyMatcherFee | [Int](https://decentralchain.io/docs/ride/data-types#int) | Matcher's purchase fee. | | 6 | sellMatcherFee | [Int](https://decentralchain.io/docs/ride/data-types#int) | Matcher's sell fee. | | 7 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 8 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 9 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 10 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 11 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of a transaction sender. | | 12 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Account public key of a sender. | | 13 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 14 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | #### CreateAliasTransaction Structure of a [create alias transaction](https://decentralchain.io/docs/decentralchain/transaction#create-alias-transaction). **Constructor** ```none CreateAliasTransaction(alias: String, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **CreateAliasTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | alias | [String](https://decentralchain.io/docs/ride/data-types#string) | [Alias](https://decentralchain.io/docs/decentralchain/account#alias). | | 3 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 4 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 5 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 6 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 7 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 8 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the transaction sender. | | 9 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 10 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | #### MassTransferTransaction Structure of a [mass transfer transaction](https://decentralchain.io/docs/decentralchain/transaction#mass-transfer-transaction). **Constructor** ```none MassTransferTransaction(assetId: ByteVector|Unit, totalAmount: Int, transfers: List[Transfer], transferCount: Int, attachment: ByteVector, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **MassTransferTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id). | | 2 | totalAmount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the token to be transferred. | | 3 | transfers | [List](https://decentralchain.io/docs/ride/data-types#list) [[Transfer](https://decentralchain.io/docs/ride/structures#transfer)] | Transfers. | | 4 | transferCount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Number of transfers. | | 5 | attachment | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Optional data attached to the transaction. This field is often used to attach a comment to the transaction. The maximum data size is 140 bytes. | | 6 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 7 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 8 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 9 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 10 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 11 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the transaction sender. | | 12 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 13 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Proofs. | #### DataTransaction Structure of a [data transaction](https://decentralchain.io/docs/decentralchain/transaction#data-transaction). **Constructor** ```none DataTransaction(data: List[BinaryEntry|BooleanEntry|DeleteEntry|IntegerEntry|StringEntry], id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **DataTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | data | [List](https://decentralchain.io/docs/ride/data-types#list) [[BinaryEntry](https://decentralchain.io/docs/ride/structures#binaryentry) \| [BooleanEntry](https://decentralchain.io/docs/ride/structures#booleanentry) \| [DeleteEntry](https://decentralchain.io/docs/ride/structures#deleteentry) \| [IntegerEntry](https://decentralchain.io/docs/ride/structures#integerentry) \| [StringEntry](https://decentralchain.io/docs/ride/structures#stringentry)] | Transaction's data array. | | 2 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 3 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 4 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 5 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 6 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of a transaction sender. | | 7 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Account public key of a sender. | | 8 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 9 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | #### SetScriptTransaction Structure of a [set script transaction](https://decentralchain.io/docs/decentralchain/transaction#set-script-transaction). **Constructor** ```none SetScriptTransaction(script: ByteVector|Unit, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **SetScriptTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | script | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | [Account script](https://decentralchain.io/docs/ride/script-types#account-script) or [dApp script](https://decentralchain.io/docs/ride/script-types#dapp-script). | | 2 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 3 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 4 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 5 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 6 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 7 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the transaction sender. | | 8 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 9 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Proofs. | #### InvokeScriptTransaction Structure of an [invoke script transaction](https://decentralchain.io/docs/decentralchain/transaction#invoke-script-transaction). **Constructor** ```none InvokeScriptTransaction(dApp: Address|Alias, payments: List[AttachedPayments], feeAssetId: ByteVector|Unit, function: String, args: List[Boolean|ByteVector|Int|String|List[Boolean|ByteVector|Int|String]], id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **InvokeScriptTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | dApp | [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the account which is calling a function. | | 2 | payments | [List](https://decentralchain.io/docs/ride/data-types#list) [[AttachedPayment](https://decentralchain.io/docs/ride/structures#attachedpayment)] | Payments attached to the transaction. | | 3 | feeAssetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) to pay the commission. | | 4 | function | [String](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | Name of the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions). | | 5 | args | [List](https://decentralchain.io/docs/ride/data-types#list) [[Boolean](https://decentralchain.io/docs/ride/data-types#boolean) \| [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Int](https://decentralchain.io/docs/ride/data-types#int) \| [String](https://decentralchain.io/docs/ride/data-types#string) \| [List](https://decentralchain.io/docs/ride/data-types#list) [[Boolean](https://decentralchain.io/docs/ride/data-types#boolean) \| [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Int](https://decentralchain.io/docs/ride/data-types#int) \| [String](https://decentralchain.io/docs/ride/data-types#string)]] | Parameters of the callable function. | | 6 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 7 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 8 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 9 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 10 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 11 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Account public key of the transaction sender. | | 12 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 13 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | ### Network **Network** | Transaction type ID | Name | Description | | --- | --- | --- | | 8 | [LeaseTransaction](https://decentralchain.io/docs/ride/structures#leasetransaction) | Structure of [lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction). | | 9 | [LeaseCancelTransaction](https://decentralchain.io/docs/ride/structures#leasecanceltransaction) | Structure of [lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction). | | 14 | [SponsorFeeTransaction](https://decentralchain.io/docs/ride/structures#sponsorfeetransaction) | Structure of [sponsor fee transaction](https://decentralchain.io/docs/decentralchain/transaction#sponsor-fee-transaction). | #### LeaseTransaction Structure of a [lease transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-transaction). **Constructor** ```none LeaseTransaction(amount: Int, recipient: Address|Alias, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **LeaseTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset) to lease. | | 2 | recipient | [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the leasing recipient. | | 3 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 4 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 5 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 6 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 7 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of a transaction sender. | | 8 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Account public key of a sender. | | 9 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 10 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Array of proofs. | #### LeaseCancelTransaction Structure of a [lease cancel transaction](https://decentralchain.io/docs/decentralchain/transaction#lease-cancel-transaction). **Constructor** ```none LeaseCancelTransaction(leaseId: ByteVector, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **LeaseCancelTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | leaseId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Leasing ID. | | 2 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 3 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 4 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 5 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 6 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 7 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the transaction sender. | | 8 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 9 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Proofs. | #### SponsorFeeTransaction Structure of a [sponsor fee transaction](https://decentralchain.io/docs/decentralchain/transaction#sponsor-fee-transaction). **Constructor** ```none SponsorFeeTransaction(assetId: ByteVector, minSponsoredAssetFee: Int|Unit, id: ByteVector, fee: Int, timestamp: Int, version: Int, sender: Address, senderPublicKey: ByteVector, bodyBytes: ByteVector, proofs: List[ByteVector]) ``` **Fields** **SponsorFeeTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | assetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | [token ID](https://decentralchain.io/docs/decentralchain/token-asset#token-id). | | 2 | minSponsoredAssetFee | [Int](https://decentralchain.io/docs/ride/data-types#int) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | Amount of asset that is equivalent to 0.001 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) (100,000 Decentralites): an integer value specified in atomic units. unit – disable sponsorship. | | 3 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 4 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 5 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 6 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | | 7 | sender | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the transaction sender. | | 8 | senderPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the transaction sender. | | 9 | bodyBytes | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction body bytes. | | 10 | proofs | [List](https://decentralchain.io/docs/ride/data-types#list) [[ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector)] | Proofs. | ### Genesis **Genesis** | Transaction type ID | Name | Description | | --- | --- | --- | | 1 | [GenesisTransaction](https://decentralchain.io/docs/ride/structures#genesistransaction) | Structure of [genesis transaction](https://decentralchain.io/docs/decentralchain/transaction#genesis-transaction). | #### GenesisTransaction Structure of a [genesis transaction](https://decentralchain.io/docs/decentralchain/transaction#genesis-transaction). **Constructor** ```none GenesisTransaction(amount: Int, recipient: Address|Alias, id: ByteVector, fee: Int, timestamp: Int, version: Int) ``` **Fields** **GenesisTransaction Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | amount | [Int](https://decentralchain.io/docs/ride/data-types#int) | Amount of the [token](https://decentralchain.io/docs/decentralchain/token-asset#token-asset). | | 2 | recipient | [Address](https://decentralchain.io/docs/ride/structures#address) \| [Alias](https://decentralchain.io/docs/ride/structures#alias) | [address](https://decentralchain.io/docs/decentralchain/account#address) or [alias](https://decentralchain.io/docs/decentralchain/account#alias) of the token recipient. | | 3 | id | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Transaction ID. | | 4 | fee | [Int](https://decentralchain.io/docs/ride/data-types#int) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 5 | timestamp | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction timestamp. | | 6 | version | [Int](https://decentralchain.io/docs/ride/data-types#int) | Transaction version. | --- # Iterations with FOLD Source: https://decentralchain.io/docs/ride/iterations-with-fold FOLD macro makes it possible to implement operations on a list of values such as sum, filter, map, zip, exists, etc. The macro behaves like the fold or reduce function in other programming languages. ```none FOLD(list, start, foldFunc) ``` **Iterations with FOLD** | Parameter | Description | | --- | --- | | N | Maximum number of iterations, up to 1000. | | list | List of values. | | start | Initial value. | | foldFunc | Combining function. | The combining function accepts two input parameters: the intermediate result and the next element of the list. Macro FOLD(list, start, foldFunc) means: - Execute up to N iterations. - At each iteration: take the r-esult of the previous iteration (at the first iteration take the start value) and the next list item list, apply the foldFunc function to this pair. - Return the final result. The value of N must be known in advance. If there are more elements in the list than specified in FOLD, the script fails. The complexity of FOLD corresponds to the complexity of foldFunc multiplied by N plus extras. The FOLD macro is a syntactic sugar; it is unwrapped by the compiler. Therefore, in particular, the size of the script increases linearly with N. ## Sum ```none func sum(accum: Int, next: Int) = accum + next let arr = [1,2,3,4,5] FOLD<5>(arr, 0, sum) # Result: 15 ``` The expression ```none FOLD<5>(arr, 0, sum) ``` after compiling and decompiling will look like this: ```none let $list = arr let $size = size($list) let $acc0 = 0 if (($size == 0)) then $acc0 else { let $acc1 = sum($acc0, $list[0]) if (($size == 1)) then $acc1 else { let $acc2 = sum($acc1, $list[1]) if (($size == 2)) then $acc2 else { let $acc3 = sum($acc2, $list[2]) if (($size == 3)) then $acc3 else { let $acc4 = sum($acc3, $list[3]) if (($size == 4)) then $acc4 else { let $acc5 = sum($acc4, $list[4]) if (($size == 5)) then $acc5 else { let $acc6 = sum($acc5, $list[5]) throw("List size exceed 5") } } } } } } ``` ## Product ```none func mult(accum: Int, next: Int) = accum * next let arr = [1,2,3,4,5] FOLD<5>(arr, 1, mult) # Result: 1204] ``` ## Filter The following code composes an array consisting only of even elements of the original array: ```none func filterEven(accum: List[Int], next: Int) = if (next % 2 == 0) then accum :+ next else accum let arr = [1,2,3,4,5] FOLD<5>(arr, [], filterEven) # Result: [2, 4] ``` ## Map The following code inverts the array, reducing each element by 1: ```none func map(accum: List[Int], next: Int) = (next - 1) :: accum let arr = [1, 2, 3, 4, 5] FOLD<5>(arr, [], map) # Result: [4, 3, 2, 1, 0] ``` --- # dApp-to-App Invocation Source: https://decentralchain.io/docs/ride/dapp-to-app-invocation A dApp callable function can invoke a callable function of another dApp, or another callable function of the same dApp, or even itself. The invocation is synchronous. The invoked function returns a value that the invoking function can use. dApp-to-dApp invocation is processed as follows: - A user sends an Invoke Script transaction that invokes the callable function 1. - The callable function 1 invokes the callable function 2 via a [strict variable](https://decentralchain.io/docs/ride/dapp-to-app-invocation#strict-variable) initialized by the [invoke or reentrantInvoke](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation) function. - The callable function 2 is executed; the script actions and return value are calculated. - The [return value](https://decentralchain.io/docs/ride/dapp-to-app-invocation#callable-function-result) is assigned to the strict variable. The subsequent operations of callable function 1 are executed, taking into account script actions of callable function 2 (as if the actions were applied to the blockchain state). - Finally, the script actions of callable functions 2 and 1 are applied to the blockchain state. ## Features - dApp-to-dApp invocations can be nested. - All invoked callable functions are executed within a single Invoke Script transaction. - A dApp-to-dApp invocation can contain payments that are transferred from the balance of the parent dApp to the balance of the invoked dApp. - Payments attached to a callable function invocation can be used in script actions and in payments attached to nested invocations. ## Conditions - Both the parent and invoked dApp scripts use standard library version 5. - If the dApp invokes itself, the invocation must not contain payments. - The number of the [invoke or reentrantInvoke](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation) function calls is up to 100 within a single Invoke Script transaction. - The maximum total number of Issue, Reissue, Burn, SponsorFee, ScriptTransfer, Lease, LeaseCancel script actions executed by all callable functions in a single transaction is 30. - The maximum total number of BinaryEntry, BooleanEntry, IntegerEntry, StringEntry, DeleteEntry script actions executed by all callable functions in a single transaction is 100. - The total complexity is limited by 26,000 for all callable functions and asset scripts of involved smart assets. The sender's account script complexity is not included in that limit. ## Strict Variable strict keyword defines a variable with eager evaluation. Unlike lazy variables defined with let, a strict variable is evaluated immediately when script execution reaches it, that is, before the next expression. ## Invoke and reentrantInvoke Functions ```none invoke(dApp: Address|Alias, function: String, arguments: List[Any], payments: List[AttachedPayments]): Any reentrantInvoke(dApp: Address|Alias, function: String, arguments: List[Any], payments: List[AttachedPayments]): Any ``` **Parameters:** **Invoke and ReentrantInvoke Functions** | Parameter | Description | | --- | --- | | dApp: Address\|Alias | Address or alias of a dApp to invoke. | | function: String\|Unit | Name of a callable function. unit for a default function invocation. | | arguments: List[Any] | Parameters of a callable function. | | payments: List[AttachedPayment] | Payments to transfer from the parent dApp to the invoked dApp, up to 10. | ```none strict z = invoke(dapp,foo,args,[AttachedPayment(unit,100000000)]) ``` The return value is of type Any, which means any valid type. You can extract a particular type from it using as[T] and exactAs[T] macros or the match ... case operator, see the [any](https://decentralchain.io/docs/ride/data-types#any) article. The invoke and reentrantInvoke functions differ only in the reentrancy restriction. For details, see the [dApp-to-dApp invocation function](https://decentralchain.io/docs/ride/functions#dapp-to-dapp-invocation-functions) article. ## Invocation Fields For dApp-to-dApp invocation, the fields of [Invocation](https://decentralchain.io/docs/ride/structures#invocation) structure used by the invoked function are filled with the following values: **Invocation Fields** | # | Name | Data type | Description | | --- | --- | --- | --- | | 1 | caller | [Address](https://decentralchain.io/docs/ride/structures#address) | [address](https://decentralchain.io/docs/decentralchain/account#address) of the dApp that invokes the callable function. | | 2 | callerPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the dApp that invokes the callable function. | | 3 | originCaller | Address | Address of the account that sent the invoke script transaction. | | 4 | originCallerPublicKey | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Public key of the account that sent the invoke script transaction. | | 5 | payments | [List](https://decentralchain.io/docs/ride/data-types#list) [[AttachedPayment](https://decentralchain.io/docs/ride/structures#attachedpayment)] | Payments indicated in the invoke or reentrantInvoke function. | | 6 | transactionId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | ID of the invoke script transaction. | | 7 | fee | [Int](https://decentralchain.io/docs/decentralchain/protocol#blockchain-data-types) | [Transaction fee](https://decentralchain.io/docs/decentralchain/transaction#transaction-fees). | | 8 | feeAssetId | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) \| [Unit](https://decentralchain.io/docs/ride/data-types#unit) | ID of the fee token. | ## Callable Function Result In standard library version 5, a callable function result is a [tuple](https://decentralchain.io/docs/ride/data-types#tuple) of two elements: - List of script actions. - Return value that is passed to the invoking function. Let's see an example: ```none ( [ ScriptTransfer(i.caller,100,unit) ], 42 ) ``` In standard library version 4 or 3, there is no return value, so unit is implied. For details, see the [callable function](https://decentralchain.io/docs/ride/functions#callable-functions) article. ## Updating Balance and Account Data Storage Entries If the callable function invoked by the invoke or reentrantInvoke function performs script actions, the results of those actions are available to the invoking function: - If the invoked function adds an entry to the account's data storage, the invoking function can obtain the entry after the invocation. - If the invoked function deletes an entry from the account's data storage, the invoking function cannot obtain the entry after the invocation. - If the invoked function performs actions with tokens (transfer, issue/reissue/burn, and others) and the invoking function obtains balances after the invocation, it receives the updated balances. ## Transaction Fail If the callable function's execution fails or [throws an exception](https://decentralchain.io/docs/ride/functions#exception-functions), the Invoke Script transaction could be rejected or saved on the blockchain as failed. This depends on whether the complexity of performed computations has exceeded the [threshold for saving a failed transaction](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations) (currently 1000). The complexity is summed up for all invocations. Consider the example: callable function 1 performs computations of 800 complexity, then invokes callable function 2 which performs computations of 300 complexity and then fails. The complexity 800 + 300 has exceeded the threshold, so the transaction is saved as failed, and the sender is charged a fee. If the total complexity of executed callable functions and asset scripts exceeds the limit of 26,000, the transaction is saved as failed as well. For example, if the complexity of executed callable functions is 25,000 in total, and there is a smart asset in script action whose script's complexity is 1500. In case of failure, no payments and script actions are applied to the blockchain state, even if some of the invoked functions are executed completely. The only state change the failed transaction entails is charging the fee. ## Limitations **Limitations** | Limitation | Maximum value | | --- | --- | | dApp script size | 32 Kbytes. | | Account script or asset script size | 8 Kbytes. | | [Complexity](https://decentralchain.io/docs/ride/dapp-to-app-invocation#script-complexity) of account script | 2000 | | Complexity of asset script | 4000 | | Complexity of each callable function of dApp script | 10,000 | | Total number of [dApp-to-dApp invocations](https://decentralchain.io/docs/ride/dapp-to-app-invocation#dapp-to-app-invocation) within a single Invoke Script transaction | 100 | | Total complexity for all callable functions and asset scripts involved in an Invoke Script transaction. The sender's account script complexity is not included in this limit | 26,000 | | Complexity threshold for saving failed transactions: if the callable function failed with an error or throwing an exception before the threshold exceeded, the invoke script transaction is rejected and the fee is not charged | 1000 | | Complexity of verifier function of dApp script | 2000 | | Sender complexity threshold: if the complexity of an account script or the verifier function of a dApp script exceeds this limit, the minimum fee for a transaction sent from the account is increased by 0.004 [DecentralCoins](https://decentralchain.io/docs/decentralchain/token-asset#decentralcoin) | 200 | | Function name or variable name | 255 bytes | | Size of [String](https://decentralchain.io/docs/ride/data-types#string) variable | 32,767 bytes | | Size of [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) variable | 32,767 bytes (except bodyBytes field of transaction structure). | | Data weight | See [data weight](https://decentralchain.io/docs/ride/dapp-to-app-invocation#data-weight). | | Number of callable function arguments | 22 | | Number of payments attached to an invocation | 10 | | Total number of [Issue](https://decentralchain.io/docs/ride/structures#issue), [Reissue](https://decentralchain.io/docs/ride/structures#reissue), [Burn](https://decentralchain.io/docs/ride/structures#burn), [SponsorFee](https://decentralchain.io/docs/ride/structures#sponsorfee), [ScriptTransfer](https://decentralchain.io/docs/ride/structures#scripttransfer), [Lease](https://decentralchain.io/docs/ride/structures#lease), and [LeaseCancel](https://decentralchain.io/docs/ride/structures#leasecancel) script actions executed by all callable functions in a single transaction | 30 | | Total number of [BinaryEntry](https://decentralchain.io/docs/ride/structures#binaryentry), [BooleanEntry](https://decentralchain.io/docs/ride/structures#booleanentry), [DeleteEntry](https://decentralchain.io/docs/ride/structures#deleteentry), [IntegerEntry](https://decentralchain.io/docs/ride/structures#integerentry), [StringEntry](https://decentralchain.io/docs/ride/structures#stringentry) script actions executed by all callable functions in a single transaction | 100 | | Total size of data written to the [account data storage](https://decentralchain.io/docs/decentralchain/account#account-data-storage) by all BinaryEntry, BooleanEntry, IntegerEntry, StringEntry script actions executed by a callable function | 5 Kbytes. | | Total size of data written to the account data storage by all BinaryEntry, BooleanEntry, IntegerEntry, StringEntry script actions executed by all callable functions in a single transaction | 15 Kbytes. | ### Script Complexity Script complexity is a dimensionless quantity that estimates computational resources needed to execute a script. The complexity of a script is estimated based on complexities of all the operators and functions it consists of. The complexity of the built-in functions is listed in the built-in functions article. Limitations on script complexity are given in the [limitations](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations) article. ### Data Weight The weight of each value approximately corresponds to its size in bytes. Weight is used in [limitations](https://decentralchain.io/docs/ride/dapp-to-app-invocation#limitations) on creating and comparing values. #### Weight Calculation **Weight Calculation** | Data type | Weight of value | | --- | --- | | [BigInt](https://decentralchain.io/docs/ride/data-types#bigint) | 64 | | [Boolean](https://decentralchain.io/docs/ride/data-types#boolean) | 1 | | [ByteVector](https://decentralchain.io/docs/ride/data-types#bytevector) | Size in bytes. | | [Int](https://decentralchain.io/docs/ride/data-types#int) | 8 | | [List](https://decentralchain.io/docs/ride/data-types#list) | See weight of list below. | | [String](https://decentralchain.io/docs/ride/data-types#string) | Size in bytes. | | [Structure](https://decentralchain.io/docs/ride/structures#structures) | See weight of tuple or structure. | | [Tuple](https://decentralchain.io/docs/ride/data-types#tuple) | See weight of tuple or structure. | | [Unit](https://decentralchain.io/docs/ride/data-types#unit) | 40 | #### Weight of List The weight of the list is calculated as follows: W_{list} = 20 + 20 × Q + W_{elems} where: - Q is a number of elements. - W_{elems} is a total weight of elements. #### Weight of Tuple or Structure The weight of the tuple or structure is calculated as follows: W_{struct} = 40 + 30 × Q + W_{fields} where: - Q is a number of fields. - W_{fields} is a total weight of fields. #### Weight Limitations - The maximum weight of the value is 307200. - A comparison of values is not allowed if the weight of each value exceeds 13000. If the limitations are exceeded, the script fails. Let's consider an example, using the AssetPair structure: ```none AssetPair(amountAsset: ByteVector|Unit, priceAsset: ByteVector|Unit) ``` An asset ID is a ByteVector of 32 bytes, its weight is 32. If both assets in the pair are not DecentralCoins, then the weight of the AssetPair structure is: W_{AssetPair} = 40 + 30 × 2 + (32 + 32) = 164 If one of the assets is DecentralCoin, then the corresponding field is of type Unit and its weight is 40. Then the weight of the AssetPair structure is: W_{AssetPair} = 40 + 30 × 2 + (32 + 40) = 172