一、准备
多文件合约的开源区别于单文件合约,要选择组合合约的所有sol文件,文件可以多,但是不能少。如果有合约之间的调用,还需要在开源时配置上调用的library类库合约地址及合约名称。被调用的类库文件可以不开源,只要可供调用即可。多文件合约通常是把工具合约文件单独剥离出来,只保留业务相关的合约文件,这样方便开发。
二、开源步骤
1、进入合约开源入口
找到最下面的Tab页,选择Contract页签
2、执行合约开源
区别于单文件合约开源的地方:第二个选择框,选择Multi-Part File即多部分文件
如果在构造函数参数输入框位置,没有自动捕获到部署合约时输入的构造函数参数,就需要手动转换构造函数参数成ABI码形式,然后补充到该输入框,否则开源失败。
3、验证合约开源后效果
三、核心功能源代码
1、构造函数源代码
constructor(uint256 _initSupply, address _usdt, address _bfundAddress, address _sfundAddress, address _uniswapV2RouterAddress) { require(_usdt != address(0), "CITTProtocol: usdt address is 0"); require(_bfundAddress != address(0), "CITTProtocol: bfund address is 0"); require(_sfundAddress != address(0), "CITTProtocol: sfund address is 0"); require(_uniswapV2RouterAddress != address(0), "CITTProtocol: router address is 0"); _totalSupply = _initSupply * 10 ** _decimals; TOTAL_GONS = MAX_UINT256 / 1e10 - (MAX_UINT256 / 1e10 % _totalSupply); usdt = _usdt; bfundAddress = _bfundAddress; sfundAddress = _sfundAddress; uniswapV2RouterAddress = _uniswapV2RouterAddress; uniswapV2Router = IUniswapV2Router02(uniswapV2RouterAddress); uniswapV2PairBNB = IUniswapV2Factory(uniswapV2Router.factory()) .createPair(address(this), uniswapV2Router.WETH()) excluded[owner()] = true; excluded[address(this)] = true; excluded[uniswapV2RouterAddress] = true; excluded[bfundAddress] = true; excluded[sfundAddress] = true; emit Transfer(address(0), owner(), _totalSupply); }
2、transfer函数源代码
function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "CITTProtocol: transfer from the zero address"); require(to != address(0), "CITTProtocol: transfer to the zero address"); uint256 fromBalance; require(fromBalance >= amount, "CITTProtocol: transfer amount exceeds balance"); require(fromBalance * 99 / 100 >= amount, "CITTProtocol: transfer amount exceeds mxdeal precent") bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; if (overMinTokenBalance && !inSwapAndLiquify && (to == uniswapV2PairBNB || to == uniswapV2PairUSDT) && swapAndLiquifyEnabled) { contractTokenBalance = numTokensSellToAddToLiquidity; swapAndLiqudity(contractTokenBalance); } uint256 finalAmount = _fee(from, to, amount); _basicTransfer(from, to, finalAmount); }
四、完整版本合约源代码如下
该合约部署、动态参数配置、添加流动性及相关注意事项操作流程教程如下:
至此,完成开源BSC链上的多文件合约所有操作流程。
pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载:
多模式(燃烧、回流指定营销地址、分红本币及任意币种,邀请推广八代收益,LP加池分红、交易分红、复利分红、NFT分红、自动筑池、动态手续费、定时开盘、回购)组合合约源代码下载:
pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载地址:
此内容仅供注册用户可见,请登录!
添加VX或者telegram获取全程线上免费指导
评论前必须登录!
注册