docs
Search…
Standard Library
Standard Move VM library is default modules that already developed and developers can use in developing new modules, scripts.
They all placed on the address 0x1. So when you import something from 0x1, you import standard modules, like:
1
use 0x1::Account;
2
use 0x1::Event;
3
use 0x1::XFI;
4
use 0x1::Coins;
5
...
Copied!
You can look for actual standard modules in dvm repository.

Time

Time module allows getting current UNIX timestamp of latest block.
Example:
1
script {
2
use 0x1::Time;
3
4
fun main() {
5
let _ = Time::now();
6
}
7
}
Copied!
The method will return u64 value as UNIX timestamp of the latest block.

Block

Block module allows getting current blockchain height.
1
script {
2
use 0x1::Block;
3
4
fun main() {
5
let _ = Block::get_current_block_height();
6
}
7
}
Copied!
The method will return u64 value as the height of the latest block.

Compare

Compare module allows comparing two vectors of u8 values (bytes).
Comparing two-byte vectors:
1
script {
2
use 0x1::Compare;
3
4
fun main() {
5
let a = x"00";
6
let b = x"01";
7
assert(Compare::cmp_lcs_bytes(&a, &b) == 0, 101);
8
}
9
}
Copied!

XFI && Coins

XFI and Coins modules allow to get a type of currency that you going to use in your code.
1
script {
2
use 0x1::Account;
3
use 0x1::XFI;
4
use 0x1::Coins;
5
6
fun main(sender: &signer, payee: address, dfi_amount: u128, eth_amount: u128, btc_amount: u128, usdt_amount: u128) {
7
Account::pay_from_sender<XFI::T>(sender, payee, dfi_amount);
8
Account::pay_from_sender<Coins::ETH>(sender, payee, eth_amount);
9
Account::pay_from_sender<Coins::BTC>(sender, payee, btc_amount);
10
Account::pay_from_sender<Coins::USDT>(sender, payee, usdt_amount);
11
}
12
}
Copied!

Oracle

Coins module also contains oracles functions: get price and has price.
1
script {
2
use 0x1::Coins;
3
4
fun main() {
5
assert(Coins::has_price<Coins::ETH, Coins::USDT>(), 101);
6
7
let _ = Coins::get_price<Coins::ETH, Coins::USDT>();
8
}
9
}
Copied!
More about work with oracles can see in our oracles documentation.

Event

Event module allows us to emit events.
Example with emitting event contains provided number:
1
script {
2
use 0x1::Event;
3
4
fun main(account: &signer, a: u64) {
5
Event::emit<u64>(account, a);
6
}
7
}
Copied!
Or you you can emit event from your module:
1
module MyEvent {
2
use 0x1::Event;
3
4
struct MyStruct {
5
value: u64
6
}
7
8
public fun my_event(account: &signer, a: u64) {
9
Event::emit(account, MyStruct {
10
value: a
11
});
12
}
13
}
Copied!

Signer

Signer module allows to work with the signer type. To get address of signer:
1
script {
2
use 0x1::Signer;
3
4
fun main(sender: &signer) {
5
let _ = Signer::address_of(sender);
6
}
7
}
Copied!
Signer type is required for functions which work with resources, address of signer could be useful in case of resource related functions: borrow_global, borrow_global_mut, exists, move_from.
Read more about the signer type in Move Book.

Account

Account module allows to work with user balances: get balances, deposit coins/tokens to balances, withdraw them to deposit in another module, etc.
Also, it creates an account, if the account doesn't exist yet, and related data, like event handlers for sending/receiving payments.
A lot of different methods can be used to send tokens from account A to account B, as these one-line methods:
1
script {
2
use 0x1::Account;
3
use 0x1::XFI;
4
5
fun main(sender: &signer, payee: address, amount: u128, metadata: vector<u8>) {
6
// Move XFI from sender account to payee.
7
Account::pay_from_sender<XFI::T>(sender, payee, amount);
8
9
// Again move XFI, but with metadata.
10
Account::pay_from_sender_with_metadata<XFI::T>(sender, payee, amount, metadata);
11
}
12
}
Copied!
Also, you can just withdraw from sender balance and deposit to payee:
1
script {
2
use 0x1::Account;
3
use 0x1::XFI;
4
5
fun main(sender: &signer, payee: address, amount: u128) {
6
// Move XFI from sender account to payee.
7
let xfi = Account::withdraw_from_sender<XFI::T>(sender, amount);
8
9
// Again move XFI, but with metadata.
10
Account::deposit(sender, payee, xfi);
11
}
12
}
Copied!
Or deposit to another module:
1
script {
2
use {{address}}::Swap;
3
use 0x1::XFI;
4
use 0x1::Coins;
5
use 0x1::Account;
6
7
fun main(sender: &signer, seller: address, price: u128) {
8
let xfi = Account::withdraw_from_sender(sender, price);
9
10
// Deposit USDT to swap coins.
11
Swap::swap<Coins::USDT, XFI::T>(sender, seller, xfi);
12
}
13
}
Copied!
Also, get a balance:
1
script {
2
use 0x1::Coins;
3
use 0x1::Account;
4
5
fun main(sender: &signer, addr: address) {
6
// My balance.
7
let my_balance = Account::balance<Coins::ETH>(sender);
8
9
// Someone balance.
10
let someone_balance = Account::balance_for<Coins::ETH>(addr);
11
12
assert(my_balance > 0, 101);
13
assert(someone_balance > 0, 102);
14
}
15
}
Copied!
For the rest of the features of Account module look at account.move.

Dfinance

Dfinance module allows you to work with coins balances, get coins info, also register new tokens, etc.
First of all, Dfinance module presents type for all balances in the system, it's Dfinance::T:
1
resource struct T<Coin> {
2
value: u128
3
}
Copied!
The value field contains information about actual balance for specific coin/token, e.g.:
1
script {
2
use 0x1::Account;
3
use 0x1::XFI;
4
5
fun main(sender: &signer, amount: u128) {
6
// Use XFI::T to get Dfinance::T<XFI::T> contains balance.
7
let xfi : 0x1::Dfinance::T<XFI::T> = Account::withdraw_from_sender<XFI::T>(sender, amount);
8
Account::deposit_to_sender(sender, xfi);
9
}
10
}
Copied!
Also, you can create an empty coin:
1
module BankXFI {
2
use 0x1::Dfinance;
3
use 0x1::XFI;
4
5
resource struct T {
6
balance: Dfinance::T<XFI::T>,
7
}
8
9
public fun create(account: &signer) {
10
move_to<T>(account, T {
11
balance: Dfinance::zero<XFI::T>()
12
})
13
}
14
}
Copied!
Get denom, decimals, and actual value:
1
script {
2
use 0x1::Dfinance;
3
use 0x1::Account;
4
use 0x1::XFI;
5
6
fun main(sender: &signer, amount: u128) {
7
let xfi = Account::withdraw_from_sender<XFI::T>(sender, amount);
8
9
// Get denom vector<8>.
10
let _ = Dfinance::denom<XFI::T>();
11
12
// Get value of withdrawed xfi.
13
let value = Dfinance::value(&xfi);
14
15
assert(amount == value, 101);
16
17
Account::deposit_to_sender(sender, xfi);
18
}
19
}
Copied!
And check if it's user token or system coin:
1
script {
2
use {{address}}::MyToken;
3
use 0x1::Dfinance;
4
use 0x1::XFI;
5
6
fun main() {
7
assert(Dfinance::is_token<XFI::T>() == false, 101);
8
assert(Dfinance::is_token<MyToken::T>(), 102);
9
}
10
}
Copied!
Also, you can create your resource and make it token too!
1
module MyToken {
2
use 0x1::Dfinance;
3
4
resource struct Token {
5
}
6
7
public fun create(account: &signer): Dfinance::T<Token> {
8
// Create new token with denom "wow" (hex == 776f77).
9
Dfinance::tokenize<Token>(account, 10, 0, x"776f77")
10
}
11
}
Copied!
And also deposit it to your balance:
1
script {
2
use {{sender}}::MyToken;
3
use 0x1::Account;
4
5
fun main(sender: &signer) {
6
let new_tokens = MyToken::create(sender);
7
Account::deposit_to_sender(sender, new_tokens);
8
}
9
}
Copied!
More documentation about the feature provided by Dfinance module see in dfinance.move.

Vector

Vector module contains functions to work with vector type.
For example:
1
script {
2
use 0x1::Vector;
3
4
fun main() {
5
let v = Vector::empty<u64>();
6
let i = 0;
7
8
loop {
9
if (i == 10) {
10
break
11
};
12
13
Vector::push_back(&mut v, i);
14
i = i + 1;
15
};
16
}
17
}
Copied!
Vector module great describe in Move Book.

Signature

Signature module allows to verify ed25519 signature:
1
script {
2
use 0x1::Signature;
3
4
fun main(signature: vector<u8>, pub_key: vector<u8>, message: vector<u8>) {
5
let is_verified = Signature::ed25519_verify(signature, pub_key, message);
6
assert(is_verified, 101);
7
}
8
}
Copied!
Last modified 1yr ago