# [Ride v5] Blockchain functions
⚠️ This is the documentation for the Standard library version 5. We recommend to use version 6. Go to version 6
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 |
wavesBalance(Address|Alias): BalanceDetails | Gets account balance in WAVES | 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 article.
# Parameters
Parameter | Description |
---|---|
AddressOrAlias: Address|Alias | |
Address or alias, usually tx.recipient |
# Examples
let address =Address(base58'3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF')
addressFromRecipient(address)
# assetBalance
Gets account balance by token ID.
The balance takes into account payments attached to the script invocation. Transfers (ScriptTransfer
) made by the current callable function do not affect the balance (however, nested invocations do).
assetBalance(addressOrAlias: Address|Alias, assetId: ByteVector): Int
# Parameters
Parameter | Description |
---|---|
addressOrAlias: Address|Alias | Address or alias of the account |
assetId: ByteVector | Token ID |
# assetInfo
Gets the information about a token.
assetInfo(id: ByteVector): Asset|Unit
For a description of the return value, see the Asset article.
# Parameters
Parameter | Description |
---|---|
id : ByteVector | ID of the token |
# Example
let bitcoinId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
let x = match assetInfo(bitcoinId) {
case asset:Asset =>
asset.decimals # 8
case _ => throw("Can't find asset")
}
# blockInfoByHeight
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 article.
# 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
Calculates ID of the token formed by the Issue structure when executing the callable function.
calculateAssetId(issue: Issue): ByteVector
# 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
Calculates ID of the lease formed by the Lease structure when executing the callable function.
calculateLeaseId(lease: Lease): ByteVector
# 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
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
Parameter | Description |
---|---|
addressOrAlias : Address|Alias | Address or alias of the account |
# Example
let addr = Address(base58'3MxBZbnN8Z8sbYjjL5N3oG5C8nWq9NMeCEm')
scriptHash(addr) # Returns base58'G6ihnWN5mMedauCgNa8TDrSKWACPJKGQyYagmMQhPuja'
# transactionHeightById
Gets the block height of a transaction. Returns unit
for failed transactions (see the Transaction Validation article) and transactions elided due to challenging a block (see the section Waves 1.5: Light Node).
transactionHeightById(id: ByteVector): Int|Unit
# 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
Gets the data of a Transfer transaction. Returns unit
for transactions elided due to challenging a block (see the section Waves 1.5: Light Node).
transferTransactionById(id: ByteVector): TransferTransaction|Unit
For a description of the return value, see the TransferTransaction article.
# 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")
}
# wavesBalance
Gets all types of WAVES balances. For description of balance types, see the Account Balance article.
The balances take into account payments attached to the script invocation. Transfers (ScriptTransfer
) made by the current callable function do not affect the balances (however, nested invocations do).
wavesBalance(addressOrAlias: Address|Alias): BalanceDetails
For a description of the return value, see the BalanceDetails article.
# Parameters
Parameter | Description |
---|---|
addressOrAlias: Address|Alias | Address or alias of the account |