dmc.js
Common library for the DMC blockchain.
Please utilize the DMC, see installation
Basic
Various methods for operating user account information in the blockchain.
Instance of Retrieving Client
Taking the testnet as an instance.
1 | var DMC = require("dmc.js"); |
get_account
Returns an object containing various details about a specific account on the blockchain.
1 | dmc_client.rpc.get_account_sync(account_name) |
Parameter
Parameter name | Type | Description |
---|---|---|
account_name | string | Account name |
Instance
1 | var getAccount = dmc_client.rpc.get_account_sync("testnetbppa1"); |
Return Value
1 | { |
get_info
Get block information.
1 | dmc_client.rpc.get_info_sync(); |
Instance
1 | var getInfo = dmc_client.get_info_sync(); |
Return Value
1 | { |
Explanation of return value parameters
Parameters | Type | Description |
---|---|---|
server_version | string | Server Version |
chain_id | string | Blockchain Chain ID |
head_block_num | number | Current Block Height |
last_irreversible_block_num | number | Irreversible Block Height |
last_irreversible_block_id | string | Irreversible Block ID |
head_block_id | string | Current Block ID |
head_block_time | date | Current Block Time |
head_block_producer | string | Current Block Producer |
virtual_block_cpu_limit | number | Virtual Block CPU Limit |
virtual_block_net_limit | number | Virtual Block Network Limit |
block_cpu_limit | number | Block CPU Limit |
block_net_limit | number | Block Network Limit |
server_version_string | string | Server Version String |
fork_db_head_block_num | number | fork Database Block Height |
fork_db_head_block_id | string | fork Database Block Address |
server_full_version_string | string | Server Full Version String |
earliest_available_block_num | number | Earliest Available Block Height |
last_irreversible_block_time | date | Irreversible Block Time |
get_code
Returns an object containing the smart contract wasm.
1 | dmc_client.rpc.get_code_sync(account_name, code_as_wasm); |
Parameters
Parameters | Type | Description |
---|---|---|
account_name | string | Contract name |
code_as_wasm | boolean | True/false |
Instance
1 | var getCode = dmc_client.rpc.get_code_sync("dmc.token",true); |
Return Value
1 | { |
get_abi
Retrieve the ABI data of an account.
1 | dmc_client.rpc.get_abi_sync(account_name); |
Parameter
Parameter | Type | Description |
---|---|---|
account_name | string | Account name |
Instance
1 | var getAbi = dmc_client.rpc.get_abi_sync("dmc"); |
Return Value
1 | { |
get_block
Get block information.
1 | dmc_client.rpc.get_block_sync(block_num_or_id); |
Parameter
Parameter | Type | Description |
---|---|---|
block_num_or_id | int | Block number or ID |
Instance
1 | var getBlock = dmc_client.rpc.get_block_sync(5); |
Return Value
1 | { |
get_table_rows
Returns to the data from the specified table.
1 | dmc_client.rpc.getTableRows(code, table,scope, index_position,key_type, encode_type, lower_bound, upper_bound, limit, reverse, show_payer); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
code | string | yes | Contract name |
table | string | yes | Table name |
scope | string | yes | DMC account name |
index_position | string | no | Index position that to be used. |
key_type | string | no | Key type specified by index_position |
encode_type | string | no | Encoding type |
lower_bound | string | no | Lower bound |
upper_bound | string | no | Upper bound |
limit | integer | no | Number of returned results |
reverse | boolean | no | Whether to reverse the results |
show_payer | boolean | no | Whether to show the RAM payer |
Instance
1 | var getTableRows = dmc_client.rpc.get_table_rows_sync({ |
Return Value
1 | { |
ecc Module
Elliptic curve encryption function, built-in with multiple methods to generate the desired keys.
randomKey()
Generate a random private key.
1 | DMC.ecc.randomKey_sync(cpuEntropyBits?, options); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
cpuEntropyBits | number | no | CPU entropy bits |
options | object | no | Configuration item |
Return Value
Return a random private key.
Instance
1 | var randomKey = DMC.ecc.randomKey_sync(undefined, { secureEnv: true }) |
privateToPublic()
Calculate the public key information from the private key information.
1 | DMC.ecc.privateToPublic(key,pubkey_prefix?); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
key | string | yes | Private key |
pubkey_prefix | string | no | Public key prefix |
Return Value
Return to public key.
Instance
1 | var publicKey = DMC.ecc.privateToPublic("5JJznTGghwYBCJoW6EcpzZfybKEDqFULMniatBp9aykeauP55bB"); |
isValidPublic()
Determine if the public key is valid.
1 | DMC.ecc.isValidPublic(pubkey,pubkey_prefix?); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
pubkey | string | yes | Public key |
pubkey_prefix | string | no | Public key prefix |
Return Value
Check if the public key is valid.
Instance
1 | var isValidPublic = DMC.ecc.isValidPublic("DM75N93rrsoBzEzrdZePZtkDUQsXiTWX51irsSBBukxB6Jg4nrua"); |
isValidPrivate()
Check if the private key is valid.
1 | DMC.ecc.isValidPrivate(wif); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
wif | string | yes | Private key |
Return Value
Check if the private key is valid.
Instance
1 | var isValidPrivate = DMC.ecc.isValidPrivate("5JJznTGghwYBCJoW6EcpzZfybKEDqFULMniatBp9aykeauP55bB"); |
sign()
Create a signature using the data information or hash.
1 | DMC.ecc.sign(data,privateKey,encoding?); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
data | string | yes | Data |
PrivateKey | string | yes | Private key |
encoding | string | no | Data encoding |
Return Value
String signature.
Instance
1 | var sign = DMC.ecc.sign("i am alive","5JJznTGghwYBCJoW6EcpzZfybKEDqFULMniatBp9aykeauP55bB"); |
signHash()
Create a signature using the data information and private key for hash encryption.
1 | DMC.ecc.signHash(dataSha256, privateKey, encoding?); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
dataSha256 | string | yes | SHA256 hash of a 32-byte buffer or string |
PrivateKey | string | yes | Private key |
encoding | string | no | Encoding data with SHA256 (if it is a string) |
Return Value
String signature with hash encryption.
Instance
1 | var dataSha256 = ecc.sha256("i am alive") |
verify()
Verify the signature data.
1 | DMC.ecc.verify(signature,data,pubkey,encoding?,hashData?); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
signature | string | yes | Signature |
data | string | yes | Data |
pubkey | string | yes | Public key |
encoding | string | no | Data encoding |
hashData | boolean | no | Whether to hash encrypt the data |
Return Value
Verify the validity of the signature data.
Instance
1 | var verify = DMC.ecc.verify("SIG_K1_Kb64YDjawgAV8fbJaJXpyjwwFVTAp8tBjzq8zMZKmw4SUrRnWsLiSxcfHfbWp1XFikuBuC7gV71MCoCZm4xfoGLCC7KkGJ","i am alive","DM75N93rrsoBzEzrdZePZtkDUQsXiTWX51irsSBBukxB6Jg4nrua"); |
recover()
Recover the public key used to create the signature.
1 | DMC.ecc.recover(signature, data,encoding?); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
signature | string | yes | Signature |
data | string | yes | Data |
encoding | string | no | Data encoding |
Return Value
return to public key.
Instance
1 | var recover = DMC.ecc.recover("SIG_K1_Kb64YDjawgAV8fbJaJXpyjwwFVTAp8tBjzq8zMZKmw4SUrRnWsLiSxcfHfbWp1XFikuBuC7gV71MCoCZm4xfoGLCC7KkGJ","i am alive") |
recoverHash()
Recover the public key used to create the hash signature.
1 | DMC.ecc.recoverHash(signature,dataSha256,encoding); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
signature | string | yes | Signature |
dataSha256 | string | yes | SHA256 hash of a 32-byte buffer or string |
encoding | string | no | Encoding data with SHA256 (if it is a string) |
Return Value
Return a public key.
Instance
1 | var dataSha256 = ecc.sha256("i am alive") |
sha256()
SHA256 encryption.
1 | DMC.ecc.sha256(data,resultEncoding?,encoding?); |
Parameters
Parameter | Type | Whether it is required or not | Description |
---|---|---|---|
data | string | yes | Binary data, requires Buffer.from(data, ‘hex’). |
resultEncoding | string | no | Encode the result as ‘hex’, ‘binary’, or ‘base64’ (optional, default is 'hex' ) |
encoding | string | no | Encode the data (if it is a string) as ‘hex’ (optional, default is 'hex' ) |
Return Value
Use the data encrypted with hash.sha256
Instance
1 | var dataSha256 = DMC.ecc.sha256("i am alive") |