resources

DMC resources are divided into two types: staked resources, including CPU and NET, and consumable resources called RAM or storage.

Users need to have sufficient RAM, CPU, and NET resources to deploy a contract.

RAM and Resources

RAM (Random Access Memory)

Network Bandwidth

CPU Bandwidth

How to Buy RAM and Stake Resources

Buying RAM

  1. Storing account information on the chain requires consuming memory. The creator needs to purchase memory for the account being created to store its information.

By calling the buyrambytes method, the parameters and their explanations are as follows:

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

dmc_client.transact_sync({
actions: [{
account: 'dmc',
name: 'buyrambytes',
authorization: [{
actor: 'from', // The account purchasing the storage resources.
permission: 'active',
}],
data: {
payer: 'from', // The account purchasing the storage resources.
receiver: 'Receiver Account',//The account receiving the storage resources.
bytes: 'bytes' // The amount of RAM being purchased
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
})
  1. To purchase storage resources, there is a distinction between buying a specific amount of tokens or buying a specific size of content.

    By calling the buyram method, the parameters and their explanations are as follows:

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

dmc_client.transact_sync({
actions: [{
account: 'dmc',
name: 'buyram',
authorization: [{
actor: 'from', // The account purchasing the storage resources.
permission: 'active',
}],
data: {
payer: 'from', // The account purchasing the storage resources.
receiver: 'Receiver Account',// The account receiving the storage resources.
quant: "0.2000 DMC" // The amount of tokens used to purchase the storage resources
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
})

Staking Resources

The creator stakes DMC on behalf of the recipient to obtain CPU and NET resources, enabling the new account to perform transfers.

By calling the delegatebw method, the parameters and their explanations are as follows:

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

dmc_client.transact_sync({
actions: [
{
account: 'dmc',
name: 'delegatebw',
authorization: [{
actor: 'from', // The account name of the resource staker
permission: 'active',
}],
data: {
from: 'from', // The account name of the resource receiver
receiver: 'receiver', // The account name of the resource receiver
stake_net_quantity: "10.0000 DMC", // The amount of DMC staked by the staker to obtain NET for the receiver
stake_cpu_quantity: "10.0000 DMC", // The amount of DMC staked by the staker to obtain CPU for the receiver
transfer: 0 // Indicating whether the corresponding tokens are transferred to the receiver along with the staked resources
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});

Unstaking Resources

To unstake, release resources, and reclaim tokens.

By calling the undelegatebw method, the parameters and their explanations are as follows:

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

dmc_client.transact_sync({
actions: [
{
account: 'dmc',
name: 'undelegatebw',
authorization: [{
actor: 'from', // The account name of the resource staker
permission: 'active',
}],
data: {
from: 'from', // The account that staked the tokens to be unstaked
receiver: 'receiver', // The staked token of which account to be unstaked
unstake_net_quantity: "10.0000 DMC", //The amount of tokens being unstaked for net resources
unstake_cpu_quantity: "10.0000 DMC", // The amount of tokens being unstaked for CPU resources
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});

Selling Resources

By calling the sellram method, the parameters and their explanations are as follows:

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
var dmc_client = DMC({
chainId: 'c102a8115bef9e4a4e751559aac2cdc2859417e6476f8cb6054cd3f7dffe1ce4',
keyProvider: 'creator_priKey',
httpEndpoint: 'http://testnode.dmctech.io:8801',
logger: {
log: null,
error: null
}
});

dmc_client.transact_sync({
actions: [
{
account: 'dmc',
name: 'sellram',
authorization: [{
actor: 'from', // The account selling the RAM tokens.
permission: 'active',
}],
data: {
account: 'from', // The account selling the RAM tokens.
bytes: 'bytes' // The amount of storage resources (RAM) being sold.
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});