币安BSC智能链发币教程——通过数组传递多个参数到构造函数的方式【pdf+视频BSC发币教程下载】

  • A+
所属分类:币安BSC
摘要

通过数组传递多个参数到构造函数的方式,避免传入过多的构造函数参数,容易报错stack too deep


chatGPT账号

币安BSC智能链发币教程——通过数组传递多个参数到构造函数的方式【pdf+视频BSC发币教程下载】

一、结论
1、多个相同类型的参数传递到构造最好通过数组的方式传递,然后在程序中读取数组变量。
2、对应address类型的变量数组,每个值要包含在双引号中,最好以数组的形成传入构造函数或者set函数
3、对应uint类型的变量不用使用双引号,直接以数组形式传递到函数即可
【附注20221208】
构造函数传递的多个输入参数,在合约开源时会自动捕获到并以ABI码的形式,填充到构造函数输入参数位置。根据编译器的不同版本,尽量避免传递过多的构造函数参数,不要超过16个函数构造函数参数,否则可能会报错stack too deep
另外,如果由多个数据类型相同的构造函数参数需要传递时,优先使用数组的形式传递,避免单个参数传入。
二、使用案例
如下形式的构造函数代码:
constructor(
        string memory name_,
        string memory symbol_,
        uint256 totalSupply_,
        address[4] memory addrs, // reward, router, marketing wallet, dividendTracker
        uint256[4] memory buyFeeSetting_, // rewards,lp,market,dead
        uint256[4] memory sellFeeSetting_,// rewards,lp,market,dead
        uint256 tokenBalanceForReward_,
        address serviceFeeReceiver_,
        uint256 serviceFee_
    ) payable ERC20(name_, symbol_)  {
        rewardToken = addrs[0];
        _marketingWalletAddress = addrs[2];

        buyTokenRewardsFee = buyFeeSetting_[0];
        buyLiquidityFee = buyFeeSetting_[1];
        buyMarketingFee = buyFeeSetting_[2];
        buyDeadFee = buyFeeSetting_[3];

        sellTokenRewardsFee = sellFeeSetting_[0];
        sellLiquidityFee = sellFeeSetting_[1];
        sellMarketingFee = sellFeeSetting_[2];
        sellDeadFee = sellFeeSetting_[3];

        require(buyTokenRewardsFee.add(buyLiquidityFee).add(buyMarketingFee).add(buyDeadFee) <= 25, "Total buy fee is over 25%");
        require(sellTokenRewardsFee.add(sellLiquidityFee).add(sellMarketingFee).add(sellDeadFee) <= 25, "Total sell fee is over 25%");

        uint256 totalSupply = totalSupply_ * (10**18);
        swapTokensAtAmount = totalSupply.mul(2).div(10**6); // 0.002%

        // use by default 300,000 gas to process auto-claiming dividends
        gasForProcessing = 300000;

        dividendTracker = BABYTOKENDividendTracker(
            payable(Clones.clone(addrs[3]))
        );

        dividendTracker.initialize(
            rewardToken,
            tokenBalanceForReward_
        );

        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(addrs[1]);
        address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());

        uniswapV2Router = _uniswapV2Router;
        uniswapPair = _uniswapV2Pair;

        _setAutomatedMarketMakerPair(_uniswapV2Pair, true);

        // exclude from receiving dividends
        dividendTracker.excludeFromDividends(address(dividendTracker));
        dividendTracker.excludeFromDividends(address(this));
        dividendTracker.excludeFromDividends(owner());
        dividendTracker.excludeFromDividends(deadWallet);
        dividendTracker.excludeFromDividends(address(_uniswapV2Router));

        // exclude from paying fees or having max transaction amount
        excludeFromFees(owner(), true);
        excludeFromFees(_marketingWalletAddress, true);
        excludeFromFees(address(this), true);

        _mint(owner(), totalSupply);

        payable(serviceFeeReceiver_).transfer(serviceFee_);
    }
1、由于设置了买卖不同的交易手续费,因此需要传入买卖不同的构造函数参数。买入作为一个数组,卖出作为一个数组。每个数组中设置代币流向的不同比例。
2、总共渠道包括rewards,lp,market,dead,即分红、LP自动加池、营销钱包、销毁 四个代币流向,如果想实现关闭买卖中的某个代币流向,可以设置为0
3、本案例构造函数参数输入形式如下:
string memory symbol_:BABY DOGE
string memory symbol_:BABY DOGE
uint256 totalSupply_:100000000000000000000000000000
address[4] memory addrs:["0x55xxxxxxxxxxxxxxxxxxxxxxxxB31979xx","0x10Exxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5602xx","0x88Ae4304b9xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxDCxx","0x38bE1xxxxxxxxxxxxxxxxxxxxxxxxx207Cxx"]
uint256[4] memory buyFeeSetting_:[5,1,2,4]
uint256[4] memory sellFeeSetting_:[5,1,2,4]
uint256 tokenBalanceForReward_:1000000000000000000
ddress serviceFeeReceiver_:0xd3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxb63xx
uint256 serviceFee_:0
至此,完成通过数组传递多个参数到构造函数的方式所有操作流程。pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载:

币安智能链BSC发币(合约部署、开源、锁仓、LP、参数配置、开发、故障处理、工具使用)教程下载:

币安BSC智能链发币教程——通过数组传递多个参数到构造函数的方式【pdf+视频BSC发币教程下载】

多模式(燃烧、回流指定营销地址、分红本币及任意币种,邀请推广八代收益,LP加池分红、交易分红、复利分红、NFT分红、自动筑池、动态手续费、定时开盘、回购)组合合约源代码下载:

币安BSC智能链发币教程——通过数组传递多个参数到构造函数的方式【pdf+视频BSC发币教程下载】币安BSC智能链发币教程——通过数组传递多个参数到构造函数的方式【pdf+视频BSC发币教程下载】

pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载地址:

此处为隐藏的内容!
登录后才能查看!

添加VX或者telegram获取全程线上免费指导

币安BSC智能链发币教程——通过数组传递多个参数到构造函数的方式【pdf+视频BSC发币教程下载】
免责声明

免责声明:

本文不代表知点网立场,且不构成投资建议,请谨慎对待。用户由此造成的损失由用户自行承担,与知点网没有任何关系;

知点网不对网站所发布内容的准确性,真实性等任何方面做任何形式的承诺和保障;

网站内所有涉及到的区块链(衍生)项目,知点网对项目的真实性,准确性等任何方面均不做任何形式的承诺和保障;

网站内所有涉及到的区块链(衍生)项目,知点网不对其构成任何投资建议,用户由此造成的损失由用户自行承担,与知点网没有任何关系;

知点区块链研究院声明:知点区块链研究院内容由知点网发布,部分来源于互联网和行业分析师投稿收录,内容为知点区块链研究院加盟专职分析师独立观点,不代表知点网立场。

本文是全系列中第117 / 237篇:通证发行

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的电报
  • 这是我的电报扫一扫
  • weinxin
chatGPT账号
知点

发表评论

您必须登录才能发表评论!