China Mobile Chain Account, Contract and Resource Relationship Introduction

The China Mobile Chain account is a user ID registered on the China Mobile Chain blockchain, and each account can hold a certain amount of resources. The CPU resource is the computing power quota used by the account to execute the smart contract, which determines the CPU computing time that the account can use. NET resource is the bandwidth quota of the account, which is used to handle transaction transmission and network communication. RAM resources are used to store state library data during smart contract execution. These resources, chain accounts and smart contracts constitute the ecological environment of the entire China Mobile Chain.

01

Create chain account

In China Mobile Chain, the public-private key pair is generated through the elliptic curve encryption algorithm, which is an asymmetric encryption algorithm that uses two different keys (public key and private key) for encryption and decryption. Therefore, before creating an account, the public-private key pair of the account must first be generated. Public-private key pairs are used for authentication and transaction signing in order to execute smart contracts. In EOS, an account can have multiple public keys, and each public key can be authorized for different operations or contract execution permissions. Corresponding to this is the private key, which is kept secret and only accessible to the holder. The private key is responsible for signing and authenticating transactions, ensuring that only the holder of the private key can perform certain actions. Therefore, the private key must be kept in a safe place to prevent unauthorized persons from accessing your account and performing illegal operations.

After confirming the public-private key pair and saving it properly, find the chain account management in the background of the BSN open alliance chain, and click Create chain account in the upper left corner.

For chain type, select Mid-Shift Chain. The default account name of China Mobile Chain is 12 characters (characters a~z, 1~5 are allowed).

Enter the generated public key in ActiveKey, and click Confirm to create to complete the creation. (Note: The public and private keys can also be downloaded and saved by clicking the Generate Online button)

After the creation is complete, you can see the created chain account in the chain account management.

02

The main resource of the chain account

In China Mobile Chain, the chain account mainly includes three resources: CPU, RAM and NET. CPU resources are the computing power used to execute smart contracts, RAM resources are used to store smart contracts and other data, and NET resources are used to handle network communications. Each China Mobile Chain account needs to purchase these resources to be able to execute smart contracts on the blockchain.

China Mobile Chain query interface gateway address /api/[project id]/rpc/getAccount can obtain account information as follows:

{  
   "account_name": "testaccount1",  
    "head_block_num": 307847,  # 区块高度
    "privileged": false,  # 是否为超级账户
    "created": "2021-12-28T02:08:41.500",  # 账户创建时间  
    "core_liquid_balance": "5.3960 SYS",  # 可用余额  
    "ram_quota": 401417, # RAM总量 byte : 是实际买的RAM + 赠送的 ram_gift_bytes (1400)  
    "net_weight": 200000, # 网络带宽资源权重  
    "cpu_weight": 200000, # cpu资源权重  
    "net_limit": {  
      "used": 70142,      # 已用net  
      "available": 36168601, # 可用余额net 单位byte  
      "max": 36238743,  # 总net 值 单位byte  
      "current_used": 21807  
    },  
    "cpu_limit": { # 账户cpu使用信息  
      "used": 6239,  
      "available": 13817727,  
      "max": 13823966,  
      "current_used": 1940  
    },  
    "ram_usage": 383920,  # RAM已用 byte   
    "permissions": [{  # 权限相关信息
        "perm_name": "active",  
        "parent": "owner",  
        "required_auth": {  
          "threshold": 1,  
          "keys": [{  
              "key": "EOS6***********",  
              "weight": 1  
            }  
          ],  
          "accounts": [],  
          "waits": []  
        }  
      },{  
          *******
    ],  
    "total_resources": { # 总资源
      "owner": "testaccount1",  
     "net_weight": "20.0000 SYS",  
      "cpu_weight": "20.0000 SYS",  
      "ram_bytes": 400017 # 实际购买的RAM 大小  
    },  
    "self_delegated_bandwidth": null, # 为自己抵押的资源
    "refund_request": null,  # 正在赎回的资源
     "voter_info": null, # 投票的信息
 }  

It can be seen from the information returned by the interface that each chain account can obtain certain CPU, NET and RAM resources. Users can purchase resources through the function of allocating resources in the China Mobile Chain open consortium chain.

03

Introduction to chain account, contract and resource relationship

Chain accounts and smart contracts are the two core concepts of the China Mobile Chain blockchain platform, and together they build the cornerstone of the China Mobile Chain ecosystem.

Smart contracts are automated contracts executed on the China Mobile blockchain. It is a program written in code that contains certain conditions and rules. In the China Mobile Chain network, users can use C++ and JavaScript to write smart contracts, which will eventually be compiled into WebAssembly (Wasm) binary file format for execution. After writing the contract, the user needs to deploy the smart contract to the chain through the chain account, and one chain account can only deploy one contract. This chain account will become the unique identifier of the contract and serve as the identifier for storing the code and data of the contract. When deploying a smart contract, it is necessary to use the private key of the chain account for digital signature and authentication, and to send the binary file of the contract and related deployment parameters to the blockchain network.

RAM, CPU and NET are the three indispensable resources in China Mobile Chain. They provide the necessary support and guarantee for smart contracts, and also provide sufficient capacity and computing power for chain accounts, thereby promoting the development of the entire ecosystem. develop and expand.

China Mobile Chain accounts need to use RAM to store various types of data and state libraries during contract execution, for example:

(1) Account data records, such as account balances, transaction records, authorization information, public keys and permissions, etc.;

(2) Contract status information, such as key-value pairs of stored data, status and configuration information of smart contracts;

Each China Mobile Chain account needs to purchase enough RAM to support its contract execution needs, otherwise it will not be able to write new data (but the available space can be cleared by deleting the data in the state database in the smart contract). CPU resources are used to execute smart contracts, while bandwidth resources NET are used to transfer transactions and data to the chain. The consumption of CPU resources depends on the complexity and execution time of contract execution, while the consumption of NET resources depends on the size of contract execution transactions. The more active transactions on the chain, the easier it is for CPU and NET to be consumed. CPU and NET resources are mortgaged. If the CPU resource or NET resource quota of an account is insufficient, the contract execution speed of the account will be limited, and new contracts and transactions cannot be executed until the resources are linearly released or re-increased. Through the console of the BSN open consortium chain, you can easily see the current resource consumption.

04

References

[1] BSN open alliance chain:

https://opb.bsnbase.com/main/index

[2] Official EOSIO account and authority introduction:

https://developers.eos.io/welcome/latest/protocol-guides/accounts_and_permissions

[3] Official EOSIO transaction introduction:

https://developers.eos.io/welcome/latest/protocol-guides/transactions_protocol

[4] Official EOSIO smart contract introduction:

https://developers.eos.io/welcome/latest/smart-contract-guides/index

[5] Introduction to the official EOSIO resource module:

https://developers.eos.io/welcome/latest/resources/index

Computer access to DDC web portal

ddc.bsnbase.com

-END-

Guess you like

Origin blog.csdn.net/BSN_yanxishe/article/details/131375674