swap丨dapp智能合约只涨不跌项目系统开发成熟技术/案例设计/逻辑方案/源码指南

简介: 合约:import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

合约:import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

}

function isVerifyMerkleNormal(bytes32[] calldata proof) view public returns (bool) {
bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
return MerkleProof.verify(proof, whiteRootNormal, leaf);
}
首先你需要import,然后合约的角色是去验证,传入proof,然后生成leaf对象,verify方法会根据root去做校验,这里会在构造方法里先初始化一个root,后面如果有白名单的增删改查的话,只要去修改这个root就行了,如果有修改只需要修改一次gas费即可。

前端
前端这里的流程是这样的,有一个accounts的数组,根据这个数组去生成默克尔树的roots,如果是部署合约的时候,直接把这个roots写进合约里就行了,但如果是增删改查白名单的话,就需要在合约里的write contract方法里去更新这个roots了。
这里注意,如果非数组里的账户生成的proof为空,前端如果要测试的话就可以这么来测试是否为白名单。
//生成白名单
const generateWhiteOGProofs = () => {

//buffer化叶子结点
const leafNodes = whitelistAddressesOG.map(addr => keccak256(addr));
//实例化默克尔树
const merkleTree = new MerkleTree(leafNodes, keccak256, { sortPairs: true });
setMerkleTreeOG(merkleTree);
//获取根哈希值
const rootHash = merkleTree.getRoot();
console.log(rootHash);
console.log('Whitelist Merkle Tree og\n', merkleTree.toString());

}

相关文章
|
3月前
|
安全 区块链 数据库
DAPP持币生息项目系统开发|步骤逻辑|源码案例
智能保证执行安全,并减少交易成本。智能合约允许在没有第三方的情况下进行可信交易,且交易可追踪、不可逆转
|
3月前
|
安全 区块链
数字货币秒合约/交易所系统开发详细程序/案例项目/需求设计/方案逻辑/源码步骤
The development of a digital currency second contract/exchange system requires the following functions:
|
11月前
|
安全 前端开发 JavaScript
swap薄饼交易所系统开发技术详细/方案项目/逻辑需求/步骤指南/功能流程/源码版
Blockchain platform selection: Choose a suitable blockchain platform as the underlying infrastructure, such as Ethereum, Coin Security smart chain, etc. These platforms provide smart contract functions and transaction confirmation mechanisms, making them suitable for building decentralized exchanges
|
1月前
|
存储 安全 前端开发
区块链 DAPP 互助逻辑模式系统开发技术方案[源码示例]
Dapp(Decentralized Application)是指不受任何中心化组织或机构控制的、使用特定区块链技术为基础的去中心化应用程序。Dapp 是一种特殊类型的应用,它可以在任何基于区块链技术的系统,例如 Ethereum、EOS 或其他的智能合约系统上运行。
|
1月前
|
安全
链游系统开发DAPP项目逻辑讲解方案
链游系统开发具有以下优势:   1.Decentralization:Chain game systems are based on blockchain technology and do not rely on centralized servers,providing a more fair and transparent gaming environment.   2.Data security:Through the decentralized characteristics and encryption algorithms of blockchain,the chai
|
3月前
|
监控 供应链 安全
dapp智能合约只涨不跌系统开发步骤详细/开发案例/功能需求/方案项目/源码功能
需求分析:明确系统的功能需求和业务逻辑。确定系统需要支持的资产类型、交易规则和逻辑限制等。
|
10月前
|
安全 区块链
阐述永续合约交易所系统开发方案逻辑及案例项目丨源码程序
阐述永续合约交易所系统开发方案逻辑及案例项目丨源码程序
|
11月前
|
vr&ar
DeFi流动性质押项目系统开发详细步骤/方案逻辑/案例开发/源码程序
DeFi (Decentralized Finance) pledge mining is a blockchain based financial activity that combines pledge and mining mechanisms. It provides a new way to provide benefits to participants and promote the development of a centralized financial ecosystem.
|
11月前
|
区块链 安全
区块链交易所系统开发详细指南丨交易所系统开发功能逻辑/方案介绍/案例设计/逻辑项目/源码出售
User experience: The interface and user experience of blockchain exchanges should be intuitive, user-friendly, and easy to use and navigate. The platform should provide a simple and clear trading interface to facilitate users' buying and selling operations.
|
12月前
|
存储 算法 前端开发
区块链 DAPP 互助逻辑模式系统开发技术源码方案
string public name; uint public goal; uint public progress; address public admin; mapping (address => bool) public members;