Standard Library
The Diem standard Move VM library contains default modules that are already developed and developers can use in their modules and scripts. This is one of the core mechanisms that the Pontem Network uses to maintain compatibility with the Diem Blockchain.
Modules are all in the address 0x1. So when you import something from 0x1, you can import standard modules, in the following way:
1
use 0x1::DiemAccount;
2
use 0x1::Event;
3
use 0x1::PONT::PONT;
4
use 0x1::Diem::{Self, Diem};
5
...
Copied!
You can see all the standard modules in the move-stdlib repository. Below are some explanations and examples of the ones you will most commonly use.

DiemTimestamp

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

DiemBlock

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

PONT

PONT module allows you to get a PONT type of currency that you are going to use in your code.
1
script {
2
use 0x1::PONT::PONT;
3
use 0x01::DiemAccount;
4
5
fun transfer(sender: signer, payee: address, amount: u64) {
6
// Withdraw tokens from sender account.
7
let pont_tokens = DiemAccount::pnt_withdraw<PONT>(&sender, amount);
8
9
// Transfer PONT tokens to payee balance.
10
DiemAccount::pnt_deposit<PONT>(payee, pont_tokens);
11
}
12
}
Copied!

Event

Event module allows us to emit events.
Example with emitting events containing a provided number:
1
script {
2
use 0x1::Signer;
3
use 0x01::Event;
4
5
fun sum(account: signer) {
6
let addr = Signer::address_of(&account);
7
8
// Create event emitter.
9
let event_handle = Event::new_event_handle(&account);
10
11
// Emit event.
12
Event::emit_event(
13
&mut event_handle,
14
addr
15
);
16
17
// Destroy event emitter.
18
Event::destroy_handle(event_handle);
19
}
20
}
Copied!
Or you can emit events from your module by creating a one time event handler:
1
address {{sender}} {
2
module MyEvent {
3
use 0x1::Signer;
4
use 0x1::Event;
5
6
struct MyStruct has key {
7
value: u64,
8
event_handle: Event::EventHandle<u64>,
9
}
10
11
public fun initialize(account: &signer, value: u64) {
12
let event_handle = Event::new_event_handle(account);
13
14
move_to<MyStruct>(account, MyStruct {
15
value,
16
event_handle,
17
});
18
}
19
20
public fun emit(account: &signer) acquires MyStruct {
21
let my_struct = borrow_global_mut<MyStruct>(Signer::address_of(account));
22
Event::emit_event(
23
&mut my_struct.event_handle,
24
my_struct.value,
25
);
26
}
27
}
28
}
Copied!

Signer

Signer module allows you to work with the signer type. A signer allows the holder to act on behalf of an address. Similar to a Unix UID, it represents a user authenticated outside of Move (i.e by checking a cryptographic signature or password). To get the address of the signer:
1
script {
2
use 0x1::Signer;
3
4
fun address_of_signer(sender: signer) {
5
let _ = Signer::address_of(sender);
6
}
7
}
Copied!
the 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, move_to, freeze.
Read more about the signer type in Diem's Signer documentation.

DiemAccount

DiemAccount module allows you to work with user balances: get balances, deposit coins/tokens to balances, withdraw them to deposit in another module, etc.
Also, it creates a VASP account -if the account doesn't exist yet- and also allows you to create 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.
In case you you don't want to a create VASP account, you can still use functions introduced by Pontem:
🧙‍♂️ Functions with pnt_ prefix are not compatible with Diem, so your code won't be fully compatible with Diem if you use these functions since there's no other way to work with Diem balances directly (store it in modules, etc). Once Diem allows us to work with balances we will migrate and release migration documentation. A list of Pontem functions can be found here.
1
script {
2
use 0x1::Signer;
3
use 0x1::DiemAccount;
4
use 0x1::PONT::PONT;
5
fun deposit(sender: signer, amount: u64) {
6
// Withdraw PONT tokens from sender account.
7
let pont_tokens = DiemAccount::pnt_withdraw<PONT>(&sender, amount);
8
9
// Deposit PONT tokens to account.
10
DiemAccount::pnt_deposit(Signer::address_of(&sender), pont_tokens);
11
}
12
}
Copied!
If you are ready to create a VASP account and use Diem functions:
1
script {
2
use 0x1::DiemAccount;
3
use 0x1::PONT::PONT;
4
use 0x1::Signer;
5
6
fun transfer_diem(tc_account: signer, sender: signer, payee: address, amount: u64) {
7
// Create VASP accounts.
8
DiemAccount::create_parent_vasp_account<PONT>(
9
&tc_account,
10
Signer::address_of(&sender),
11
x"",
12
x"626f62", // Account name, hex (Bob)
13
true
14
);
15
16
17
DiemAccount::create_parent_vasp_account<PONT>(
18
&tc_account,
19
payee,
20
x"",
21
x"616c696365", // Account name, hex (Alice)
22
true
23
);
24
25
// Do transfers.
26
let cap = DiemAccount::extract_withdraw_capability(&sender);
27
DiemAccount::pay_from<PONT>(&cap, payee, amount, x"", x"");
28
DiemAccount::restore_withdraw_capability(cap);
29
}
30
}
Copied!
Or deposit to another module:
1
script {
2
use {{address}}::Swap;
3
use {{address}}::ExampleToken;
4
5
use 0x1::PONT::PONT;
6
use 0x1::DiemAccount as Account;
7
8
fun main(sender: &signer, seller: address, price: u128) {
9
let pont = Account::pnt_withdraw(sender, price);
10
11
// Deposit NewToken to swap coins.
12
Swap::swap<ExampleToken::Token, PONT>(sender, seller, pont);
13
}
14
}
Copied!
Also, get a balance:
1
script {
2
use 0x1::Signer;
3
use 0x1::PONT::PONT;
4
use 0x1::DiemAccount;
5
6
fun get_balance(sender: signer, addr: address) {
7
// My balance.
8
let my_balance = DiemAccount::balance<PONT>(Signer::address_of(&sender));
9
10
// Someone balance.
11
let someone_balance = DiemAccount::balance<PONT>(addr);
12
13
assert(my_balance > 0, 101);
14
assert(someone_balance > 0, 102);
15
}
16
}
Copied!
To see all of the features of the DiemAccount module look at account.move.

Diem

The Diem module allows you to work with coin balances, get coin info, and also register new tokens among other capabilities.
The Pontem module presents type for all balances in the system, it's Diem::Diem:
1
/// The `Diem` resource defines the Diem coin for each currency in
2
/// Diem. Each "coin" is coupled with a type `CoinType` specifying the
3
/// currency of the coin, and a `value` field specifying the value
4
/// of the coin (in the base units of the currency `CoinType`
5
/// and specified in the `CurrencyInfo` resource for that `CoinType`
6
/// published under the `CoreAddresses::CURRENCY_INFO_ADDRESS()` account address).
7
struct Diem<CoinType> has store {
8
/// The value of this coin in the base units for `CoinType`
9
value: u64
10
}
Copied!
The value field contains information about actual balance for specific coin/token, e.g.:
1
script {
2
use 0x1::Signer;
3
use 0x1::DiemAccount;
4
use 0x1::PONT::PONT;
5
use 0x1::Diem::{Self, Diem}; // Use both Diem resource and Diem functions itself.
6
7
fun deposit(sender: signer, amount: u64) {
8
// Withdraw PONT tokens from sender account.
9
let pont_tokens : Diem<PONT> = DiemAccount::pnt_withdraw<PONT>(&sender, amount);
10
11
assert(Diem::value<PONT>(&pont_tokens) == amount, 101); // Throw an error if the withdrawn amount is wrong.
12
13
// Deposit PONT tokens to account.
14
DiemAccount::pnt_deposit(Signer::address_of(&sender), pont_tokens);
15
}
16
}
Copied!
You can create an empty coin:
1
address {{sender}} {
2
module BankPONT {
3
use 0x1::Diem::{Self, Diem};
4
use 0x1::PONT::PONT;
5
6
struct Storage has key {
7
balance: Diem<PONT>,
8
}
9
10
public fun create(account: &signer) {
11
move_to(account, Storage {
12
balance: Diem::zero<PONT>()
13
})
14
}
15
}
16
}
Copied!
Get denom, decimals, and actual value:
1
script {
2
use 0x1::Signer;
3
use 0x1::Diem;
4
use 0x1::DiemAccount;
5
use 0x1::PONT::PONT;
6
7
fun diem_example(sender: signer, amount: u64) {
8
let pont_tokens = DiemAccount::pnt_withdraw<PONT>(&sender, amount);
9
10
// Get denom vector<8>.
11
let _ = Diem::currency_code<PONT>();
12
13
// Get value of withdrawed xfi.
14
let value = Diem::value(&pont_tokens);
15
16
assert(amount == value, 101);
17
18
DiemAccount::pnt_deposit(Signer::address_of(&sender), pont_tokens);
19
}
20
}
Copied!
And check if it's a user token or system coin:
1
script {
2
use {{sender}}::ExampleToken::Token;
3
use 0x1::Diem;
4
use 0x1::PONT::PONT;
5
6
fun custom_token() {
7
assert(Diem::is_currency<PONT>() == false, 101);
8
assert(Diem::is_currency<Token>(), 102);
9
}
10
}
Copied!
For more documentation about the features provided by Pontem module see in Diem.move.

Vector

The Vector module contains functions to work with vector type.
For example:
1
script {
2
use 0x1::Vector;
3
4
fun vec() {
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!
For more information on this primitive type see the Diem Vector documentation.

Signature

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

Notice

The latest release of the Diem Standard Library contains a lot of changes related to permissioned blockchain functionality. A lot of functions can only be called/executed together with signatures from the Diem Root Account or Diem Treasury Account. To maintain compatibility, we had to slightly change the logic of the Standard Library. We restricted some functions that wouldn't be useful for developers working on a permissionless blockchain, but could be useful only for the Diem treasury or root account such as ‘AccountFreezing.move’. In this way we don't lose compatibility. A list of Restricted functions can be found here.
For tests of functions that require treasury or root signatures (e.g. create_account or register_currency) we created a way for developers to get access to those signatures. They just need to use dove during compilation of their script and put dr or tr literal as argument for the script. Documentation about dr and tr literals can be found here.
We also created Pontem-only related functions, as initially Diem blocked any operations with account balances, so developers couldn't even withdraw coins from the account and put it inside smart contracts, so we had to add our own functions with a ‘pnt_’ prefix. It breaks compatibility for now but, later once Diem allows us to work with balances we will migrate and release migration documentation. A list of Pontem functions can be found here.
Last modified 1mo ago