当前位置:网站首页>[5 minutes to play lighthouse] quickly use Chang'an chain
[5 minutes to play lighthouse] quickly use Chang'an chain
2022-06-23 21:04:00 【Changan chain_ ChainMaker】
1、 Product background and significance
In the community operation of Chang'an chain, we found , When new users deploy Chang'an chain , Because the local environment is different , It causes some unnecessary blocking to the fast experience test Chang'an chain . So we plan to use the ECS , Provide a set of standard environment suitable for Changan chain , For community developers to experience and test Chang'an chain .
In addition, Tencent cloud Lighthouse Low cost features , When community users have lightweight Chang'an chain applications, they need to pilot and demo when , You can also use Lighthouse Achieve... At a low cost .
This product mainly includes : A Tencent cloud CVM The server 、 A set of Chang'an chain management platform , A long safety chain , One CMS Interactive console .
For the convenience of users , The Chang'an chain has been subscribed to the Chang'an chain management console , Four common test contracts are provided , For new users to get started quickly .
2、 choice Lighthouse + Changan chain service
Let's enter first Tencent cloud Lighthouse Lightweight application server page ,
Select the corresponding server to configure according to your needs .
- regional : Select as needed
- Image type : Apply image
- apply name : Changan chain Chainmaker
- Example packages , Server configuration , Minimum server machine configuration requirements 2 nucleus 8G.
3、 Visit Chang'an chain management console
Get into Lighthouse( Lightweight application servers ) Console , Find the Chang'an chain service you purchased in the server module , Click to enter service details .
In application management , Find the Chang'an chain management console application , among
- The login address is the access address of the management console
- The default account name is admin, The default password can be clicked on the login button , Log in to the server and enter the following command to obtain the password .
cat /home/chainmaker/credentials.txt - More instructions can be viewed , User manual
- Changan chain node address is , Node RPC Address , May pass through SDK Configure the address direct access chain on .
4、 Instructions for management console
4.1、 Login module
- Use the account and password obtained above to log in to the management console .
4.2、 Built in Changan chain configuration description
- At present, a Chang'an chain has been built in the management console , The main configuration information is as follows
Serial number | Content | explain |
|---|---|---|
1 | Changan chain version | V2.2.1 |
2 | chain id | chain1 |
3 | Number of organizations | 4 Organizations |
4 | Number of nodes | 4 Consensus nodes |
5 | Consensus algorithm | TBFT |
6 | The maximum trading capacity of a single block | 100 transaction |
7 | Transaction expiration time | 600s |
8 | Transaction interval | 2000ms |
9 | Do you support docker_VM | Support |
4.3、 Blockchain list
- At the blockchain management office , You can see the built-in deployed Chang'an chain . Click on the card to start using .
- Relevant certificates used in the chain , You can view and download in the certificate module .
- By default, the... Of this chain is used ,org1 Organized consensus1 Nodes to subscribe to the chain , And by org1 Organized admin1 User certificates are used to send transactions to the chain .
4.4、 View the sample contract
- The deployed contract information of this blockchain is shown here . New contracts are supported , Upgrade contract , Freeze the contract , Unfreeze the contract , Cancel the contract , Edit and view the contract, etc .
- Four test contracts are built in by default , Including the deposit contract , Transfer contract ,ERC-20 contract ,ERC-721 contract . Introduction to relevant contracts , See the contract introduction section .
4.5、 Use the example contract
- Here is the record of calling the contract through the platform , And the results of the implementation , You can also click to see the details , Jump to the blockchain browser to view the detailed information on the chain .
- Here, you can click initiate uplink to directly call the sample contract .
- Before using , It is recommended that you go to the contract introduction chapter first , Be familiar with the specific business content of the sample contract , Call again .
4.6、 Initiate the uplink
- Here you can select the contract you want to call , And the corresponding contract method , And fill in the reference , Click ok , Initiate uplink transactions .
- After the uplink request is initiated , The transaction will be built with the user selected during the subscription chain , And sign the transaction .
- After the transaction is sent successfully , You can view the details in the blockchain browser
4.7、 See the transaction details
- Each time the information on the chain will be in the form of blockchain transactions , Send to the blockchain .
- Transaction details can be viewed here , Including the block information of the transaction , Transaction originator information , The contract called by the exchange , The exchange carries information on the chain .
4.8、 View block details
- Transactions over a period of time will be collectively packaged into blocks , And link with other blocks in the form of new block chain to form a growing blockchain .
- Here you can view the specific information of the block , Include block hashes , Read / write set hash ,DAG Information , And the transaction information in this block .
5、 Sample contract introduction
5.1、 Overall description
For the convenience of users , Give an overall description of the following contract contents ( Or regulation ).
- Function type : Including execution and query , The execution function will perform the chain consensus operation , Query functions do not , Only the processing logic of the connected node is called ;
- Return value : When successful, there is a specific return value description , In case of failure, the failure reason will be returned ( Failure is no longer specified in the function set table );
- Introduction : If this parameter is optional, it will be explained , All other cases are required .
5.2、 List of contracts
Currently pre deployed 4 Sample contracts , As shown in the following table :
Serial number | Contract name | Contract function |
|---|---|---|
1 | SaveContract | Deposit contract , Can be saved Key-Value And descriptive information |
2 | TransferContract | Ordinary transfer contract , Used for general transfer business , No authority and other related design |
3 | ERC20Contract | ERC20 contract , Basically meet the official standards of Ethereum , Can be used as Token released Demo |
4 | ERC721Contract | ERC721 contract , Basically meet the official standards of Ethereum , Can be used as NFT released Demo |
5.3、 Deposit contract (Save)
5.3.1、 Contract function set
Function name | Function type | Function description | Introduction | Return value | remarks |
|---|---|---|---|---|---|
save | perform | existing evidence | key: Data storage key data: Contents of data storage desc: Description of data storage ( Optional ) | Data storage key | Repetitive key The original data will be overwritten |
find | Inquire about | Query object | key: Data storage key | Storing content JSON Format | Object structure : type EvidenceInstance struct { Key string |
Conduct save operation , That is, when saving the object to the bottom chain , If saved successfully, it will trigger preservation event , The subject of this event is :topic_save
5.3.2 Contract usage guide
The use of depository contracts is very simple , It mainly includes two methods :
- 1) Certificate data : call save Function to store data ;
- 2) Query data : call find Function to query the stored content ;
5.4、 Ordinary transfer contract
5.4.1 Contract function set
Function name | Function type | Function description | Introduction | Return value | remarks |
|---|---|---|---|---|---|
reset | perform | Set account assets | account: account number ; assets: Amount of funds ,uint64 Format string | The assets of the account ; | The account number can be any string |
add | perform | Add a specified number of assets to a specific account number | account: Specific account number ; assets: The amount of funds added to the account ,uint64 Format string | All remaining assets of the account number ; | |
transfer | perform | Transfer of assets | from: Account number transferred out to: Account number transferred in assets: Number of transferred assets ,uint64 Format string | The remaining assets of the transfer out account number | |
find | Inquire about | Query the asset quantity of the account | account: Specific account number | The remaining assets of the account |
The input parameters of all functions in the contract are required , Do not be empty , And it has strict format verification , Account is not recommended "/&%#@“ Equal special symbol When calling reset、add、transfer In operation , If the operation is successful, it will trigger Transfer event , The subject of this event is :topic_transfer
5.4.2 Contract usage guide
The contract invokes the core process simply , It can be simply divided into the following three steps :
- 1) Allocate assets : call reset function , A certain number of assets can be set for an account ;
- 2) Transfer of assets : call transfer function , You can transfer a specified number of assets from one account to another ;
- 3) Additional assets : call add function , You can add a specified number of assets to an account number ;
If you want to query the assets of an account , You can call find function , Just pass in the address of the account .
5.5、ERC20 contract
5.5.1 Contract initialization
Some basic configurations can be set during contract initialization , Including distribution token The name of 、 abbreviation 、 Total amount and other information , If it is not set, the default configuration in the contract code will be used . The parameter configuration list involved in the initialization process is described as follows :
Parameter name | Parameter meaning | The default value is |
|---|---|---|
owner | Address of contract owner | Address of the user who initiated the contract installation |
totalSupply | token Total supply | 1_000_000_000,10 Billion |
decimals | token Calculate the number of decimal points supported | 2, Indicates minimal support 0.01 |
name | token name | DEMO |
symbol | token abbreviation | DE |
5.5.2 Contract function set
Function name | Function type | Function description | Introduction | Return value | remarks |
|---|---|---|---|---|---|
name | Inquire about | Inquire about token name | The token The name of | Any account can be queried | |
symbol | Inquire about | Inquire about token abbreviation | The token For short | Any account can be queried | |
decimals | Inquire about | Inquire about token Support decimal places | The token Supported decimal places | Any account can be queried | |
totalSupply | Inquire about | Inquire about token Total number of issues | The token Total number of issues | Any account can be queried | |
owner | Inquire about | Query the owner of the contract | The owner of the contract | Any account can be queried | |
balanceOf | Inquire about | Query the name of the specified user token Number | owner: Specified user address | The address owns token Number | Any account can be queried |
transfer | perform | Transfer the specified quantity token Assign account number to | to: The account address of the transfer in ; value: Transferred token Number | The remaining in the current account token Number | This function can only transfer itself out ( Transaction originator ) Of token |
transferFrom | perform | Transfer the specified quantity instead of a certain account number token To a specific account number | from: Transfer out address ; to: Transfer in address ; value: Transfer token Number | from Account number remaining token Number | The transaction initiator of this function must go through from Authorization of account number , namely approve |
approve | perform | The authorized account can transfer a specified number of token | spender: Authorized user address value: Allowing transfer token Number | Allowing transfer token Number | Repeated calls to this function will reset the authorized value |
allowance | Inquire about | Returns that the specified account authorizes the remaining from a specific account token Number | owner: Authorized user address ; spender: Authorized user address | Authorize the remaining token Number | Any account can be queried |
transferOwner | perform | Transfer the owner of the current contract | to: New owner address | New owner address | Only the contract owner can initiate the transaction |
mint | perform | Issue additional to the designated account number token | to: Additional user address value: Additional issue token Number | The remainder of the additional address token Number | Only the contract owner can initiate the transaction , The contract call will adjust the total issuance amount |
burn | perform | Destroy a specified amount of token | value: Destroyed token Number | The account number remains token Number | Only the account number of the transaction initiator can be destroyed token |
deliver | perform | Distribute to the designated account token | to: Distributed users ( Optional , If it is not set, the current account number ) value: Distributed token Number | The account number remains token Number | Only the contract owner can initiate the transaction , The contract call will not affect the total issuance amount , This operation is to delete... From the contract account token Transfer out |
address | Inquire about | Returns the current user address | The address of the user | Any account can be queried |
5.5.3 Contract usage guide
In Changan chain docker-vm In the virtual machine model , The address algorithm of the transaction initiator has not been disclosed yet , Therefore, the user needs to manually call the contract address() Method to get .
ERC20 A contract is an issue token The contract of , Can be specified through this contract token Release operation of . Its core operation process includes the following steps :
- 1) Release the contract : Initialize contract , When initializing a contract, you can set the contract name through initialization parameters 、 The abbreviation and total issuance amount are set , After the issuance of the contract , All... In this contract token At the designated address CTT in , These need to be sent through the dispatch operation token Transfer out .
- 2) distributed token: Call the contract deliver Method to distribute the contract , By this method token From the default address CTT Transfer to the designated account number ;
- 3) Transfer your own token: Call the contract transfer The method can put your own token Transfer to another account ;
- 4) Transfer another's token: call transferFrom The method can be Others Of token Transfer to the designated account number , but Others You must empower yourself enough token The transfer operation can , Authorization operations can be performed through approve Function ;
- 5) Additional issue token: When need is right token When issuing additional shares , By calling mint Function to do ;
- 6) The destruction token: It can be done by burn Function destroys its own part token;
5.6、ERC721 contract
5.6.1 Contract initialization
Some basic configurations can be set during contract initialization , Including distribution NFT The name of 、 Abbreviation and other information , If it is not set, the default configuration in the contract code will be used . The parameter configuration list involved in the initialization process is described as follows :
Parameter name | Parameter meaning | The default value is |
|---|---|---|
name | token name | NFT-DEMO |
symbol | token abbreviation | NFDO |
5.6.2 Contract function set
Function name | Function type | Function description | Introduction | Return value | remarks |
|---|---|---|---|---|---|
name | Inquire about | Inquire about NFT name | The NFT The name of | Any account can be queried | |
symbol | Inquire about | Inquire about NFT abbreviation | The NFT For short | Any account can be queried | |
tokenURI | Inquire about | The query NFT Of URI Configuration information | tokenId: NFT Unique identification | The NFT Of URI Configuration information | Any account can be queried |
totalSupply | Inquire about | Query published NFT Number | The NFT The number of | Any account can be queried | |
tokenByIndex | Inquire about | Query all NFT Of a sequence number in a set NFT identification | index: The NFT Sequence number in the whole list | Corresponding serial number NFT identification (tokenId) | Any account can be queried |
tokenOfOwnerByIndex | Inquire about | Query a serial number under an account NFT identification | owner: Account number queried ; index: The sequence number of the query | Corresponding serial number NFT identification (tokenId) | Any account can be queried |
balanceOf | Inquire about | Look up the... Owned by an address NFT Number | owner: Account number queried | The address owns NFT Number ( Those destroyed are not included ) | Any account can be queried |
ownerOf | Inquire about | Query a NFT The owner of the | tokenId: NFT Unique identification | Have the right to NFT The address of | Any account can be queried |
transferFrom | perform | take NFT Transfer from one address to another | from: Transfer out address ( Optional , If it is not filled in, it is the current account number ); to: Transfer in address ; tokenId: NFT Unique identification | character string :“success” | if from It's not the time to NFT The owner of requires authorization from its owner |
safeTransferFrom | perform | Safely NFT Transfer from one address to another | from: Transfer out address ( Optional , If it is not filled in, it is the current account number ); to: Transfer in address ; tokenId: NFT Unique identification data: The content of verification , Usually by to The address is given by the user , It can be done by setCheckData Set up | character string :“success” | if from It's not the time to NFT The owner of requires authorization from its owner |
approve | perform | An authorized user can operate a NFT | approved: Authorized account number tokenId: Authorized NFT Unique identification | character string :“success” | This operation will overwrite the previously authorized account |
setApprovalForAll | perform | Set a user to own token Authorization status of | operator: to grant authorization / Reclaim the authorized account number approved: The state of being authorized ,0: Not authorized ,1: to grant authorization | 0: Not authorized ,1: to grant authorization | This authorization has priority over approve Higher |
getApproved | Inquire about | Get a NFT Address of the authorized operation | tokenId: NFT Unique identification | The NFT Authorized operation address of | Any account can be queried , However, you can only query your authorization |
isApprovedForAll | Inquire about | Get the authorization status of a specified user for an operator | owner : Designated users ( Optional , If you don't fill it in, it means you ) operator : Authorized operation address | 0: Not authorized ,1: to grant authorization | Any account can be queried |
mint | perform | Additional issuance of designated NFT To an account number | to: The additional account number to ( Optional , If you don't fill it out, you will be issued to yourself ) tokenId: NFT Unique identification tokenURI: NFT Of URI attribute | NFT Unique identification of (tokenId) | Any account can be reissued , but tokenId Can't repeat |
burn | perform | Destroy a specified NFT | tokenId: NFT Unique identification | character string :“success” | This account number must be this NFT The owner of the , Authorization cannot |
setTokenURI | perform | Set up NFT Of URI attribute | tokenId: NFT Unique identification tokenURI: NFT Of URI attribute | character string :“success” | This account number must be this NFT The owner of the , Authorization cannot , But to ensure uniqueness , Calling this function... Is not recommended |
setCheckData | perform | Set the account number check data | data: Set up check data | character string :“success” | This account can only set its own data, The data for safeTransferFrom Medium data check |
checkData | Inquire about | Query settings check data | The account number is set check data | Any account can be queried | |
address | Inquire about | Returns the current user address | The address of the user | Any account can be queried |
5.6.3 Contract usage guide
Same as ERC20 The contract is the same , The address of the transaction initiator requires the user to manually call the address in the contract address() Method to get .
ERC721 Is a distribution NFT The contract of , May be issued through this contract NFT Or transfer NFT Wait for the operation . Its core process includes the following steps :
- Release the contract : That is, initialize the contract , This class can be set during initialization NFT The name of (name) And abbreviation (symbol);
- Release NFT: Call the contract mint Method to issue the specified NFT, It is recommended to set... At the time of release NFT Of URI Information , Calling... Is not recommended setTokenURI Adjustment ;
- to grant authorization NFT: That is to authorize others to operate their own NFT, It can be done by approve Method to perform a NFT Authorization of , It can also be done through setApprovalForAll Function to authorize a user to perform all operations instead of himself , Of the two, the latter has a higher priority , Of course, users can realize their own logic by adjusting the contract mode ;
- General transfer NFT: This can be done by invoking the transferFrom Method , Realization NFT The transfer of , If the current operator is not the corresponding NFT The owner of the , Its owner is required to authorize the current operator ;
- Secure transfer NFT: This can be done by invoking the safeTransferFrom Method realization NFT Safe transfer of , The so-called security transfer refers to adding data Parameters , Can be based on data To achieve safe operation ;
- The destruction NFT: When users no longer want to use NFT when , It can be done by burn Function implementation to NFT Destruction of , It cannot be recovered after destruction .
6、SDK Access bottom chain
default Lighthouse There is no port required for open bottom chain access in environment , Without modifying the configuration 12301/12302/12303/12304. If you need to go through SDK Access bottom chain , You need to open the port first .
6.1、 Release the bottom chain access port
Enter Tencent cloud Lighthouse My management desk , Select the firewall page .
You can see that only some basic ports are open now , We are concerned about 12301-12304 Not open , Click here " Add rules " Button , Enter the rule configuration page :
Fill in the rules according to the above figure , If you want to restrict access to sources , Which IP The address can access the port , You can choose Enable Check box , Fill in the specified source IP:
After completion , Click the OK button , You will see the newly created rule :
In this case, if it is used locally telnet Tools to access , You can find that the port has been accessed normally :
6.2、 Download the certificate
adopt WebShell Sign in Lighthouse After the server , Use the following command to enter the user certificate page of the specified organization :
[[email protected] ~]$ cd /home/chainmaker/chain/release/chainmaker-v2.2.1-lh-org1.chainmaker.org/config/lh-org1.chainmaker.org/certs/user
[[email protected] user]$ ll
total 12
drwxr-xr-x 2 chainmaker chainmaker 4096 Jun 14 11:31 admin1
drwxr-xr-x 2 chainmaker chainmaker 4096 Jun 14 11:31 client1
drwxr-xr-x 2 chainmaker chainmaker 4096 Jun 14 11:31 light1The path in the above command chainmaker-v2.2.1-lh-org1.chainmaker.org and lh-org1.chainmaker.org Medium org1 The organization represented , Users can adjust according to their own organization , for example :org2 The corresponding adjustment is :
chainmaker-v2.2.1-lh-org2.chainmaker.org and lh-org2.chainmaker.org.
The system has built-in three users for each organization :admin/client/light, They represent the administrator 、 Ordinary users and light node users .
Users can enter the designated user page to download the corresponding certificate according to their own needs , With admin For example :
[[email protected] admin1]$ cd ../
[[email protected] user]$ cd admin1/
[[email protected] admin1]$ sudo su chainmaker
[[email protected] admin1]$ sz *
Received - admin1.sign.crt 17.89 KB/s Spend: 0 seconds
Received - admin1.sign.key 4.43 KB/s Spend: 0 seconds
Received - admin1.tls.crt 18.36 KB/s Spend: 0 seconds
Received - admin1.tls.key 4.52 KB/s Spend: 0 secondsSpecial note , You need to switch to before downloading chainmaker user , Otherwise, there will be permission problems .
6.3、SDK Use
SDK Available for reference :https://docs.chainmaker.org.cn/dev/SDK.html
边栏推荐
- How to deal with unclear pictures? What are the techniques for taking clear pictures?
- Machine learning related
- 【Golang】快速复习指南QuickReview(十)——goroutine池
- 徽商期货交易软件正规吗?如何安全下载?
- Install bitgarden open source password manager
- JS namespace
- . NET Core . NET Framework
- Troubleshooting of black screen after easynvr is cascaded to the upper platform and played for one minute
- Teach you how to use web pages to develop apps
- The substring() method in. JS can be used to intercept all characters after the specified string
猜你喜欢
Application of JDBC in performance test

Yaokui tower in Fengjie, Chongqing, after its completion, will be the safety tower for Sichuan river shipping with five local scholars in the company

3000 frame animation illustrating why MySQL needs binlog, redo log and undo log

JS advanced programming version 4: generator learning

Use of the vs2022scanf function. An error is reported when using scanf - the return value is ignored: Solutions

FPGA based electromagnetic ultrasonic pulse compression detection system paper + source file

Applet development framework recommendation
Implementing MySQL fuzzy search with node and express
随机推荐
Copilot - employee, your layoff notice has been delivered
How to separate image processing? What should I pay attention to when separating layers?
Postman tutorial - teach you API interface testing by hand
Process injection
JS delete object attribute
December 29, 2021: the elimination rules of a subsequence are as follows: 1. In a subsequence
游戏安全丨喊话CALL分析-写代码
Script tag attributes and & lt; noscript> label
Process crash does not generate dump. Configure localdumps
What is the role of short video AI intelligent audit? Why do I need intelligent auditing?
Machine learning related
Is it safe for flush to open an account online? Is the Commission high
Cobalt Strike Spawn & Tunnel
From different angles, you can learn about the implementation of sliding list in fluent
From AIPL to grow, talking about the marketing analysis model of Internet manufacturers
What is the main content of short video audit? What is illegal?
网上证券开户安全还是去营业部安全
[golang] quick review guide quickreview (VII) -- Interface
What are the server host security risks? How to prevent safety risks?
【Golang】怎样优雅的清空切片