Token Contract

Operation Example

NPM version

The dmc_client object is an instance of dmc.js, which provides a series of methods for interacting with the blockchain.

The dmc_client mentioned in the following code is created by the code provided below, and it will not be reiterated.

1
2
3
4
5
6
7
8
9
10
var DMC = require('dmc.js');
var dmc_client = DMC({
chainId: 'c102a8115bef9e4a4e751559aac2cdc2859417e6476f8cb6054cd3f7dffe1ce4',
keyProvider: 'creator_priKey',
httpEndpoint: 'http://testnode.dmctech.io:8801',
logger: {
log: null,
error: null
}
});

transfer

Transfer - Only tokens issued by datamall can be called (currently only DMC@datamall).

Parameters

name type description
from string token sender
to string token receiver
quantity string token quantity
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'transfer',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
from: account,
to: 'dmccouncil',
quantity: '20.3375 DMC',
memo: 'havefun'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

extransfer

Transfer.

Parameters

name type description
from string token sender
to string token receiver
quantity string token quantity
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'extransfer',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
from: account,
to: 'dmccouncil',
quantity: {
quantity: '20.3375 DMC',
contract: 'datamall'
}
memo: 'havefun'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

exissue

Increase token issuance.

Parameters

name type description
to string token receiver
quantity string token quantity
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'exissue',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
to: account,
quantity: {
quantity: '10.0000 DMC',
contract: 'datamall'
},
memo: 'issue to datamall'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

exretire

Destroy the circulating tokens held by an account.

Parameters

name type description
from string token sender
value string token quantity
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'exretire',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
from: account,
value: {
quantity: '10.0000 DMC',
contract: 'datamall'
},
memo: 'retire tokens'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

exlock

Lock token.

Parameters

name type description
from string token owner
quantity string token quantity
expiration date-time lock-up period
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'exlock',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
from: account,
quantity: {
quantity: '10.0000 DMC',
contract: 'datamall'
},
expiration: '2024-08-01T00:00:00',
memo: 'lock tokens'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

exunlock

Unlock.

Parameters

name type description
owner string token owner
quantity string unlocked quantity
expiration date-time unlocked quantity Lock-up period for pending unlock tokens
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'exunlock',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
owner: account,
quantity: {
quantity: '10.0000 DMC',
contract: 'datamall'
},
expiration: '2024-08-01T00:00:00',
memo: 'unlock tokens'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

bill

Place a PST order.

Parameters

name type description
owner string order Placer
asset string quantity of the PST of the order
price double the price of the order
expire_on date-time minimun period of the order
deposit_ratio uint64_t stake rate
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'bill',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
owner: account,
asset: {
quantity: '10 PST',
contract: 'datamall'
},
price: 0.1,
expire_on: '2024-08-01T00:00:00',
deposit_ratio: 2,
memo: 'bill tokens'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

unbill

Cancel Order.

Parameters

name type description
owner string order Placer
bill_id uint64_t id of the order
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'unbill',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
owner: account,
bill_id: bill_id,
memo: 'unbill tokens'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

order

fill an order.

Parameters

name type description
owner string account Name that executes the transaction
bill_id uint64_t order ID
benchmark_price uint64_t the benchmark price when placing the order, to convert the price to an integer, multipy the benchmark price by 10000
price_range PriceRangeType 1:Based on the benchmark price with a positive or negative fluctuation of 20%
2: Based on the base price with a positive or negative fluctuation of 30%
3: No price limit
epoch uint64_t service period (in weeks), currently with a minimum of 24.
asset extended_asset PST quantity to be purchased
reserve extended_asset reserve
memo string memo

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'order',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
owner: account,
bill_id: 1,
benchmark_price: 20000,
price_range: 3,
epoch: 24,
asset: {
quantity: '10 PST',
contract: 'datamall'
},
reserve: {
quantity: '100.0000 DMC',
contract: 'datamall'
},
memo: 'order tokens'
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

increase

Increase reserve.

Parameters

name type description
owner string account Name that executes the transaction
asset string the amount of increased reserve
miner string miner

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'increase',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'owner': account,
'asset': {
'quantity': '100.0000 DMC',
'contract': 'datamall'
},
'miner': account
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

redemption

claim reserve.

Parameters

name type description
owner string account Name that executes the transaction
rate double claim rate, $ 0<rate\le1$
miner string miner

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'redemption',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'owner': account,
'rate': rate,
'miner': account
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

mint

mint PST.

Parameters

name type description
owner string account Name that executes the transaction
asset string the quantity of minted PST

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'mint',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'owner': account,
'asset': {
'quantity': '10 PST',
'contract': 'datamall'
}
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

setmakerrate

The minimum staking rate for miners.

Parameters

name type description
owner string account Name that executes the transaction
rate double the minimum staking rate for miners $0.2 \le rate \le 1$

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'setmakerrate',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'owner': account,
'rate': rate
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

setmakerbstr

Setting a custom staking rate for miners.

Parameters

name type description
owner string account Name that executes the transaction
self_benchmark_stake_rate uint64_t custom staking ratio for miners, multiplied by 100 due to the limitation of two decimal places.0

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'setmakerbstr',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'owner': account,
'self_benchmark_stake_rate': REAL_SELF_BENCHMARK_STAKE_RATE * 100
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

addmerkle

Miners and users provide consistent Merkle tree root information.

Parameters

name type description
sender string account Name that executes the transaction
order_id uint64_t order ID
merkle_root checksum256 merkle tree root
data_block_count uint64_t number of data blocks

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'addmerkle',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'sender': account,
'order_id': 1,
'merkle_root': merkle_tree[merkle_tree.length - 1][0],
'data_block_count': data.length
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

reqchallenge

User requests a challenge.

Parameters

name type description
sender string account Name that executes the transaction
order_id uint64_t order ID
data_id uint64_t data block ID
hash_data checksum256 data block hash
nonce std::string random number

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'reqchallenge',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'sender': account,
'order_id': 1,
'data_id': 1,
'hash_data': hash_data,
'nonce': nonce
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

anschallenge

Miner answers a challenge.

Parameters

name type description
sender string account Name that executes the transaction
order_id uint64_t order ID
reply_hash checksum256 response hash

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'anschallenge',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'sender': account,
'order_id': 1,
'reply_hash': reply_hash
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

arbitration

Arbitration by miner.

Parameters

name type description
sender string account Name that executes the transaction
order_id uint64_t order ID
data std::vector\<uint8_t> data
cut_merkle std::vector\<checksum256> merkle tree

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'arbitration',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'sender': account,
'order_id': 1,
'data': Buffer.from(data[2]),
'cut_merkle': [
merkle_tree[0][3],
merkle_tree[1][0]
]
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

paychallenge

Challenge timeout compensation.

Parameters

name type description
sender string account Name that executes the transaction
order_id uint64_t order ID

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'paychallenge',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'sender': account,
'order_id': 1
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

claimorder

Claim delivery rewards.

Parameters

name type description
payer string account Name that executes the transaction
order_id uint64_t order ID

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'claimorder',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'payer': account,
'order_id': 1
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

claimdeposit

Claim user‘s deposit.

Parameters

name type description
payer string account name
order_id uint64_t order ID

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'claimdeposit',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'payer': account,
'order_id': 1
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

addordasset

Increase order predeposit by user.

Parameters

name type description
sender string account name
order_id uint64_t order ID
quantity extended_asset increased quantity

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'addordasset',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'sender': account,
'order_id': 1,
'quantity': {
'quantity': '1.0000 DMC',
'contract': 'datamall'
}
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

subordasset

Decrease order predeposit by user.

Parameters

name type description
sender string account name
order_id uint64_t order ID
quantity extended_asset decreased quantity

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'subordasset',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'sender': account,
'order_id': 1,
'quantity': {
'quantity': '1.0000 DMC',
'contract': 'datamall'
}
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

updateorder

Update order status.

Parameters

name type description
payer string account name
order_id uint64_t order ID

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'updateorder',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'payer': account,
'order_id': 1,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

cancelorder

Cancel order.

Parameters

name type description
sender string account name
order_id uint64_t order ID

Instance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc.token',
name: 'cancelorder',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
'sender': account,
'order_id': 1,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);