DecentralChainDecentralChain
  • Technologysubmenu
    Why DecentralChainWhat sets this chain apartHow the chain worksPublic blocks, public validatorsBlockchain featuresWhat is on, what is being voted onFinalityThe rollback bound, and what is unverifiedRIDEContracts that cannot run foreverFor machinesUnsigned transactions and RIDE in processSolana bridgePhantom and Solflare, mainnet onlyNetwork statusHeight, sync and peers, read live
  • Ecosystemsubmenu
    DCC public saleOpens 26 SeptemberDecentralCoinSupply, allocation and tokenomicsDecentral.ExchangeexternalDecentralPropDecentralScansoonCubensis ConnectDecentralAmericasoon
  • Developerssubmenu
    QuickstartRead, compile and composeREST APIEvery endpoint, no key, no accountSDK packages19 on npm, 5 in the workspaceSigningAuthorising without custodyMCP & AgentsThe chain, and the tools we have builtDecentralChain NodeRun a validator, and what LPoS pays
  • Communitysubmenu
    ChannelsTelegram, X and the reposDCC AirdropAllocated, not yet arrangedGovernanceWho can actually decide anythingBrand kitThe mark, and how to use it
  • Documentation
XGitHub
Start buildingarrow
DecentralChainDecentralChain

An open Layer-1 with Leased Proof of Stake.

Native token: DecentralCoin (DCC)

Fixed supply 100,000,000 DCC
Minted at genesis, never inflated

  • X
  • GitHub
  • Telegram

Build

  • Quickstart
  • REST API
  • SDK packages
  • Signing
  • MCP & Agents
  • Documentation

Ecosystem

  • DCC public sale
  • DecentralCoin
  • Decentral.Exchange
  • DecentralProp
  • DecentralSwap
  • Cubensis Connect

Network

  • Blockchain features
  • Finality
  • RIDE
  • Solana bridge
  • Run a node
  • Network status

Project

  • Community
  • DCC Airdrop
  • Governance
  • Brand kit
  • GitHub
mainnetHeight—Node—read from your browser
© 2026 DecentralChainOperated by DecentralExchange · Cédula Jurídica 3-102-956858
Jacó, Garabito, Costa Rica
TermsPrivacySecurityLicensingdecentralchain.io
Documentation/RIDE language

Functions

RIDE language

  • Syntax Basics
  • Data Types
  • Functions
  • Script Types
  • Structures
  • Iterations with FOLD<N>
  • dApp-to-App Invocation

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. The value of the function is the expression result. Definition of the function with no parameters that returns an integer:

func main() = {
 3
}

Definition of a function with two parameters:

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.

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:

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:

{-# 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:

@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.

@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.

@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.

Account Data Storage Functions
NameDescriptionComplexity
getBinary(Address|Alias, String): ByteVector|UnitGets an array of bytes by key10
getBinary(String): ByteVector|UnitGets an array of bytes by key from dApp's own data storage10
getBinaryValue(Address|Alias, String): ByteVectorGets an array of bytes by key. Fails if there is no data10
getBinaryValue(String): ByteVectorGets an array of bytes by key from dApp's own data storage. Fails if there is no data10
getBoolean(Address|Alias, String): Boolean|UnitGets a boolean value by key10
getBoolean(String): Boolean|UnitGets a boolean value by key from dApp's own data storage10
getBooleanValue(Address|Alias, String): BooleanGets a boolean value by key. Fails if there is no data10
getBooleanValue(String): BooleanGets a boolean value by key from dApp's own data storage. Fails if there is no data10
getInteger(Address|Alias, String): Int|UnitGets an integer by key10
getInteger(String): Int|UnitGets an integer by key from dApp's own data storage10
getIntegerValue(Address|Alias, String): IntGets an integer by key. Fails if there is no data10
getIntegerValue(String): IntGets an integer by key from dApp's own data storage. Fails if there is no data10
getString(Address|Alias, String): String|UnitGets a string by key10
getString(String): String|UnitGets a string by key from dApp's own data storage10
getStringValue(Address|Alias, String): StringGets a string by key. Fails if there is no data10
getStringValue(String): StringGets a string by key from dApp's own data storage. Fails if there is no data10
isDataStorageUntouched(Address|Alias): BooleanChecks if the data storage of a given account never contained any entries10

getBinary(Address|Alias, String): ByteVector|Unit

Gets an array of bytes by key.

getBinary(addressOrAlias: Address|Alias, key: String): ByteVector|Unit

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
key: StringEntry key.

getBinary(String): ByteVector|Unit

Gets an array of bytes by key from the dApp's own data storage.

getBinary(key: String): ByteVector|Unit

Parameters

Parameters
ParameterDescription
key: StringEntry key.

getBinaryValue(Address|Alias, String): ByteVector

Gets an array of bytes by key. Fails if there is no data.

getBinaryValue(addressOrAlias: Address|Alias, key: String): ByteVector

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
key: StringEntry key.

getBinaryValue(String): ByteVector

Gets an array of bytes by key from the dApp's own data storage.

getBinaryValue(key: String): ByteVector

Parameters

Parameters
ParameterDescription
key: StringEntry key.

getBoolean(Address|Alias, String): Boolean|Unit

Gets a boolean value by key.

getBoolean(addressOrAlias: Address|Alias, key: String): Boolean|Unit

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
key: StringEntry key.

getBoolean(String): Boolean|Unit

Gets a boolean value by key by key from the dApp's own data storage.

getBoolean(key: String): Boolean|Unit

Parameters

Parameters
ParameterDescription
key: StringEntry key.

getBooleanValue(Address|Alias, String): Boolean

Gets a boolean value by key. Fails if there is no data.

getBooleanValue(addressOrAlias: Address|Alias, key: String): Boolean

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
key: StringEntry key.

getBooleanValue(String): Boolean

Gets a boolean value by key from the dApp's own data storage.

getBooleanValue(key: String): Boolean

Parameters

Parameters
ParameterDescription
key: StringEntry key.

getInteger(Address|Alias, String): Int|Unit

Gets an integer by key.

getInteger(addressOrAlias: Address|Alias, key: String): Int|Unit

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
key: StringEntry key.

getInteger(String): Int|Unit

Gets an integer by key from the dApp's own data storage.

getInteger(key: String): Int|Unit

Parameters

Parameters
ParameterDescription
key: StringEntry key.

getIntegerValue(Address|Alias, String): Int

Gets an integer by key. Fails if there is no data.

getIntegerValue(addressOrAlias: Address|Alias, key: String): Int

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
key: StringEntry key.

getIntegerValue(String): Int

Gets an integer by key from the dApp's own data storage.

getIntegerValue(key: String): Int

Parameters

Parameters
ParameterDescription
key: StringEntry key.

getString(Address|Alias, String): String|Unit

Gets a string by key.

getString(addressOrAlias: Address|Alias, key: String): String|Unit

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
key: StringEntry key.

getString(String): String|Unit

Gets a string by key from the dApp's own data storage.

getString(key: String): String|Unit

Parameters

Parameters
ParameterDescription
key: StringEntry key.

getStringValue(Address|Alias, String): String

Gets a string by key. Fails if there is no data.

getStringValue(addressOrAlias: Address|Alias, key: String): String

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
key: StringEntry key.

getStringValue(String): String

Gets a string by key from the dApp's own data storage.

getString(key: String): String

Parameters

Parameters
ParameterDescription
key: StringEntry 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.

isDataStorageUntouched(addressOrAlias: Address|Alias): Boolean

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.

Example

let addr = Address(base58'3N4iKL6ikwxiL7yNvWQmw7rg3wGna8uL6LU')
isDataStorageUntouched(addr) # Returns false

Blockchain Functions

Blockchain Functions
NameDescriptionComplexity
addressFromRecipient(Address|Alias): AddressGets the corresponding address of the alias5
assetBalance(Address|Alias, ByteVector): IntGets account balance by token ID10
assetInfo(ByteVector): Asset|UnitGets the information about a token15
blockInfoByHeight(Int): BlockInfo|UnitGets the information about a block by the block height5
calculateAssetId(Issue): ByteVectorCalculates ID of the token formed by the Issue structure when executing the callable function10
calculateLeaseId(Lease): ByteVectorCalculates ID of the lease formed by the Lease structure when executing the callable function1
scriptHash(Address|Alias): ByteVector|UnitReturns BLAKE2b-256 hash of the script assigned to a given account200
transactionHeightById(ByteVector): Int|UnitGets the block height of a transaction20
transferTransactionById(ByteVector): TransferTransaction|UnitGets the data of a transfer transaction60
decentralchainBalance(Address|Alias): BalanceDetailsGets account balance in DecentralCoins10

addressFromRecipient(Address|Alias): Address

Gets the corresponding address of the alias.

addressFromRecipient(AddressOrAlias: Address|Alias): Address

For a description of the return value, see the Address structure article.

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
Address or alias, usually tx.recipient

Example

let address = Address(base58'3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF')
addressFromRecipient(address)

assetBalance(Address|Alias, ByteVector): Int

Gets account balance by token ID.

assetBalance(addressOrAlias: Address|Alias, assetId: ByteVector): Int

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.
assetId: ByteVectortoken ID

assetInfo(ByteVector): Asset|Unit

Gets the information about a token (asset).

assetInfo(id: ByteVector): Asset|Unit

For a description of the return value, see the BlockInfo structure article.

Parameters

Parameters
ParameterDescription
id: ByteVectortoken ID

Example

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 by the block height.

blockInfoByHeight(height: Int): BlockInfo|Unit

For a description of the return value, see the BlockInfo structure article.

Parameters

Parameters
ParameterDescription
height: Intblock height

Example

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 structure when executing the callable function.

calculateAssetId(issue: Issue): ByteVector

Parameters

Parameters
ParameterDescription
issue: IssueStructure that sets the parameters of the token issue.

Example

{-# 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 structure when executing the callable function.

calculateLeaseId(lease: Lease): ByteVector

Parameters

Parameters
ParameterDescription
lease: LeaseStructure that sets the lease parameters.

Example

{-# 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.

scriptHash(addressOrAlias: Address|Alias): ByteVector|Unit

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.

Example

let addr = Address(base58'3MxBZbnN8Z8sbYjjL5N3oG5C8nWq9NMeCEm')
scriptHash(addr) # Returns base58'G6ihnWN5mMedauCgNa8TDrSKWACPJKGQyYagmMQhPuja'

transactionHeightById(ByteVector): Int|Unit

Gets the block height of a transaction.

transactionHeightById(id: ByteVector): Int|Unit

Parameters

Parameters
ParameterDescription
id: ByteVectorID of the transaction.

Example

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.

transferTransactionById(id: ByteVector): TransferTransaction|Unit

For a description of the return value, see the TransferTransaction structure article.

Parameters

Parameters
ParameterDescription
id: ByteVectorID of the transfer transaction.

Example

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 balances. For description of balance types, see the account balance article.

decentralchainBalance(addressOrAlias: Address|Alias): BalanceDetails

Parameters

Parameters
ParameterDescription
addressOrAlias: Address | Aliasaddress or alias of the account.

Byte Array Functions

Byte Array Functions
NameDescriptionComplexity
drop(ByteVector, Int): ByteVectorReturns the byte array without the first N bytes6
dropRight(ByteVector, Int): ByteVectorReturns the byte array without the last N bytes6
size(ByteVector): IntReturns the number of bytes in the byte array1
take(ByteVector, Int): ByteVectorReturns the first N bytes of the byte array6
takeRight(ByteVector, Int): ByteVectorReturns the last N bytes of the byte array6

drop(ByteVector, Int): ByteVector

Returns the byte array without the first N bytes.

drop(xs: ByteVector, number: Int): ByteVector

Parameters

Parameters
ParameterDescription
xs: ByteVectorByte array.
number: IntN bytes.

Example

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.

dropRight(xs: ByteVector, number: Int): ByteVector

Parameters

Parameters
ParameterDescription
xs: ByteVectorByte array.
number: IntN bytes.

Example

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.

size(byteVector: ByteVector): Int

Parameters

Parameters
ParameterDescription
xs: ByteVectorByte array.

Example

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.

take(xs: ByteVector, number: Int): ByteVector

Parameters

Parameters
ParameterDescription
xs: ByteVectorByte array.
number: IntN bytes.

Example

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.

takeRight(xs: ByteVector, number: Int): ByteVector

Parameters

Parameters
ParameterDescription
xs: ByteVectorByte array.
number: IntN bytes.

Example

takeRight(base58'37BPKA', 2) # Returns the last 2 bytes of the byte array

Converting Functions

Converting Functions
NameDescriptionComplexity
addressFromPublicKey(ByteVector): AddressGets the corresponding address of the account public key `63
parseBigInt(String): BigInt|UnitConverts the string representation of a number to its big integer equivalent65
parseBigIntValue(String): BigIntConverts the string representation of a number to its big integer equivalent. Fails if the string cannot be parsed65
parseInt(String): Int|UnitConverts the string representation of a number to its integer equivalent2
parseIntValue(String): IntConverts the string representation of a number to its integer equivalent. Fails if the string cannot be parsed2
toBigInt(ByteVector): BigIntConverts an array of bytes to a big integer65
toBigInt(ByteVector, Int, Int): BigIntConverts an array of bytes starting from a certain index to a big integer65
toBigInt(Int): BigIntConverts an integer to a big integer1
toBytes(Boolean): ByteVectorConverts a boolean to an array of bytes1
toBytes(Int): ByteVectorConverts an integer to an array of bytes1
toBytes(String): ByteVectorConverts a string to an array of bytes8
toBytes(BigInt): ByteVectorConverts a big integer to an array of bytes65
toInt(BigInt): IntConverts a big integer to an integer. Fails if the number cannot be converted1
toInt(ByteVector): IntConverts an array of bytes to an integer1
toInt(ByteVector, Int): IntConverts an array of bytes to an integer starting from a certain index1
toString(Address): StringConverts an address to a string10
toString(Boolean): StringConverts a boolean to a string1
toString(Int): StringConverts an integer to a string1
toString(BigInt): StringConverts a big integer to a string65
toUtf8String(ByteVector): StringConverts an array of bytes to a UTF-8 string7
transferTransactionFromProto(ByteVector): TransferTransaction|UnitDeserializes transfer transaction5

addressFromPublicKey(ByteVector): Address

Gets the corresponding address of the account public key.

addressFromPublicKey(publicKey: ByteVector): Address

For a description of the return value, see the Address structure article.

Parameters

Parameters
ParameterDescription
publicKey: ByteVectorPublic key.

Example

let address = addressFromPublicKey(base58'J1t6NBs5Hd588Dn7mAPytqkhgeBshzv3zecScfFJWE2D')

parseBigInt(String): BigInt|Unit

Converts the string representation of a number to its big integer equivalent.

parseBigInt(str: String): BigInt|Unit

Parameters

Parameters
ParameterDescription
str: StringString to parse.

parseBigIntValue(String): BigInt

Converts the string representation of a number to its big integer equivalent. Fails if the string cannot be parsed.

parseBigIntValue(str: String): BigInt

Parameters

Parameters
ParameterDescription
str: StringString to parse.

parseInt(String): Int|Unit

Converts the string representation of a number to its integer equivalent.

parseInt(str: String): Int|Unit

Parameters

Parameters
ParameterDescription
str: StringString to parse.

Example

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.

parseIntValue(str: String): Int

Parameters

Parameters
ParameterDescription
str: StringString to parse.

Example

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 using the big-endian byte order.

toBigInt(bin: ByteVector): BigInt

Parameters

Parameters
ParameterDescription
bin: ByteVectorArray of bytes to convert.

toBigInt(ByteVector, Int, Int): BigInt

Converts an array of bytes starting from a certain index to a big integer using the big-endian byte order.

toBigInt(bin: ByteVector, offset: Int, size: Int): BigInt

Parameters

Parameters
ParameterDescription
bin: ByteVectorArray of bytes to convert.
offset: IntIndex to start from.
size: IntNumber of bytes (subarray length) to convert.

toBigInt(Int): BigInt

Converts an integer to a big integer.

toBigInt(n: Int): BigInt

Parameters

Parameters
ParameterDescription
n: IntInteger to convert.

toBytes(Boolean): ByteVector

Converts a boolean value to an array of bytes.

toBytes(b: Boolean): ByteVector

Parameters

Parameters
ParameterDescription
b: BooleanBoolean to convert.

Example

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.

toBytes(n: Int): ByteVector

Parameters

Parameters
ParameterDescription
n: IntInteger to convert.

Example

toBytes(10) # Returns base58'1111111B'

toBytes(String): ByteVector

Converts a string to an array of bytes.

toBytes(s: String): ByteVector

Parameters

Parameters
ParameterDescription
str: StringString to convert.

Example

toBytes("Ride") # Returns base58'37BPKA'

toBytes(BigInt): ByteVector

Converts a big integer to an array of bytes using the big-endian byte order.

toBytes(n: BigInt): ByteVector

Parameters

Parameters
ParameterDescription
n: BigIntBig integer to convert.

toInt(BigInt): Int

Converts a big integer to an integer. Fails if the number cannot be converted.

toInt(n: BigInt): Int

Parameters

Parameters
ParameterDescription
n: BigIntBig integer to convert.

toInt(ByteVector): Int

Converts an array of bytes to an integer using the big-endian byte order.

toInt(bin: ByteVector) : Int

Parameters

Parameters
ParameterDescription
bin: ByteVectorArray of bytes to convert.

Example

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.

toInt(bin: ByteVector, offset: Int): Int

Parameters

Parameters
ParameterDescription
bin: ByteVectorArray of bytes to convert.
offset: IntIndex to start from.

Example

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 to a string.

toString(addr: Address): String

Parameters

Parameters
ParameterDescription
addr: AddressAddress to convert.

Example

let address = Address(base58'3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF')
toString(address) # Returns "3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF"

toString(Boolean): String

Converts a boolean value to a string.

toString(b: Boolean): String

Parameters

Parameters
ParameterDescription
b: BooleanBoolean to convert.

Example

toString(true) # Returns "true"
toString(false) # Returns "false"

toString(Int): String

Converts an integer to a string.

toString(n: Int): String

Parameters

Parameters
ParameterDescription
n: IntInteger to convert.

Example

toString(10) # Returns "10"

toString(BigInt): String

Converts a big integer to a string.

toString(n: BigInt): String

Parameters

Parameters
ParameterDescription
n: BigIntBig 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.

toUtf8String(u: ByteVector): String

Parameters

Parameters
ParameterDescription
u: ByteVectorArray of bytes to convert.

Example

let bytes = toBytes("Ride")
toUtf8String(bytes) # Returns "Ride"

transferTransactionFromProto(ByteVector): TransferTransaction|Unit

Deserializes transfer transaction: converts protobuf-encoded binary format specified in transaction.proto to a TransferTransaction structure. Returns unit if deserialization failed.

transferTransactionFromProto(b: ByteVector): TransferTransaction|Unit

For a description of the return value, see the TransferTransaction structure article.

Parameters

Parameters
ParameterDescription
b: ByteVectorTransfer transaction in protobuf-encoded binary format.

Example

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
NameDescriptionComplexity
invoke(Address|Alias, String, List[Any], List[AttachedPayments]): AnyInvokes a dApp callable function, with reentrancy restriction75
reentrantInvoke(Address|Alias, String, List[Any], List[AttachedPayments]): AnyInvokes a dApp callable function, without reentrancy restriction75

invoke(Address|Alias, String, List[Any], List[AttachedPayments]): Any

Invokes a dApp callable function, with reentrancy restriction.

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 article.

The invoke function can be used by a callable function of a dApp script, but not by a verifier function, account script or 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 article.

To ensure executing callable functions and applying their actions in the right order, initialize a strict variable 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 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 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:

→ dApp A
  → dapp B
      → dApp A
→ dApp A
  → dapp B
     → dApp C
        → dApp A

The following invocation stacks are valid:

→ dApp A
  → dapp A
     → dapp A
→ dApp N
  → dapp A
  → dApp A
→ dapp N
  → dapp A
     → dapp B
  → dapp B
     → dapp A
     → dapp C
Parameters
ParameterDescription
dApp: Address | Aliasaddress or alias of a dApp to invoke.
function: String | UnitName 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.

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 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:

{-# 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:

{-# 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. 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:

→ 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.
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 structure or from any list of data entries.

Data Transaction Functions
NameDescriptionComplexity
getBinary(List[], String): ByteVector|UnitGets a binary value from a list of data entires by key10
getBinary(List[], Int): ByteVector|UnitGets a binary value from a list of data entires by index4
getBinaryValue(List[], String): ByteVectorGets a binary value from a list of data entires by key. Fails if there is no data10
getBinaryValue(List[], Int): ByteVectorGets a binary value from a list of data entires by index. Fails if there is no data4
getBoolean(List[], String): Boolean|UnitGets a boolean value from a list of data entires by key10
getBoolean(List[], Int): Boolean|UnitGets a boolean value from a list of data entires by index4
getBooleanValue(List[], String): BooleanGets a boolean value from a list of data entires by key. Fails if there is no data10
getBooleanValue(List[], Int): BooleanGets a boolean value from a list of data entires by index. Fails if there is no data4
getInteger(List[], String): Int|UnitGets an integer value from a list of data entires by key10
getInteger(List[], Int): Int|UnitGets an integer value from a list of data entires by index4
getIntegerValue(List[], String): IntGets an integer value from a list of data entires by key. Fails if there is no data10
getIntegerValue(List[], Int): IntGets an integer value from a list of data entires by index. Fails if there is no data4
getString(List[], String): String|UnitGets a string value from a list of data entires by key10
getString(List[], Int): String|UnitGets a string value from a list of data entires by index4
getStringValue(List[], String): StringGets a string value from a list of data entires by key. Fails if there is no data10
getStringValue(List[], Int): StringGets a string value from a list of data entires by index. Fails if there is no data4

getBinary(List[], String): ByteVector|Unit

Gets a binary value from a list of data entires by key.

getBinary(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): ByteVector|Unit

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
key: StringKey.

getBinary(List[], Int): ByteVector|Unit

Gets a binary value from a list of data entires by index.

getBinary(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): ByteVector|Unit

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
index: IntIndex.

getBinaryValue(List[], String): ByteVector

Gets a binary value from a list of data entires by key. Fails if there is no data.

getBinaryValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): ByteVector

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
key: StringKey.

getBinaryValue(List[], Int): ByteVector

Gets a binary value from a list of data entires by index. Fails if there is no data.

getBinaryValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): ByteVector

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
index: IntIndex.

getBoolean(List[], String): Boolean|Unit

Gets a boolean value from a list of data entires by key.

getBoolean(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): Boolean|Unit

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
key: StringKey.

getBoolean(List[], Int): Boolean|Unit

Gets a boolean value from a list of data entires by index.

getBoolean(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): Boolean|Unit

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
index: IntIndex.

getBooleanValue(List[], String): Boolean

Gets a boolean value from a list of data entires by key. Fails if there is no data.

getBooleanValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): Boolean

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
key: StringKey.

getBooleanValue(List[], Int): Boolean

Gets a boolean value from a list of data entires by index. Fails if there is no data.

getBooleanValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): Boolean

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
index: IntIndex.

getInteger(List[], String): Int|Unit

Gets integer from a list of data entires by key.

getInteger(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): Int|Unit

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
key: StringKey.

getInteger(List[], Int): Int|Unit

Gets an integer value from a list of data entires by index.

getInteger(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): Int|Unit

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
index: IntIndex.

getIntegerValue(List[], String): Int

Gets an integer value from a list of data entires by key. Fails if there is no data.

getIntegerValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): Int

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
key: StringKey.

getIntegerValue(List[], Int): Int

Gets an integer value from a list of data entires by index. Fails if there is no data.

getIntegerValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): Int

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
index: IntIndex.

getString(List[], String): String|Unit

Gets a string value from a list of data entires by key.

getString(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): String|Unit

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
key: StringKey.

getString(List[], Int): String|Unit

Gets a string value from a list of data entires by key.

getString(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): String|Unit

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
index: IntIndex.

getStringValue(List[], String): String

Gets a string value from a list of data entires by key. Fails if there is no data.

getStringValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], key: String): String

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
key: StringKey.

getStringValue(List[], Int): String

Gets a string value from a list of data entires by index. Fails if there is no data.

getStringValue(data: List[BinaryEntry|BooleanEntry|IntegerEntry|StringEntry], index: Int): String

Parameters

Parameters
ParameterDescription
data: List []List of data entries, usually tx.data.
index: IntIndex.

Decoding Functions

Decoding Functions
NameDescriptionComplexity
addressFromString(String): Address|UnitDecodes address from base58 string1
addressFromStringValue(String): AddressDecodes address from base58 string. Fails if the address cannot be decoded1
fromBase16String(String): ByteVectorDecodes base16 string to an array of bytes10
fromBase58String(String): ByteVectorDecodes base58 string to an array of bytes1
fromBase64String(String): ByteVectorDecodes base64 string to an array of bytes40

addressFromString(String): Address|Unit

Decodes address from base58 string.

addressFromString(string: String): Address|Unit

For a description of the return value, see the Address structure article.

Parameters

Parameters
ParameterDescription
string: stringString to decode.

Example

let address = addressFromString("3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF")

addressFromStringValue(String): Address

Decodes address from base58 string. Fails if the address cannot be decoded.

addressFromStringValue(string: String): Address

For a description of the return value, see the Address structure article.

Parameters

Parameters
ParameterDescription
string: stringString to decode.

Example

let address = addressFromStringValue("3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF")

fromBase16String(String): ByteVector

Decodes a base16 string to an array of bytes.

fromBase16String(str: String): ByteVector

Parameters

Parameters
ParameterDescription
string: stringString to decode.

Example

let bytes = fromBase16String("52696465")

fromBase58String(String): ByteVector

Decodes a base58 string to an array of bytes.

fromBase58String(str: String): ByteVector

Parameters

Parameters
ParameterDescription
string: stringString to decode.

Example

let bytes = fromBase58String("37BPKA")

fromBase64String(String): ByteVector

Decodes a base64 string to an array of bytes.

fromBase64String(str: String): ByteVector

Parameters

Parameters
ParameterDescription
string: stringString to decode.

Example

let bytes = fromBase64String("UmlkZQ==")

Encoding Functions

Encoding Functions
NameDescriptionComplexity
toBase16String(ByteVector): StringEncodes array of bytes to base16 string10
toBase58String(ByteVector): StringEncodes array of bytes to base58 string3
toBase64String(ByteVector): StringEncodes array of bytes to base64 string35

toBase16String(ByteVector): String

Encodes an array of bytes to a base16 string.

toBase16String(bytes: ByteVector): String

Parameters

Parameters
ParameterDescription
bytes: ByteVectorArray of bytes to encode.

Example

toBase16String("Ride".toBytes()) # Returns "52696465"
toBase16String(base16'52696465') # Returns "52696465"

toBase58String(ByteVector): String

Encodes an array of bytes to a base58 string.

toBase58String(bytes: ByteVector): String

Parameters

Parameters
ParameterDescription
bytes: ByteVectorArray of bytes to encode.

Example

toBase58String("Ride".toBytes()) # Returns "37BPKA"
toBase58String(base58'37BPKA')  # Returns "37BPKA

toBase64String(ByteVector): String

Encodes an array of bytes to a base64 string.

toBase64String(bytes: ByteVector): String

Parameters

Parameters
ParameterDescription
bytes: ByteVectorArray of bytes to encode.

Example

toBase64String("Ride".toBytes()) # Returns "UmlkZQ=="
toBase64String(base64'UmlkZQ==') # Returns "UmlkZQ=="

Exception Functions

Exception Functions
NameDescriptionComplexity
throw()Raises an exception1
throw(String)Raises an exception with a message1

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 article for details.

throw()

Raises an exception.

throw(String)

Raises an exception with a message.

throw(err: String)

Parameters

Parameters
ParameterDescription
err: StringThe exception message.

Hashing Functions

Hashing Functions
NameDescriptionComplexity
blake2b256(ByteVector): ByteVectorRange of functions. Hash an array of bytes using BLAKE2b-25610–200
keccak256(ByteVector): ByteVectorRange of functions. Hash an array of bytes using Keccak-25610–200
sha256(ByteVector): ByteVectorRange of functions. Hash an array of bytes using SHA-25610–200

blake2b256(ByteVector): ByteVector

Range of functions that hash an array of bytes using BLAKE2b-256.

blake2b256
NameMax data sizeComplexity
blake2b256(bytes: ByteVector): ByteVector150 kB200
blake2b256_16Kb(bytes: ByteVector): ByteVector16 kB10
blake2b256_32Kb(bytes: ByteVector): ByteVector32 kB25
blake2b256_64Kb(bytes: ByteVector): ByteVector64 kB50
blake2b256_128Kb(bytes: ByteVector): ByteVector128 kB100

Parameters

Parameters
ParameterDescription
bytes: ByteVectorThe array of bytes to encode. Maximum size: 1) For blake2b256_<N>Kb functions — N kB. 2) For blake2b256 function — 150 kB.

Example

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
NameMax data sizeComplexity
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
ParameterDescription
bytes: ByteVectorThe array of bytes to encode. Maximum size: 1) For keccak256_<N>Kb functions — N kB. 2) For keccak256 function — 150 kB.

Example

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
NameMax data sizeComplexity
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
ParameterDescription
bytes: ByteVectorThe array of bytes to encode. Maximum size: 1) For sha256_<N>Kb functions — N kB. 2) For sha256 function — 150 kB.

Example

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
NameDescriptionComplexity
cons(A, List[B]): List[A|B]Inserts element to the beginning of the list1
containsElement(List[T], T): BooleanCheck if the element is in the list5
getElement(List[T], Int): TGets element from the list2
indexOf(List[T], T): Int|UnitReturns the index of the first occurrence of the element in the list5
lastIndexOf(List[T], T): Int|UnitReturns the index of the last occurrence of the element in the list5
max(List[Int]): IntReturns the largest element in the list of integers3
max(List[BigInt]): BigIntReturns the largest element in the list of big integers192
min(List[Int]): IntReturns the smallest element in the list of integers3
min(List[BigInt]): BigIntReturns the smallest element in the list of big integers192
removeByIndex(List[T], Int): List[T]Removes an element from the list by index7
size(List[T]): IntReturns the size of the list2

A, B, T means any valid type.

cons(A, List[B]): List[A|B]

Inserts element to the beginning of the list.

cons(head:T, tail: List[T]): List[T]

Parameters

Parameters
ParameterDescription
head: TElement
tail: List [T]List

Example

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.

containsElement(list: List[T], element: T): Boolean

Parameters

Parameters
ParameterDescription
list: List [T]List
element: TElement to search for

getElement(List[T], Int): T

Gets the element from the list by index.

getElement(arr: List[T], pos: Int): T

Parameters

Parameters
ParameterDescription
arr: List [T]List
pos: IntIndex of the element

Example

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 or unit if the element is missing.

indexOf(list: List[T], element: T): Int|Unit

Parameters

Parameters
ParameterDescription
list: List [T]List
element: TElement to locate

Example

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 or unit if the element is missing.

lastIndexOf(list: List[T], element: T): Int|Unit

Parameters

Parameters
ParameterDescription
list: List [T]List
element: TElement to locate

Example

let stringList = ["a","b","a","c"]
lastIndexOf("a", stringList) # Returns 2

max(List[Int]): Int

Returns the largest element in the list of integers. Fails if the list is empty.

max(List[Int]): Int

Parameters

Parameters
ParameterDescription
list: List [Int]List

max(List[BigInt]): BigInt

Returns the largest element in the list of big integers. Fails if the list is empty.

max(List[BigInt]): BigInt

Parameters

Parameters
ParameterDescription
list: List [BigInt]List

min(List[Int]): Int

Returns the smallest element in the list of integers. Fails if the list is empty.

min(List[Int]): Int

Parameters

Parameters
ParameterDescription
list: List [Int]List

min(List[BigInt]): BigInt

Returns the smallest element in the list of big integers. Fails if the list is empty.

min(List[BigInt]): BigInt

Parameters

Parameters
ParameterDescription
list: List [BigInt]List

removeByIndex(List[T], Int): List[T]

Removes an element from the list by index.

removeByIndex(list: List[T], index: Int): List[T]

Parameters

Parameters
ParameterDescription
list: List [T]List
index: TIndex of the element

Example

removeByIndex(["Ride", 42, true], 1) # Returns ["Ride", true]

size(List[T]): Int

Returns the size of the list.

size(arr: List[T]): Int

Parameters

Parameters
ParameterDescription
arr: List [T]List

Example

size(["Hello", "World", "."]) # Returns 3

Math Functions

Math Functions
NameDescriptionComplexity
fraction(Int, Int, Int): IntMultiplies and divides integers to avoid overflow14
fraction(Int, Int, Int, Union): IntMultiplies and divides integers to avoid overflow, applying the specified rounding method17
fraction(BigInt, BigInt, BigInt): BigIntMultiplies and divides bid integers to avoid overflow128
fraction(BigInt, BigInt, BigInt, Union): BigIntMultiplies and divides big integers to avoid overflow, applying the specified rounding method128
log(Int, Int, Int, Int, Int, Union): IntCalculates logarithm of a number with a base100
log(BigInt, Int, BigInt, Int, Int, Union): BigIntCalculates logarithm of a number to a given base with high accuracy200
median(List[Int]): IntReturns the median of a list of integers20
median(List[BigInt]): BigIntReturns the median of a list of big integers160
pow(Int, Int, Int, Int, Int, Union): IntRaises a number to a given power100
pow(BigInt, Int, BigInt, Int, Int, Union): BigIntRaises a number to a given power with high accuracy200

fraction(Int, Int, Int): Int

Multiplies integers 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.

fraction(a: Int, b: Int, c: Int): Int

Parameters

Parameters
ParameterDescription
a: IntInteger a
b: IntInteger b
c: IntInteger 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 \* and /, fails due to overflow:

a * b / c #  overflow, because a × b exceeds max integer value

The fraction function with no overflow:

fraction(a, b, c) # Result: 2,000,000,000,000,000,000

fraction(Int, Int, Int, Union): Int

Multiplies integers 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.

fraction(a: Int, b: Int, c: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int

Parameters

Parameters
ParameterDescription
a: IntInteger a
b: IntInteger b
c: IntInteger c
round: DOWN|CEILING|FLOOR|HALFUP|HALFEVENOne of the rounding variables

fraction(BigInt, BigInt, BigInt): BigInt

Multiplies integers 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.

fraction(a: BigInt, b: BigInt, c: BigInt): BigInt

Parameters

Parameters
ParameterDescription
a: BigIntBig integer a
b: BigIntBig integer b
c: BigIntBig integer c

fraction(BigInt, BigInt, BigInt, Union): BigInt

Multiplies integers 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.

fraction(a: BigInt, b: BigInt, c: BigInt, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt

Parameters

Parameters
ParameterDescription
a: BigIntBig integer a
b: BigIntBig integer b
c: BigIntBig integer c
round: DOWN|CEILING|FLOOR|HALFUP|HALFEVENOne of the rounding variables

log(Int, Int, Int, Int, Int, Union): Int

Calculates log_b a.

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 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
ParameterDescription
value: IntNumber a without decimal point.
vp: IntNumber of decimals of a.
base: IntLogarithm base b without decimal point.
bp: IntNumber of decimals of b.
rp: IntNumber of decimals in the resulting value, from 0 to 8 inclusive. Specifies the accuracy of the calculated result.
round: DOWN|CEILING|FLOOR|HALFUP|HALFEVENOne of the rounding variables.

Example

log_{2.7} 16.25 = 2.807035421...

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.

log(value: BigInt, ep: Int, base: BigInt, bp: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt

Parameters

Parameters
ParameterDescription
value: BigIntNumber a without decimal point.
vp: IntNumber of decimals of a.
base: BigIntLogarithm base b without decimal point.
bp: IntNumber of decimals of b.
rp: IntNumber of decimals in the resulting value, from 0 to 18 inclusive. Specifies the accuracy of the calculated result.
round: DOWN|CEILING|FLOOR|HALFUP|HALFEVENOne of the rounding variables.

median(List[Int]): Int

Returns the median of the list of integers. Fails if the list is empty.

median(arr: List[Int]): Int

Parameters

Parameters
ParameterDescription
arr: List [Int]List of integers

Example

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 of big integers. Fails if the list is empty or contains more than 100 elements.

median(arr: List[BigInt]): BigInt

Parameters

Parameters
ParameterDescription
arr: List [BigInt]List of big integers

pow(Int, Int, Int, Int, Int, Union): Int

Calculates a^{b}.

pow(base: Int, bp: Int, exponent: Int, ep: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): Int

Parameters

Parameters
ParameterDescription
base: IntLogarithm base b without decimal point.
bp: IntNumber of decimals of a.
exponent: IntExponent b without decimal point.
ep: IntNumber of decimals of b.
rp: IntNumber of decimals in the resulting value, from 0 to 8 inclusive. Specifies the accuracy of the calculated result.
round: DOWN|CEILING|FLOOR|HALFUP|HALFEVENOne of the rounding variables.

Example

16.25^{2.7} = 1859,1057168...

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.

pow(base: BigInt, bp: Int, exponent: BigInt, ep: Int, rp: Int, round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN): BigInt

Parameters

Parameters
ParameterDescription
base: BigIntLogarithm base b without decimal point.
bp: IntNumber of decimals of a.
exponent: BigIntExponent b without decimal point.
ep: IntNumber of decimals of b.
rp: IntNumber of decimals in the resulting value, from 0 to 18 inclusive. Specifies the accuracy of the calculated result.
round: DOWN|CEILING|FLOOR|HALFUP|HALFEVENOne 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
NameDescription
DOWNRounds towards zero.
CEILINGRounds towards positive infinity.
FLOORRounds towards negative infinity.
HALFUPRounds towards the nearest integer; if the integers are equidistant, then rounds away from zero.
HALFEVENRounds towards the nearest integer; if the integers are equidistant, then rounds towards the nearest even integer.

Example

Parameters
Input number/Rounding methodDOWNCEILINGFLOORHALFUPHALFEVEN
5.556566
2.523232
1.612122
1.112111
1.011111
-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
NameDescriptionComplexity
contains(String, String): BooleanChecks whether the string contains substring3
drop(String, Int): StringDrops the first n characters of a string20
dropRight(String, Int): StringDrops the last n characters of a string20
indexOf(String, String): Int|UnitReturns the index of the first occurrence of a substring3
indexOf(String, String, Int): Int|UnitReturns the index of the first occurrence of a substring after a certain index3
lastIndexOf(String, String): Int|UnitReturns the index of the last occurrence of a substring3
lastindexOf(String, String, Int): Int|UnitReturns the index of the last occurrence of a substring before a certain index3
makeString(List[String], String): StringConcatenates list strings adding a separator30
size(String): IntReturns the size of a string1
split(String, String): List[String]Splits a string delimited by a separator into a list of substrings.75
take(String, Int): StringTakes the first n characters from a string20
takeRight(String, Int): StringTakes the last n characters from a string20

contains(String, String): Boolean

Checks whether the string contains substring.

contains(haystack: String, needle: String): Boolean

Parameters

Parameters
ParameterDescription
haystack: StringString to search in.
needle: StringString to search for.

Example

"hello".contains("hell") # Returns true
"hello".contains("world") # Returns false

drop(String, Int): String

Drops the first n characters of a string.

drop(xs: String, number: Int): String

Parameters

Parameters
ParameterDescription
xs: StringThe string.
number: IntThe number n.

Example

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.

dropRight(xs: String, number: Int): String

Parameters

Parameters
ParameterDescription
xs: StringThe string.
number: IntThe number n.

Example

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.

indexOf(str: String, substr: String): Int|Unit

Parameters

Parameters
ParameterDescription
str: StringThe string.
substr: StringThe substring.

Example

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.

indexOf(str: String, substr: String, offset: Int): Int|Unit

Parameters

Parameters
ParameterDescription
str: StringThe string.
substr: StringThe substring.
offset: IntThe index.

Example

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.

lastIndexOf(str: String, substr: String): Int|Unit

Parameters

Parameters
ParameterDescription
str: StringThe string.
substr: StringThe substring.

Example

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.

lastIndexOf(str: String, substr: String, offset: Int): Int|Unit

Parameters

Parameters
ParameterDescription
str: StringThe string.
substr: StringThe substring.
offset: IntThe index.

Example

lastIndexOf("mamamama","ma",4) # Returns 4
lastIndexOf("mamamama","ma",3) # Returns 2

makeString(List[String], String): String

Concatenates list strings adding a separator.

makeString(arr: List[String], separator: String): String

Parameters

Parameters
ParameterDescription
arr: List [String]List of strings to concatenate.
separator: StringSeparator.

Example

makeString(["Apple","Orange","Mango"], " & ") # Returns "Apple & Orange & Mango"

size(String): Int

Returns the size of a string.

size(xs: String): Int

Parameters

Parameters
ParameterDescription
xs: StringThe string.

Example

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.

split(str: String, separator: String): List[String]

Parameters

Parameters
ParameterDescription
str: StringThe string.
separator: StringThe separator.

Example

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.

take(xs: String, number: Int): String

Parameters

Parameters
ParameterDescription
xs: StringThe string.
number: IntThe number n.

Example

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.

takeRight(xs: String, number: Int): String

Parameters

Parameters
ParameterDescription
xs: StringThe string.
number: IntThe number n.

Example

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
NameDescriptionComplexity
isDefined(T|Unit): BooleanChecks if an argument is not unit1
value(T|Unit): TGets a value from a union type argument. Fails if it is unit2
valueOrElse(T|Unit, T): TReturns a value from a union type argument if it's not unit. Otherwise, returns the second argument2
valueOrErrorMessage(T|Unit, String): TGets a value from a union type argument if it's not unit. Otherwise, fails with the message specified in the second argument2

isDefined(T|Unit): Boolean

Checks if an argument is not unit.

isDefined(a: T|Unit): Boolean

Parameters

Parameters
ParameterDescription
a: T|UnitArgument to check.

value(T|Unit): T

Gets a value from a union type argument. Fails if it is unit.

value(a: T|Unit): T

Parameters

Parameters
ParameterDescription
a: T|UnitArgument to return value from.

valueOrElse(T|Unit, T): T

Returns a value from a union type argument if it's not unit. Otherwise, returns the second argument.

valueOrElse(t: T|Unit, t0: T): T

Parameters

Parameters
ParameterDescription
a: T|UnitArgument to return value from.
t0: TReturned if t is unit.

valueOrErrorMessage(T|Unit, String): T

Returns a value from a union type argument if it's not unit. Otherwise, fails with the message specified in the second argument.

valueOrErrorMessage(a: T|Unit, msg: String): T

Parameters

Parameters
ParameterDescription
a: T|UnitArgument to return value from.
msg: StringError message.

Verification Functions

Verification Functions
NameDescriptionComplexity
bn256groth16Verify(ByteVector, ByteVector, ByteVector): BooleanRange of functions. Check zk-SNARK by groth16 protocol on the bn254 curve800–1650
createMerkleRoot(List[ByteVector], ByteVector, Int) : ByteVectorCalculates the Merkle root hash for transactions of block30
ecrecover(messageHash: ByteVector, signature: ByteVector)Recovers public key from the message hash and the ECDSA digital signature70
groth16Verify(ByteVector, ByteVector, ByteVector): BooleanRange of functions. Check zk-SNARK by groth16 protocol on the bls12-381 curve1200–2700
rsaVerify(digestAlgorithmType, ByteVector, ByteVector, ByteVector): BooleanRange of functions. Check that the RSA digital signature is valid, i.e. it was created by the owner of the public key500–1000
sigVerify(ByteVector, ByteVector, ByteVector): BooleanRange of functions. Check that the Curve25519 digital signature is valid, i.e. it was created by the owner of the public key47–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
NameMax number of inputsComplexity
bn256groth16Verify(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean161650
bn256groth16Verify_1inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean1800
bn256groth16Verify_2inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean2850
bn256groth16Verify_3inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean3950
bn256groth16Verify_4inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean41000
bn256groth16Verify_5inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean51050
bn256groth16Verify_6inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean61100
bn256groth16Verify_7inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean71150
bn256groth16Verify_8inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean81200
bn256groth16Verify_9inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean91250
bn256groth16Verify_10inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean101300
bn256groth16Verify_11inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean111350
bn256groth16Verify_12inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean121400
bn256groth16Verify_13inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean131450
bn256groth16Verify_14inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean141550
bn256groth16Verify_15inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean151600

Parameters

Parameters
ParameterDescription
vk: ByteVectorKey for the check. Maximum size: 1) For bn256groth16Verify_<N>inputs function — 256 + 32 × N bytes. 2) For bn256groth16Verify function — 256 + 32 × 16 = 768 bytes.
proof: ByteVectorZero-knowledge proof. Fixed size: 128 bytes.
inputs: ByteVectorZero-knowledge proof's public inputs array. For example, array of UTXO hashes in case of shielded transactions. Maximum size: 1) For bn256groth16Verify_<N>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.

createMerkleRoot(merkleProofs: List[ByteVector], valueBytes: ByteVector, index: Int): ByteVector

Parameters

Parameters
ParameterDescription
merkleProofs: List [ByteVector]Array of sibling hashes of the Merkle tree. Up to 16 items, 32 bytes each.
valueBytes: ByteVectorHash of transaction. Fixed size: 32 bytes. You can use blake2b256 function. The transaction must be hashed together with the signature.
index: IntIndex 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.

ecrecover(messageHash: ByteVector, signature: ByteVector): ByteVector

Parameters

Parameters
ParameterDescription
messageHash: ByteVectorKeccak-256 hash of the message. Fixed size: 32.
signature: ByteVectorECDSA 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.
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
NameMax number of inputsComplexity
groth16Verify(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean162700
groth16Verify_1inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean11200
groth16Verify_2inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean21300
groth16Verify_3inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean31400
groth16Verify_4inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean41500
groth16Verify_5inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean51600
groth16Verify_6inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean61700
groth16Verify_7inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean71800
groth16Verify_8inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean81900
groth16Verify_9inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean92000
groth16Verify_10inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean102100
groth16Verify_11inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean112200
groth16Verify_12inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean122300
groth16Verify_13inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean132400
groth16Verify_14inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean142500
groth16Verify_15inputs(vk:ByteVector, proof:ByteVector, inputs:ByteVector): Boolean152600

Parameters

Parameters
ParameterDescription
vk: ByteVectorKey for the check. Maximum size: 1) For groth16Verify_<N>inputs function — 384 + 48 × N bytes. 2) For groth16Verify function — 384 + 48 × 16 = 1152 bytes.
proof: ByteVectorZero-knowledge proof. Fixed size: 192 bytes.
inputs: ByteVectorZero-knowledge proof's public inputs array. For example, array of UTXO hashes in case of shielded transactions. Maximum size: 1) For groth16Verify_<N>inputs function – 32 × N bytes. 2) For groth16Verify function – 512 bytes.

Example

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
NameMax message sizeComplexity
rsaVerify(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean150 kB1000
rsaVerify_16Kb(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean16 kB500
rsaVerify_32Kb(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean32 kB550
rsaVerify_64Kb(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean64 kB625
rsaVerify_128Kb(digest: digestAlgorithmType, message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean128 kB750

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
ParameterDescription
digest: digestAlgorithmTypeThe 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: ByteVectorSigned data. Maximum size: 1) For rsaVerify_<N>Kb functions — N bytes. 2) For rsaVerify function — 150 bytes.
sig: ByteVectorDigital signature. Fixed size: 25 bytes.
pub: ByteVectorBinary 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
NameMax message sizeComplexity
sigVerify(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean150 kB200
sigVerify_8Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean8 kB47
sigVerify_16Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean16 kB57
sigVerify_32Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean32 kB70
sigVerify_64Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean64 kB102
sigVerify_128Kb(message: ByteVector, sig: ByteVector, pub: ByteVector): Boolean128 kB172

Parameters

Parameters
ParameterDescription
message: ByteVectorSigned data. Maximum size: 1) For sigVerify_<N>Kb functions — N bytes. 2) For sigVerify function — 150 bytes.
sig: ByteVectorDigital signature. Fixed size: 25 bytes.
pub: ByteVectorBinary public key. Fixed size: 294 bytes.
PreviousData TypesNextScript Typesarrow

Elsewhere on this site

RIDE on DecentralChainarrowWhat the language guarantees, and why a script is priced before it deploys.SDK packagesarrowThe compiler and the SDKs, published to npm and runnable in a browser.