Skip to content

Libraries

A library is imported at the top of a contract, token, script or description body with import Name;. The tables list the libraries and methods that compile with pha-tomb and run on the current chain. A compiler library whose calls the validator rejects is not listed; nativecheck:error reports such calls at compile time.

Account

MethodReturn typeDescription
Account.getName(from:Address)StringReturns the name registered for the address, or an empty string.

The other methods of the compiler’s Account library (name registration, account scripts, migration) call the account native contract, which the current chain does not serve.

Address

MethodReturn typeDescription
Address.isNull(target:Address)BoolReturns true if the address is the null address.
Address.isUser(target:Address)BoolReturns true if the address is a user address.
Address.isSystem(target:Address)BoolReturns true if the address is a system address.
Address.isInterop(target:Address)BoolReturns true if the address is an interop address.

Array

Arrays can also be used directly through TOMB array variables.

MethodReturn typeDescription
Array.get(array:Any, index:Number)Generic<0>Returns the element at the index.
Array.set(array:Any, index:Number, value:Generic<0>)NoneSets the element at the index.
Array.remove(array:Any, index:Number)NoneRemoves the element at the index.
Array.clear(array:Any)NoneRemoves every element.
Array.length(array:Any)NumberReturns the number of elements.
Array.push(array:Any, value:Generic<0>)NoneAppends an element.
Array.pop(array:Any)Generic<0>Removes and returns the last element.

Call

MethodReturn typeDescription
Call.interop(name:String, …:Generic)TCalls a VM interop by name, for example Call.interop<number>("Map.Get", "OTHER", "_field", key, $TYPE_OF(number)). The interop reference lists the names the validator implements.
Call.contract(contract:String, method:String, …:Generic)TCalls a method of a deployed contract, or of the gas and stake native contracts.
Call.method(method:Method, …:Generic)TCalls a method of the current contract by name.

The type parameter names the return type; use none for a method that returns nothing.

Decimal

MethodReturn typeDescription
Decimal.decimals(target:Any)NumberReturns the number of decimal places of a decimal<N> value.
Decimal.convert(decimalPlaces:Number, value:Number)NumberConverts a value to the given number of decimal places.

Enum

MethodReturn typeDescription
Enum.isSet(target:Enum<>, flag:Enum<>)BoolReturns true if the flag is set in the value.

Format

Available inside description modules only, which render event text for wallets and explorers.

MethodReturn typeDescription
Format.decimals(value:Number, symbol:String)StringRenders an amount with the decimals of the token.
Format.symbol(symbol:String)StringRenders a token symbol.
Format.account(address:Address)StringRenders an address, with its name when one is registered.

List

Lists are declared as storage_list<T> globals; the methods are called on the variable.

MethodReturn typeDescription
List.get(index:Number)GenericReturns the element at the index.
List.add(value:Generic)NoneAppends an element.
List.replace(index:Number, value:Generic)NoneReplaces the element at the index.
List.removeAt(index:Number)NoneRemoves the element at the index. The last element takes its place.
List.count()NumberReturns the number of elements.
List.clear()NoneRemoves every element.

Map

Maps are declared as storage_map<K, V> globals; the methods are called on the variable.

MethodReturn typeDescription
Map.get(key:Generic)GenericReturns the value stored under the key, or the default of the value type.
Map.set(key:Generic, value:Generic)NoneStores a value under the key.
Map.remove(key:Generic)NoneRemoves the key.
Map.clear()NoneRemoves every entry.
Map.count()NumberReturns the number of entries.
Map.has(key:Generic)BoolReturns true if the key exists.

Math

MethodReturn typeDescription
Math.min(a:Number, b:Number)NumberReturns the smaller number.
Math.max(a:Number, b:Number)NumberReturns the larger number.
Math.abs(a:Number)NumberReturns the absolute value.
Math.pow(a:Number, b:Number)NumberReturns a raised to the power b.
Math.sqrt(x:Number)NumberReturns the integer square root.

Module

MethodReturn typeDescription
Module.getScript(target:Module)BytesReturns the compiled script of a module declared in the same file.
Module.getABI(target:Module)BytesReturns the serialized ABI of a module declared in the same file.

NFT

MethodReturn typeDescription
NFT.transfer(from:Address, to:Address, symbol:String, id:Number)NoneTransfers one NFT by its Phantasma NFT id.
NFT.mint(from:Address, to:Address, symbol:String, rom:Any, ram:Any, seriesID:Number)NoneMints an NFT with the given ROM and RAM into a series.
NFT.write(from:Address, symbol:String, tokenID:Number, ram:Any)NoneReplaces the RAM of an NFT (Runtime.WriteToken). Runs onWrite when the token contract defines it; without onWrite, the token owner must sign or the token’s own contract must call.
NFT.burn(from:Address, symbol:String, id:Number)NoneBurns an NFT.
NFT.infuse(from:Address, symbol:String, id:Number, infuseSymbol:String, infuseValue:Number)NoneMoves a fungible amount or one NFT into the NFT.
NFT.getInfusions(symbol:String, id:Number)AnyReturns what the NFT holds.
NFT.getOwnerships(address:Address, symbol:String)AnyReturns the NFT ids of the token the address owns.
NFT.getOwnershipsBySeries(address:Address, symbol:String, seriesID:Number)AnyThe same, limited to one series.
NFT.read(symbol:String, id:Number)AnyReturns the NFT fields (Runtime.ReadToken).
NFT.readROM(symbol:String, id:Number)TReturns the ROM of an NFT as the struct type T.
NFT.readRAM(symbol:String, id:Number)TReturns the RAM of an NFT as the struct type T.
NFT.createSeries(from:Address, symbol:String, seriesID:Number, maxSupply:Number, mode:Enum, nft:Module)NoneCreates a series of the token from an nft submodule.

Runtime

MethodReturn typeDescription
Runtime.expect(condition:Bool, error:String)NoneAborts execution with the error text when the condition is false.
Runtime.log(message:String)NoneWrites a log line.
Runtime.isWitness(address:Address)BoolReturns true if the address signed the transaction.
Runtime.isTrigger()BoolReturns true inside a trigger.
Runtime.context()StringReturns the name of the executing context.
Runtime.previousContext()StringReturns the name of the calling context.
Runtime.gasTarget()AddressReturns the gas target address of the transaction.
Runtime.version()NumberReturns the VM behavior version.
Runtime.deployContract(from:Address, contract:Module)NoneDeploys a standalone contract from a module declared in the same file.
Runtime.upgradeContract(from:Address, contract:Module)NoneUpgrades a deployed contract.

Stake

MethodReturn typeDescription
Stake.stake(from:Address, stakeAmount:Number)NoneStakes SOUL for the address.
Stake.unstake(from:Address, unstakeAmount:Number)NoneUnstakes SOUL.
Stake.claim(from:Address, stakeAddress:Address)NoneClaims the KCAL generated by a stake.
Stake.getUnclaimed(from:Address)NumberReturns the KCAL the address can claim.

Warning

Stake.stake($THIS_ADDRESS, amount) does not increase contract storage. Storage growth is paid by the transaction through SOUL data escrow and maxData. See Storage And Data Escrow.

The master, voting-power and conversion methods of the compiler’s Stake library are not served by the current stake contract.

Storage

MethodReturn typeDescription
Storage.read(contract:String, field:String)GenericReads a field of a contract (Data.Get).
Storage.write(field:String, value:Any)NoneWrites a field of the current contract (Data.Set).
Storage.delete(field:String)NoneDeletes a field of the current contract (Data.Delete).

Writes go to the current contract only. Storage growth is charged through the transaction’s SOUL data escrow; see Storage And Data Escrow. The file storage methods of the compiler’s Storage library call the storage native contract, which the current chain does not serve.

String

MethodReturn typeDescription
String.length(target:String)NumberReturns the number of characters.
String.substr(target:String, index:Number, length:Number)StringReturns a substring.
String.toArray(target:String)ArrayReturns the characters as an array of numbers.
String.fromArray(target:Array)StringBuilds a string from an array of character codes.
String.toUpper(target:String)StringReturns the upper-case form.
String.toLower(target:String)StringReturns the lower-case form.

Time

MethodReturn typeDescription
Time.now()TimestampReturns the block time.
Time.unix(value:Number)TimestampBuilds a timestamp from a Unix time in seconds.

Token

MethodReturn typeDescription
Token.create(from:Address, script:Bytes, abi:Bytes)NoneCreates a token-backed contract; the symbol, name, flags, supply and decimals come from the token module’s properties.
Token.exists(symbol:String)BoolReturns true if the token exists.
Token.getDecimals(symbol:String)NumberReturns the decimals of the token; zero for an NFT.
Token.getFlags(symbol:String)EnumReturns the TokenFlags of the token.
Token.getOwner(symbol:String)AddressReturns the owner address of the token.
Token.transfer(from:Address, to:Address, symbol:String, amount:Number)NoneTransfers an amount of a fungible token.
Token.transferAll(from:Address, to:Address, symbol:String)NoneTransfers the whole balance of a fungible token.
Token.mint(from:Address, to:Address, symbol:String, amount:Number)NoneMints an amount of a fungible token.
Token.write(from:Address, symbol:String, tokenID:Number, ram:Any)NoneReplaces the RAM of an NFT (Runtime.WriteToken).
Token.burn(from:Address, symbol:String, amount:Number)NoneBurns an amount of a fungible token.
Token.getBalance(from:Address, symbol:String)NumberReturns the balance of the address.

UID

MethodReturn typeDescription
UID.generate()NumberReturns an identifier that is unique within the transaction.