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

Name

Description

Complexity

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

Gets an array of bytes by key

\(10\)

getBinary(String): ByteVector|Unit

Gets an array of bytes by key from dApp’s own data storage

\(10\)

getBinaryValue(Address|Alias, String): ByteVector

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

\(10\)

getBinaryValue(String): ByteVector

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

Gets a boolean value by key

\(10\)

getBoolean(String): Boolean|Unit

Gets a boolean value by key from dApp’s own data storage

\(10\)

getBooleanValue(Address|Alias, String): Boolean

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

\(10\)

getBooleanValue(String): Boolean

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

Gets an integer by key

\(10\)

getInteger(String): Int|Unit

Gets an integer by key from dApp’s own data storage

\(10\)

getIntegerValue(Address|Alias, String): Int

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

\(10\)

getIntegerValue(String): Int

Gets an integer by key from dApp’s own data storage. Fails if there is no data

\(10\)

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

Gets a string by key

\(10\)

getString(String): String|Unit

Gets a string by key from dApp’s own data storage

\(10\)

getStringValue(Address|Alias, String): String

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

\(10\)

getStringValue(String): String

Gets a string by key from dApp’s own data storage. Fails if there is no data

\(10\)

isDataStorageUntouched(Address|Alias): Boolean

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.

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

Parameters

Parameters#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

key: String

Entry 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#

Parameter

Description

key: String

Entry 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#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

key: String

Entry key.

getBinaryValue(String): ByteVector#

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

getBinaryValue(key: String): ByteVector

Parameters

Parameters#

Parameter

Description

key: String

Entry key.

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

Gets a boolean value by key.

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

Parameters

Parameters#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

key: String

Entry 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#

Parameter

Description

key: String

Entry 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#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

key: String

Entry key.

getBooleanValue(String): Boolean#

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

getBooleanValue(key: String): Boolean

Parameters

Parameters#

Parameter

Description

key: String

Entry key.

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

Gets an integer by key.

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

Parameters

Parameters#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

key: String

Entry key.

getInteger(String): Int|Unit#

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

getInteger(key: String): Int|Unit

Parameters

Parameters#

Parameter

Description

key: String

Entry 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#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

key: String

Entry key.

getIntegerValue(String): Int#

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

getIntegerValue(key: String): Int

Parameters

Parameters#

Parameter

Description

key: String

Entry key.

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

Gets a string by key.

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

Parameters

Parameters#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

key: String

Entry key.

getString(String): String|Unit#

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

getString(key: String): String|Unit

Parameters

Parameters#

Parameter

Description

key: String

Entry 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#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

key: String

Entry key.

getStringValue(String): String#

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

getString(key: String): String

Parameters

Parameters#

Parameter

Description

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

isDataStorageUntouched(addressOrAlias: Address|Alias): Boolean

Parameters

Parameters#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

Example

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

Blockchain Functions#

Blockchain Functions#

Name

Description

Complexity

addressFromRecipient(Address|Alias): Address

Gets the corresponding address of the alias

\(5\)

assetBalance(Address|Alias, ByteVector): Int

Gets account balance by token ID

\(10\)

assetInfo(ByteVector): Asset|Unit

Gets the information about a token

\(15\)

blockInfoByHeight(Int): BlockInfo|Unit

Gets the information about a block by the block height

\(5\)

calculateAssetId(Issue): ByteVector

Calculates ID of the token formed by the Issue structure when executing the callable function

\(10\)

calculateLeaseId(Lease): ByteVector

Calculates ID of the lease formed by the Lease structure when executing the callable function

\(1\)

scriptHash(Address|Alias): ByteVector|Unit

Returns BLAKE2b-256 hash of the script assigned to a given account

\(200\)

transactionHeightById(ByteVector): Int|Unit

Gets the block height of a transaction

\(20\)

transferTransactionById(ByteVector): TransferTransaction|Unit

Gets the data of a transfer transaction

\(60\)

decentralchainBalance(Address|Alias): BalanceDetails

Gets account balance in DecentralCoins

\(10\)

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#

Parameter

Description

addressOrAlias: Address | Alias

address 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#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

assetId: ByteVector

token 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#

Parameter

Description

id: ByteVector

token 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#

Parameter

Description

height: Int

block 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#

Parameter

Description

issue: Issue

Structure 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#

Parameter

Description

lease: Lease

Structure 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#

Parameter

Description

addressOrAlias: Address | Alias

address 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#

Parameter

Description

id: ByteVector

ID 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#

Parameter

Description

id: ByteVector

ID 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#

Parameter

Description

addressOrAlias: Address | Alias

address or alias of the account.

Byte Array Functions#

Byte Array Functions#

Name

Description

Complexity

drop(ByteVector, Int): ByteVector

Returns the byte array without the first N bytes

\(6\)

dropRight(ByteVector, Int): ByteVector

Returns the byte array without the last N bytes

\(6\)

size(ByteVector): Int

Returns the number of bytes in the byte array

\(1\)

take(ByteVector, Int): ByteVector

Returns the first N bytes of the byte array

\(6\)

takeRight(ByteVector, Int): ByteVector

Returns the last N bytes of the byte array

\(6\)

drop(ByteVector, Int): ByteVector#

Returns the byte array without the first N bytes.

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

Parameters

Parameters#

Parameter

Description

xs: ByteVector

Byte array.

number: Int

N 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#

Parameter

Description

xs: ByteVector

Byte array.

number: Int

N 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#

Parameter

Description

xs: ByteVector

Byte 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#

Parameter

Description

xs: ByteVector

Byte array.

number: Int

N 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#

Parameter

Description

xs: ByteVector

Byte array.

number: Int

N bytes.

Example

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

Converting Functions#

Converting Functions#

Name

Description

Complexity

addressFromPublicKey(ByteVector): Address

Gets the corresponding address of the account public key `

\(63\)

parseBigInt(String): BigInt|Unit

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

\(65\)

parseBigIntValue(String): BigInt

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

\(65\)

parseInt(String): Int|Unit

Converts the string representation of a number to its integer equivalent

\(2\)

parseIntValue(String): Int

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

\(2\)

toBigInt(ByteVector): BigInt

Converts an array of bytes to a big integer

\(65\)

toBigInt(ByteVector, Int, Int): BigInt

Converts an array of bytes starting from a certain index to a big integer

\(65\)

toBigInt(Int): BigInt

Converts an integer to a big integer

\(1\)

toBytes(Boolean): ByteVector

Converts a boolean to an array of bytes

\(1\)

toBytes(Int): ByteVector

Converts an integer to an array of bytes

\(1\)

toBytes(String): ByteVector

Converts a string to an array of bytes

\(8\)

toBytes(BigInt): ByteVector

Converts a big integer to an array of bytes

\(65\)

toInt(BigInt): Int

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

\(1\)

toInt(ByteVector): Int

Converts an array of bytes to an integer

\(1\)

toInt(ByteVector, Int): Int

Converts an array of bytes to an integer starting from a certain index

\(1\)

toString(Address): String

Converts an address to a string

\(10\)

toString(Boolean): String

Converts a boolean to a string

\(1\)

toString(Int): String

Converts an integer to a string

\(1\)

toString(BigInt): String

Converts a big integer to a string

\(65\)

toUtf8String(ByteVector): String

Converts an array of bytes to a UTF-8 string

\(7\)

transferTransactionFromProto(ByteVector): TransferTransaction|Unit

Deserializes transfer transaction

\(5\)

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#

Parameter

Description

publicKey: ByteVector

Public 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#

Parameter

Description

str: String

String 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#

Parameter

Description

str: String

String to parse.

parseInt(String): Int|Unit#

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

parseInt(str: String): Int|Unit

Parameters

Parameters#

Parameter

Description

str: String

String 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#

Parameter

Description

str: String

String 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#

Parameter

Description

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

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

Parameters

Parameters#

Parameter

Description

bin: ByteVector

Array of bytes to convert.

offset: Int

Index to start from.

size: Int

Number of bytes (subarray length) to convert.

toBigInt(Int): BigInt#

Converts an integer to a big integer.

toBigInt(n: Int): BigInt

Parameters

Parameters#

Parameter

Description

n: Int

Integer to convert.

toBytes(Boolean): ByteVector#

Converts a boolean value to an array of bytes.

toBytes(b: Boolean): ByteVector

Parameters

Parameters#

Parameter

Description

b: Boolean

Boolean 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#

Parameter

Description

n: Int

Integer 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#

Parameter

Description

str: String

String 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#

Parameter

Description

n: BigInt

Big 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#

Parameter

Description

n: BigInt

Big 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#

Parameter

Description

bin: ByteVector

Array 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#

Parameter

Description

bin: ByteVector

Array of bytes to convert.

offset: Int

Index 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#

Parameter

Description

addr: Address

Address 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#

Parameter

Description

b: Boolean

Boolean 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#

Parameter

Description

n: Int

Integer to convert.

Example

toString(10) # Returns "10"

toString(BigInt): String#

Converts a big integer to a string.

toString(n: BigInt): String

Parameters

Parameters#

Parameter

Description

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

toUtf8String(u: ByteVector): String

Parameters

Parameters#

Parameter

Description

u: ByteVector

Array 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#

Parameter

Description

b: ByteVector

Transfer 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#

Name

Description

Complexity

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

Invokes a dApp callable function, with reentrancy restriction

\(75\)

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

Invokes a dApp callable function, without reentrancy restriction

\(75\)

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#

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\).

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#

Name

Description

Complexity

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

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

\(10\)

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

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

\(4\)

getBinaryValue(List[], String): ByteVector

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

\(10\)

getBinaryValue(List[], Int): ByteVector

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

\(4\)

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

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

\(10\)

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

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

\(4\)

getBooleanValue(List[], String): Boolean

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

\(10\)

getBooleanValue(List[], Int): Boolean

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

\(4\)

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

Gets an integer value from a list of data entires by key

\(10\)

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

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

\(4\)

getIntegerValue(List[], String): Int

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

\(10\)

getIntegerValue(List[], Int): 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

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

\(10\)

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

Gets a string value from a list of data entires by index

\(4\)

getStringValue(List[], String): String

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

\(10\)

getStringValue(List[], Int): String

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.

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

Parameters

Parameters#

Parameter

Description

data: List []

List of data entries, usually tx.data.

key: String

Key.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

index: Int

Index.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

key: String

Key.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

index: Int

Index.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

key: String

Key.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

index: Int

Index.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

key: String

Key.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

index: Int

Index.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

key: String

Key.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

index: Int

Index.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

key: String

Key.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

index: Int

Index.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

key: String

Key.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

index: Int

Index.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

key: String

Key.

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#

Parameter

Description

data: List []

List of data entries, usually tx.data.

index: Int

Index.

Decoding Functions#

Decoding Functions#

Name

Description

Complexity

addressFromString(String): Address|Unit

Decodes address from base58 string

\(1\)

addressFromStringValue(String): Address

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

\(1\)

fromBase16String(String): ByteVector

Decodes base16 string to an array of bytes

\(10\)

fromBase58String(String): ByteVector

Decodes base58 string to an array of bytes

\(1\)

fromBase64String(String): ByteVector

Decodes base64 string to an array of bytes

\(40\)

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#

Parameter

Description

string: string

String 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#

Parameter

Description

string: string

String 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#

Parameter

Description

string: string

String 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#

Parameter

Description

string: string

String 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#

Parameter

Description

string: string

String to decode.

Example

let bytes = fromBase64String("UmlkZQ==")

Encoding Functions#

Encoding Functions#

Name

Description

Complexity

toBase16String(ByteVector): String

Encodes array of bytes to base16 string

\(10\)

toBase58String(ByteVector): String

Encodes array of bytes to base58 string

\(3\)

toBase64String(ByteVector): String

Encodes array of bytes to base64 string

\(35\)

toBase16String(ByteVector): String#

Encodes an array of bytes to a base16 string.

toBase16String(bytes: ByteVector): String

Parameters

Parameters#

Parameter

Description

bytes: ByteVector

Array 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#

Parameter

Description

bytes: ByteVector

Array 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#

Parameter

Description

bytes: ByteVector

Array of bytes to encode.

Example

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

Exception Functions#

Exception Functions#

Name

Description

Complexity

throw()

Raises an exception

\(1\)

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

throw()#

Raises an exception.

throw(String)#

Raises an exception with a message.

throw(err: String)

Parameters

Parameters#

Parameter

Description

err: String

The exception message.

Hashing Functions#

Hashing Functions#

Name

Description

Complexity

blake2b256(ByteVector): ByteVector

Range of functions. Hash an array of bytes using BLAKE2b-256

\(10–200\)

keccak256(ByteVector): ByteVector

Range of functions. Hash an array of bytes using Keccak-256

\(10–200\)

sha256(ByteVector): 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

The 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#

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

The 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#

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

The 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#

Name

Description

Complexity

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

Inserts element to the beginning of the list

\(1\)

containsElement(List[T], T): Boolean

Check if the element is in the list

\(5\)

getElement(List[T], Int): T

Gets element from the list

\(2\)

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

Returns the index of the first occurrence of the element in the list

\(5\)

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

Returns the index of the last occurrence of the element in the list

\(5\)

max(List[Int]): Int

Returns the largest element in the list of integers

\(3\)

max(List[BigInt]): BigInt

Returns the largest element in the list of big integers

\(192\)

min(List[Int]): Int

Returns the smallest element in the list of integers

\(3\)

min(List[BigInt]): BigInt

Returns the smallest element in the list of big integers

\(192\)

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

Removes an element from the list by index

\(7\)

size(List[T]): Int

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.

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

Parameters

Parameters#

Parameter

Description

head: T

Element

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#

Parameter

Description

list: List [T]

List

element: T

Element 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#

Parameter

Description

arr: List [T]

List

pos: Int

Index 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#

Parameter

Description

list: List [T]

List

element: T

Element 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#

Parameter

Description

list: List [T]

List

element: T

Element 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#

Parameter

Description

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#

Parameter

Description

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#

Parameter

Description

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#

Parameter

Description

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#

Parameter

Description

list: List [T]

List

index: T

Index 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#

Parameter

Description

arr: List [T]

List

Example

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

Math Functions#

Math Functions#

Name

Description

Complexity

fraction(Int, Int, Int): Int

Multiplies and divides integers to avoid overflow

\(14\)

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

Multiplies and divides integers to avoid overflow, applying the specified rounding method

\(17\)

fraction(BigInt, BigInt, BigInt): BigInt

Multiplies and divides bid integers to avoid overflow

\(128\)

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

Multiplies and divides big integers to avoid overflow, applying the specified rounding method

\(128\)

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

Calculates logarithm of a number with a base

\(100\)

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

Calculates logarithm of a number to a given base with high accuracy

\(200\)

median(List[Int]): Int

Returns the median of a list of integers

\(20\)

median(List[BigInt]): BigInt

Returns the median of a list of big integers

\(160\)

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

Raises a number to a given power

\(100\)

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

Raises a number to a given power with high accuracy

\(200\)

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#

Parameter

Description

a: Int

Integer a

b: Int

Integer b

c: 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 * 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#

Parameter

Description

a: Int

Integer a

b: Int

Integer b

c: Int

Integer c

round: DOWN|CEILING|FLOOR|HALFUP|HALFEVEN

One 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#

Parameter

Description

a: BigInt

Big integer a

b: BigInt

Big integer b

c: BigInt

Big 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#

Parameter

Description

a: BigInt

Big integer a

b: BigInt

Big integer b

c: 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\).

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#

Parameter

Description

value: Int

Number a without decimal point.

vp: Int

Number of decimals of a.

base: Int

Logarithm base b without decimal point.

bp: Int

Number of decimals of b.

rp: 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...\)

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#

Parameter

Description

value: BigInt

Number a without decimal point.

vp: Int

Number of decimals of a.

base: BigInt

Logarithm base b without decimal point.

bp: Int

Number of decimals of b.

rp: 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 of integers. Fails if the list is empty.

median(arr: List[Int]): Int

Parameters

Parameters#

Parameter

Description

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#

Parameter

Description

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#

Parameter

Description

base: Int

Logarithm base b without decimal point.

bp: Int

Number of decimals of a.

exponent: Int

Exponent b without decimal point.

ep: Int

Number of decimals of b.

rp: 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...\)

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#

Parameter

Description

base: BigInt

Logarithm base b without decimal point.

bp: Int

Number of decimals of a.

exponent: BigInt

Exponent b without decimal point.

ep: Int

Number of decimals of b.

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

Checks whether the string contains substring

\(3\)

drop(String, Int): String

Drops the first n characters of a string

\(20\)

dropRight(String, Int): String

Drops the last n characters of a string

\(20\)

indexOf(String, String): Int|Unit

Returns the index of the first occurrence of a substring

\(3\)

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

Returns the index of the first occurrence of a substring after a certain index

\(3\)

lastIndexOf(String, String): Int|Unit

Returns the index of the last occurrence of a substring

\(3\)

lastindexOf(String, String, Int): Int|Unit

Returns the index of the last occurrence of a substring before a certain index

\(3\)

makeString(List[String], String): String

Concatenates list strings adding a separator

\(30\)

size(String): Int

Returns the size of a string

\(1\)

split(String, String): List[String]

Splits a string delimited by a separator into a list of substrings.

\(75\)

take(String, Int): String

Takes the first n characters from a string

\(20\)

takeRight(String, Int): String

Takes the last n characters from a string

\(20\)

contains(String, String): Boolean#

Checks whether the string contains substring.

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

Parameters

Parameters#

Parameter

Description

haystack: String

String to search in.

needle: String

String 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#

Parameter

Description

xs: String

The string.

number: Int

The 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#

Parameter

Description

xs: String

The string.

number: Int

The 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#

Parameter

Description

str: String

The string.

substr: String

The 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#

Parameter

Description

str: String

The string.

substr: String

The substring.

offset: Int

The 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#

Parameter

Description

str: String

The string.

substr: String

The 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#

Parameter

Description

str: String

The string.

substr: String

The substring.

offset: Int

The 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#

Parameter

Description

arr: List [String]

List of strings to concatenate.

separator: String

Separator.

Example

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

size(String): Int#

Returns the size of a string.

size(xs: String): Int

Parameters

Parameters#

Parameter

Description

xs: String

The 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#

Parameter

Description

str: String

The string.

separator: String

The 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#

Parameter

Description

xs: String

The string.

number: Int

The 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#

Parameter

Description

xs: String

The string.

number: Int

The 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#

Name

Description

Complexity

isDefined(T|Unit): Boolean

Checks if an argument is not unit

\(1\)

value(T|Unit): T

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

\(2\)

valueOrElse(T|Unit, T): 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

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.

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 type argument. Fails if it is unit.

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 type argument if it’s not unit. Otherwise, returns the second argument.

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

Parameter

Description

a: T|Unit

Argument to return value from.

msg: String

Error message.

Verification Functions#

Verification Functions#

Name

Description

Complexity

bn256groth16Verify(ByteVector, ByteVector, ByteVector): Boolean

Range of functions. Check zk-SNARK by groth16 protocol on the bn254 curve

\(800–1650\)

createMerkleRoot(List[ByteVector], ByteVector, Int) : ByteVector

Calculates the Merkle root hash for transactions of block

\(30\)

ecrecover(messageHash: ByteVector, signature: ByteVector)

Recovers public key from the message hash and the ECDSA digital signature

\(70\)

groth16Verify(ByteVector, ByteVector, ByteVector): Boolean

Range of functions. Check zk-SNARK by groth16 protocol on the bls12-381 curve

\(1200–2700\)

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

\(500–1000\)

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

\(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

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

Zero-knowledge proof. Fixed size: \(128\) bytes.

inputs: ByteVector

Zero-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#

Parameter

Description

merkleProofs: List [ByteVector]

Array of sibling hashes of the Merkle tree. Up to \(16\) items, \(32\) bytes each.

valueBytes: ByteVector

Hash of transaction. Fixed size: \(32\) bytes. You can use blake2b256 function. The transaction must be hashed together with the signature.

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

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

Parameters

Parameters#

Parameter

Description

messageHash: ByteVector

Keccak-256 hash of the message. Fixed size: \(32\).

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

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

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

Zero-knowledge proof. Fixed size: \(192\) bytes.

inputs: ByteVector

Zero-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#

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

Signed data. Maximum size: 1) For rsaVerify_<N>Kb functions — \(N\) bytes. 2) For rsaVerify function — \(150\) bytes.

sig: ByteVector

Digital signature. Fixed size: \(25\) bytes.

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

Signed data. Maximum size: 1) For sigVerify_<N>Kb functions — \(N\) bytes. 2) For sigVerify function — \(150\) bytes.

sig: ByteVector

Digital signature. Fixed size: \(25\) bytes.

pub: ByteVector

Binary public key. Fixed size: \(294\) bytes.