Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the intelligent contract of block chain warehouse

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to realize the block chain warehouse intelligent contract, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to realize the intelligent contract of block chain warehouse. let's take a look.

[the goal of this paper] through the study of this paper, we can realize the block chain private placement and the method of locking the position for a certain time and releasing gradually when the foundation employee option (token) is encouraged.

[pre-condition] 1) A token for ERC20 has been completed. This paper takes the CLB that the author came into contact with as an example. 2) know how to debug SOLIDITY language in REMIX, unfamiliar reference article Solidity language editor REMIX guide Daquan.

Requirement implementation description

General blockchain projects in private placement or employee communication, there will be a clear policy on the issuance of tokens, generally speaking, the project will be required to lock up the position for how long, divided into several years. If we operate manually by way of contract, one is that it is more troublesome or uncontrollable, on the other hand, there is also a situation that private equity firms or employees cannot be trusted.

Then professional teams will choose to achieve it through smart contracts, which is the best way to be more credible, open, and unchangeable.

Generally speaking, this implementation includes three steps: 1) issue ERC20 token intelligence contract; 2) configure lock contract parameters, release lock intelligence contract; 3) transfer ERC20 token to lock position smart contract.

Analysis of Intelligent contract for Lock up

Lock position Intelligent contract Core Code:

/ * * @ title TokenVesting * @ dev A token holder contract that can release its token balance gradually like a * typical vesting scheme, with a cliff and vesting period. Optionally revocable by the * owner. * / contract TokenVesting is Ownable {using SafeMath for uint256; using SafeERC20 for Colorbay; event Released (uint256 amount); event Revoked (); / / beneficiary of tokens after they are released address public beneficiary; uint256 public cliff; uint256 public start; uint256 public duration; bool public revocable; mapping (address = > uint256) public released; mapping (address = > bool) public revoked; / * * @ dev Creates a vesting contract that vests its balance of any ERC20 token to the * _ beneficiary, gradually in a linear fashion until _ start + _ duration. By then all * of the balance will have vested. * @ param _ beneficiary address of the beneficiary to whom vested tokens are transferred * @ param _ cliff duration in seconds of the cliff in which tokens will begin to vest * @ param _ start the time (as Unix time) at which point vesting starts * @ param _ duration duration in seconds of the period in which the tokens will vest * @ param _ revocable whether the vesting is revocable or not * / constructor (address _ beneficiary, uint256 _ start, uint256 _ cliff, uint256 _ duration Bool _ revocable) public {require (_ beneficiary! = address (0)) Require (_ cliff 0); released [_ token] = released [_ token] .add (unreleased); _ token.safeTransfer (beneficiary, unreleased); emit Released (unreleased);} / * * @ notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. * @ param _ token ERC20 token which is being vested * / function revoke (Colorbay _ token) public onlyOwner {require (revocable); require (! revoked [_ token]); uint256 balance = _ token.balanceOf (address (this)); uint256 unreleased = releasableAmount (_ token); uint256 refund = balance.sub (unreleased); revoked [_ token] = true; _ token.safeTransfer (owner, refund); emit Revoked () } / * @ dev Calculates the amount that has already vested but hasn't been released yet. * @ param _ token Colorbay token which is being vested * / function releasableAmount (Colorbay _ token) public view returns (uint256) {return vestedAmount (_ token) .sub (released [_ token]);} / * * @ dev Calculates the amount that has already vested. * @ param _ token ERC20 token which is being vested * / function vestedAmount (Colorbay _ token) public view returns (uint256) {uint256 currentBalance = _ token.balanceOf (this); uint256 totalBalance = currentBalance.add (released [_ token]); if (block.timestamp

< cliff) { return 0; } else if (block.timestamp >

= start.add (duration) | | revoked [_ token]) {return totalBalance;} else {return totalBalance.mul (block.timestamp.sub (start)) .div (duration);}

Function description:

1. Lock contract initialization function constructor (...), which contains 5 parameters:

Address _ beneficiary: the income account that accepts the release of the pass

Uint256 _ start: start time (Unix time), indicating when to start timing

Uint256 _ cliff: in seconds, cliff time, for example, 1 year in "lock up for 4 years, thaw 25% at a time after 1 year"

Uint256 _ duration: unit in seconds (s), duration of lock-up, for example, 4 years in "lock up for 4 years, thaw 25% at a time after 1 year"

Bool _ revocable: whether it can be recycled (for example, the company gave employees Zhang San 10K tokens to lock up for 4 years, Zhang San left his job for one year, whether the rest of the company can be recycled)

Give an example to illustrate:

If _ cliff= for half a year The specific thawing conditions of _ duration=1 are as follows: Month 1: I get 0 tokens Month 2: I get 0 tokens Month 3: I get 0 tokens Month 4: I get 0 tokens Month 5: I get 0 tokens Month 6: I get 0 tokens-- End of cliff Month 7: I get 700 tokens (7/12th) Month 8: I get 100 tokens (8/12th) Month 9: I get 100 tokens (9/12th) Month 10: I get 100 tokens (10/12th) Month 11: I get 100 tokens (11/12th) ) Month 12: I get 100 tokens (12/12th)

2. The option token release function release (...), which contains 1 parameter:

Colorbay _ token:_token is the instance parameter of CLB token. When the time is up, it will be released to the corresponding revenue account through this function.

3. The option token recovery function revoke (...), which contains 1 parameter:

Colorbay _ token:_token is the instance parameter of CLB tokens, which returns unreleased tokens to the previous allocated account pool.

4 Test case verification

1] the administrator account issues a ColorBay token contract of ERC20

Administrator address: 0xca35b7d915458ef540ade6068dfe2f44e8fa733c

The information of the token contract is as follows: (1) decimals = 18; (2) totalSupply () = 1 billion; (3) symbol = CLB (4) paused = false (5) owner = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c (6) contract address = 0x692a70d2e424a56d2c6c27aa97d1a86395877b3a

CLB related information

2] the administrator account forwards 5 million to the employee incentive account for option incentive.

Administrator address: 0xca35b7d915458ef540ade6068dfe2f44e8fa733c

Special account address for employee motivation: 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

Transfer operation: (remember to remove "," after "5 million") transfer ("0x14723a09acff6d2a60dcdf7aa4aff308fddc160c", "500000000000000000000")

[result verification] balanceOf ("0x14723a09acff6d2a60dcdf7aa4aff308fddc160c") check confirms that the balance is 5 million CLB.

3) the current account is switched to a dedicated employee incentive account to create an option incentive plan

Scenario assumption: the incentive program starts at [20:25 on August 06, 2018.06], cannot be released within 2 minutes, lasts for 5 minutes (300s), and supports the recovery of unreleased options.

Special account address for employee motivation: 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

Private income account address of employee Li Si: 0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db

Call function: constructor ("0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db", "1533558300", "120,300", true)

[description] how to obtain an accurate starting time, you can use the webmaster tool to enter a specific time to convert.

The successful information of an intelligent contract example of option incentive is as follows: (1) contract address = 0x0fdf4894a3b7c5a101686829063be52ad45bcfb7

4] under the CLB contract, call the CLB pass to the option incentive intelligent contract address

Switch to the dedicated employee incentive account 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

Perform the transfer operation (remember to remove the "," after 1 million) transfer ("0x0fdf4894a3b7c5a101686829063be52ad45bcfb7", "1000000pr 0000000000000000")

As a result, the balanceOf ("0x0fdf4894a3b7c5a101686829063be52ad45bcfb7") check confirms that the balance is 1 million, indicating that the CLB token has been transferred to the option incentive smart contract.

5] [17:31 on August 06, 2018.06] Test allocation options after 5 minutes (300s)

Whether the execution option operates release ("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a")

Switch to the CLB contract and check Li Si's private account balanceOf ("0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db") to confirm that the balance is 1 million and the transfer is successful.

Query result

6] implementation of incentive plan for outgoing employees

The scenario assumes that the current account is switched to a dedicated employee incentive account to create an option incentive plan. It is assumed that the incentive given to the employee Wang Wu starts at [21:00 on August 06, 2018.06] and cannot be released within 2 minutes. It lasts for 5 minutes (300s), and the option recovery is supported. Wang Wu left his job in 4 minutes, and the company withdrew the unmotivated tokens and returned to the employee incentive account.

Special account for employee motivation: 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c

Private income account of employee Wang Wu: 0x583031d1113ad414f02576bd6afabfb302140225

* * perform actions: * * constructor ("0x583031d1113ad414f02576bd6afabfb302140225", "1533560400", "120,300", true)

The intelligent contract information of option incentive is as follows: contract address = 0x15e08fa9fe3e3aa3607ac57a29f92b5d8cb154a2

7] under the CLB contract, the pass calls the intelligent contract address of the option incentive

Switch to a dedicated employee incentive account and operate 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c under the CLB contract

Wang Wu option incentive intelligent contract address: 0x15e08fa9fe3e3aa3607ac57a29f92b5d8cb154a2

Specific operation (remember to remove the "," after 1 million) transfer ("0x15e08fa9fe3e3aa3607ac57a29f92b5d8cb154a2", "1000000pr 0000000000000000000")

Check the account balance of Wang Wu option incentive intelligent contract: balanceOf ("0x15e08fa9fe3e3aa3607ac57a29f92b5d8cb154a2") check and confirm that the balance is 1 million.

Check the account balance of the employee option incentive smart contract: balanceOf ("0x14723a09acff6d2a60dcdf7aa4aff308fddc160c") check to confirm that the balance is 3 million

8] [21:03 on August 06, 2018.06] Test allocation options after 3 minutes (180 s)

All release operations within 2 minutes will fail to roll back. 21:03 operation release function: release ("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a")

Switch to the CLB contract and check the Wang Wu private account balanceOf ("0x583031d1113ad414f02576bd6afabfb302140225") to check that 760000 tokens have been released to the Wang Wu income account.

9] [21:05 on August 06, 2018.06] 4 minutes later (240 s), Li Si resigned and withdrew the allocation option

Revoke ("0x692a70d2e424a56d2c6c27aa97d1a86395877b3a")

Switch to the CLB contract, query Li Si's private account balanceOf ("0x583031d1113ad414f02576bd6afabfb302140225") to check that there are 760000 tokens in the Wang Wu income account, no increase.

Query employee dedicated account balance balanceOf ("0x14723a09acff6d2a60dcdf7aa4aff308fddc160c")

It is found that all the remaining unreleased quota of Wang Wu has been returned to the employee-only account.

This is the end of the article on "how to realize the Intelligent contract of Block chain Warehouse". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to realize the intelligent contract of block chain warehouse". If you still want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 283

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report