System 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 in the code examples below is created using the following code, and it is not reiterated further.

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

newaccount

create a new account.

Parameters

name type description
creator string account name of the creator
name string account name of the account being created
owner string owner permission public key of the account being created
active string active permission public key of the account being created

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
32
33
34
35
36
37
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc',
name: 'newaccount',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
creator: account,
name: 'newaccount',
owner: {
threshold: 1,
keys: [{
key: 'DMC6MRy..',
weight: 1
}],
accounts: [],
waits: []
},
active: {
threshold: 1,
keys: [{
key: 'DMC6MRy..',
weight: 1
}],
accounts: [],
waits: []
},
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

setcode

Deploying a wasm contract.

Parameters

name type description
account string account of the contract owner
vmtype uint8 contract engine type
vmversion uint8 contract engine version
code string contract code

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',
name: 'setcode',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
account: account,
vmtype: '0',
vmversion: '0',
code: Buffer.from(fs.readFile(${wasm_file_path})).hex()
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

setabi

Deploy ABI file.

Parameters

name type description
account string account of the contract owner
abi json abi file code

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',
name: 'setabi',
authorization: [
{
actor: account,
permission: 'active'
},
],
data: {
account: account,
abi: encoding.hex.encode(dmc.jsonToRawAbi(abi))
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

updateauth

Add or modify user permissions.

Parameters

name type description
account string the name of the account
permission string the name of an existing permission or a newly created permission
parent string the parent permission that creates this permission
auth json the composition of this permission

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
let r = dmc_client.transact_sync({
actions: [
{
account: 'dmc',
name: 'updateauth',
authorization: [{
actor: account,
permission: 'owner',
}],
data: {
account: account,
permission: "PERMISSION_NAME",
parent: "PARENT_PERMISSION_NAME",
auth: {
threshold: 1,
keys: [{
key: new_pub_key,
weight: 1
}],
accounts: [],
waits: []
},
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

deleteauth

Delete permission.

Parameters

name type description
account string account name
permission string permission to be deleted

Instance

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

linkauth

Specify action for permission.

Parameters

name type description
account string account name
code string contract name
type string action name
requirement string permission name

Instance

Taking the example of binding the dmc.token contract with the transfer action.

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',
name: 'linkauth',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
account: account,
code: 'dmc.token',
type: 'transfer',
requirement: 'PERMISSION_NAME',
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});

unlinkauth

Actions allowed to be executed by the permission being deleted.

Parameters

name type description
account string account name
code string contract name
type string action name

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',
name: 'unlinkauth',
authorization: [{
actor: account,
permission: 'owner',
}],
data: {
account: account,
code: 'dmc.token',
type: 'transfer',
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});

buyrambytes

Purchase storage resources.

Parameters

name type description
payer string account name of the creator
receiver string account name of the receiver
bytes uint32 amount of ram to be purchased in bytes

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',
name: 'buyrambytes',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
payer: account,
receiver: account,
bytes: bytes,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

buyram

Purchase storage resources, distinguishing between buying a specific quantity of tokens or buying a specific size of content.

Parameters

name type description
payer string account buying the storage resources
receiver string account receiving the storage resources
quant string amount of tokens used for purchasing the storage resources

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',
name: 'buyram',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
payer: account,
receiver: account,
quant: '0.1273 DMC',
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});

sellram

Sell unused storage resources.

Parameters

name type description
account string account receiving the sold resource tokens, which is the same as the seller’s account
bytes uint64 amount of storage space to be sold

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',
name: 'sellram',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
account: account,
bytes: bytes,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

delegatebw

Stake tokens to obtain CPU and bandwidth resources.

Parameters

name type description
from string account name of the resource staker
receiver string account name of the resource receiver
stake_net_quantity string staker staking DMC for the receiver to obtain NET
stake_cpu_quantity string staker staking DMC for the receiver to obtain CPU
transfer bool whether to transfer the corresponding tokens to the receiver when staking resources. 1 for transfer, 0 for no transfer

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',
name: 'delegatebw',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
from: account,
receiver: account,
stake_net_quantity: '1.0000 DMC',
stake_cpu_quantity: '1.0000 DMC',
transfer: 0
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

undelegatebw

Used to unstake resources, release resources, and retrieve tokens.

Parameters

name type description
from string unstake tokens staked by which account
receiver string tokens staked on which account to be unstaked
unstake_net_quantity string amount of tokens staked for obtaining bandwidth resources to be unstaked
unstake_cpu_quantity string amount of tokens staked for obtaining CPU resources to be unstaked

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',
name: 'undelegatebw',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
from: account,
receiver: account,
unstake_net_quantity: '1.0000 DMC',
unstake_cpu_quantity: '1.0000 DMC',
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

refund

Called after undelegatebw function to unstake the tokens and return them to the account.

Parameters

name type description
owner string account name to which the tokens will be returned

Instance

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

regproducer

Register as a block producer.

Parameters

name type description
producer string register as a block producer
producer_key string register as a block producer
url string block producer website
location uint16 block producer server location area code, following the ISO 3166-1 standard.

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',
name: 'regproducer',
authorization: [{
actor: account,
permission: 'active',
}],
data: {
producer: account,
producer_key: publicKey,
url: url,
location: location,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.log(r);

unregprod

Unregister as a block producer.

Parameters

name type description
producer string account name

Instance

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

claimrewards

Block producer claims rewards.

Parameters

name type description
owner string block producer name

Instance

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