# 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 an asset ID | 10 |
| assetInfo(ByteVector): Asset|Unit | Gets asset parameters by its ID | 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 |
| calculateDelay(ByteVector, Int, Address, Int): Int | Calculates the time delay before generating a block | 1 |
| 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 an asset 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).
To get the WAVES balance, use the wavesBalance function.
assetBalance(addressOrAlias: Address|Alias, assetId: ByteVector): Int
# Parameters
| Parameter | Description |
|---|---|
| addressOrAlias: Address|Alias | Address or alias of the account |
| assetId: ByteVector | Token ID |
# Example
let address = Address(base58'3PJaDyprvekvPXPuAtxrapacuDJopgJRaU3')
let bitcoinId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
assetBalance(address, bitcoinId) # Returns Bitcoin balance
# assetInfo
Gets asset parameters by its ID.
The function does not provide parameters of WAVES.
assetInfo(id: ByteVector): Asset|Unit
For a description of the return value, see the Asset article.
# 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
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 8 #-}
{-# 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
)
}
# calculateDelay
Calculates the time delay in milliseconds before block generation, according to the Fair PoS formula (with Tmin = 0).
⚠️ The functions is added in Standard library version 8.
func calculateDelay(generator: Address, balance: Int): Int
# Parameters
| Parameter | Description |
|---|---|
generator: Address | Address whose bytes in addition to the current block's VRF are used to get the hit to be inserted into the formula |
balance: Int | Generating balance in WAVELET to be inserted into the formula |
# Example
calculateDelay(i.caller, i.caller.wavesBalance().generating)
# 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 8 #-}
{-# 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 |