Token Contract

操作實例

NPM version

dmc_client 對象是 dmc.js 的一個實例,它提供了一系列的方法,用於與區塊鏈進行交互。
以下代碼中的 dmc_client 均由下面的代碼創建,不再贅述。

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

轉賬 —— 只有發行方為 datamall 的通證可以調用 (目前只有 DMC@datamall)

參數

name type description
from string 通證轉出方
to string 通證轉入方
quantity string 通證數量
memo string 附言

示例

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

轉賬

參數

name type description
from string 通證轉出方
to string 通證轉入方
quantity string 通證數量
memo string 附言

示例

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

增發通證

參數

name type description
to string 通證轉入方
quantity string 通證數量
memo string 附言

示例

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

銷燬賬戶持有的流通通證

參數

name type description
from string 通證轉出方
value string 通證數量
memo string 附言

示例

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

通證鎖倉

參數

name type description
from string 通證持有者
quantity string 通證數量
expiration date-time 鎖倉期
memo string 附言

示例

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

解鎖

參數

name type description
owner string 通證持有者
quantity string 解鎖數量
expiration date-time 待解鎖通證鎖倉期
memo string 附言

示例

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

掛單 PST

參數

name type description
owner string 掛單方
asset string 掛單數量
price double 掛單價格
expire_on date-time 最小掛單週期
deposit_ratio uint64_t 抵押比例
memo string 附言

示例

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

撤銷掛單

參數

name type description
owner string 掛單方
bill_id uint64_t 掛單ID
memo string 附言

示例

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

掛單成交

參數

name type description
owner string 執行交易者的賬戶名
bill_id uint64_t 掛單ID
benchmark_price uint64_t 提交訂單時的基準價格, 提交時需要將價格轉換為整數,即基準價格 * 10000
price_range PriceRangeType 1:基於基準價正負浮動 20%
2:基於基準價正負浮動 30%
3:價格不限
epoch uint64_t 服務週期(周), 目前最小為 24
asset extended_asset PST 購買量
reserve extended_asset 保證金
memo string 附言

示例

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

增加準備金

參數

name type description
owner string 執行交易者的賬戶名
asset string 增加的準備金數量
miner string 礦工

示例

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

贖回準備金

參數

name type description
owner string 執行交易者的賬戶名
rate double 贖回比例, $ 0<rate\le1$
miner string 礦工

示例

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

鑄造 PST

參數

name type description
owner string 執行交易者的賬戶名
asset string 鑄造的 PST 數量

示例

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

礦工最低質押比例

參數

name type description
owner string 執行交易者的賬戶名
rate double 礦工最低質押比例 $0.2 \le rate \le 1$

示例

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

設置礦工自定義質押率

參數

name type description
owner string 執行交易者的賬戶名
self_benchmark_stake_rate uint64_t 礦工自定義質押率, 由於兩位精度限制,所以需要乘以100

示例

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

礦工和用戶提供一致的默克爾樹根信息

參數

name type description
sender string 執行交易者的賬戶名
order_id uint64_t 訂單 ID
merkle_root checksum256 默克爾樹根
data_block_count uint64_t 數據塊數量

示例

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

用戶請求挑戰

參數

name type description
sender string 執行交易者的賬戶名
order_id uint64_t 訂單 ID
data_id uint64_t 數據塊 ID
hash_data checksum256 數據塊哈希
nonce std::string 隨機數

示例

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

礦工回答挑戰

參數

name type description
sender string 執行交易者的賬戶名
order_id uint64_t 訂單 ID
reply_hash checksum256 回覆哈希

示例

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

礦工仲裁

參數

name type description
sender string 執行交易者的賬戶名
order_id uint64_t 訂單 ID
data std::vector\<uint8_t> 數據
cut_merkle std::vector\<checksum256> 默克爾樹

示例

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

挑戰超時賠付

參數

name type description
sender string 執行交易者的賬戶名
order_id uint64_t 訂單 ID

示例

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

領取交付獎勵

參數

name type description
payer string 執行交易者的賬戶名
order_id uint64_t 訂單 ID

示例

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

取回用戶押金

參數

name type description
payer string 賬戶名
order_id uint64_t 訂單 ID

示例

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

用戶增加訂單預存額

參數

name type description
sender string 賬戶名
order_id uint64_t 訂單 ID
quantity extended_asset 增加數量

示例

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

用戶減少訂單預存額

參數

name type description
sender string 賬戶名
order_id uint64_t 訂單 ID
quantity extended_asset 減少數量

示例

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

更新訂單狀態

參數

name type description
payer string 賬戶名
order_id uint64_t 訂單 ID

示例

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

取消訂單

參數

name type description
sender string 賬戶名
order_id uint64_t 訂單 ID

示例

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);