币安BSC智能链发币教程——合约中增加批量转账功能【pdf+视频BSC发币教程下载】

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

合约中增加批量转账功能,提供三种批量转账相关的合约实现功能代码:批量转账包含精度、批量转账不包含精度、批量转账固定数量

163Hash
Bitop
pi network
币安BSC智能链发币教程——合约中增加批量转账功能【pdf+视频BSC发币教程下载】
通常批量转账可以作为独立的软件来使用,但是第三方的批量转账软件都不太完善,要么需要你把所有的代币全部转让对方指定的账户地址,要么在使用第三方批量转账软件时需要提供钱包私钥,这样就容易泄露钱包私钥,存在安全隐患。考虑到此类问题,建议在合约中增加批量转账功能,就可以避免使用第三方批量转账软件。
一、如果提供三种批量转账相关的合约实现功能代码:批量转账包含精度、批量转账不包含精度、批量转账固定数量
1、批量转账包含精度代码实现
function multiTransfer(address from, address[] calldata addresses, uint256[] calldata tokens) external onlyOwner {

    require(addresses.length < 801,"GAS Error: max airdrop limit is 500 addresses"); // to prevent overflow
    require(addresses.length == tokens.length,"Mismatch between Address and token count");

    uint256 SCCC = 0;

    for(uint i=0; i < addresses.length; i++){
        SCCC = SCCC + tokens[i];
    }

    require(balanceOf(from) >= SCCC, "Not enough tokens in wallet");

    for(uint i=0; i < addresses.length; i++){
        _transfer(from,addresses[i],tokens[i]);
    }
}

如果合约包含分红tricker,那么相关的代码就需要修改为如下形式:

function multiTransfer(address from, address[] calldata addresses, uint256[] calldata tokens) external onlyOwner {

    require(addresses.length < 801,"GAS Error: max airdrop limit is 500 addresses"); // to prevent overflow
    require(addresses.length == tokens.length,"Mismatch between Address and token count");

    uint256 SCCC = 0;

    for(uint i=0; i < addresses.length; i++){
        SCCC = SCCC + tokens[i];
    }

    require(balanceOf(from) >= SCCC, "Not enough tokens in wallet");

    for(uint i=0; i < addresses.length; i++){
        _basicTransfer(from,addresses[i],tokens[i]);
        if(!isDividendExempt[addresses[i]]) {
            try distributor.setShare(addresses[i], balanceOf(addresses[i])) {} catch {} 
        }
    }

    // Dividend tracker
    if(!isDividendExempt[from]) {
        try distributor.setShare(from, balanceOf(from)) {} catch {}
    }
}

2、批量转账不包含精度

function multiTransfer_nodecimals(address from, address[] calldata addresses, uint256[] calldata tokens) external onlyOwner {

    require(addresses.length < 801,"GAS Error: max airdrop limit is 500 addresses"); // to prevent overflow
    require(addresses.length == tokens.length,"Mismatch between Address and token count");

    uint256 SCCC = 0;

    for(uint i=0; i < addresses.length; i++){
        SCCC = SCCC + tokens[i];
    }
    SCCC = SCCC * 10**_decimals;

    require(balanceOf(from) >= SCCC, "Not enough tokens in wallet");

    for(uint i=0; i < addresses.length; i++){
        _transfer(from,addresses[i],(tokens[i] * 10**_decimals));
    }
}

如果合约包含分红tricker,那么相关的代码就需要修改为如下形式:

function multiTransfer_nodecimals(address from, address[] calldata addresses, uint256[] calldata tokens) external onlyOwner {

    require(addresses.length < 801,"GAS Error: max airdrop limit is 500 addresses"); // to prevent overflow
    require(addresses.length == tokens.length,"Mismatch between Address and token count");

    uint256 SCCC = 0;

    for(uint i=0; i < addresses.length; i++){
        SCCC = SCCC + tokens[i];
    }
    SCCC = SCCC * 10**_decimals;

    require(balanceOf(from) >= SCCC, "Not enough tokens in wallet");

    for(uint i=0; i < addresses.length; i++){
        _basicTransfer(from,addresses[i],(tokens[i] * 10**_decimals));
        if(!isDividendExempt[addresses[i]]) {
            try distributor.setShare(addresses[i], balanceOf(addresses[i])) {} catch {} 
        }
    }

    // Dividend tracker
    if(!isDividendExempt[from]) {
        try distributor.setShare(from, balanceOf(from)) {} catch {}
    }
}

3、批量转账固定数量

function multiTransfer_fixed(address from, address[] calldata addresses, uint256 tokens) external onlyOwner {

    require(addresses.length < 2001,"GAS Error: max airdrop limit is 2000 addresses"); // to prevent overflow

    uint256 SCCC = tokens * addresses.length;

    require(balanceOf(from) >= SCCC, "Not enough tokens in wallet");

    for(uint i=0; i < addresses.length; i++){
        _transfer(from,addresses[i],tokens);
    }
}

如果合约包含分红tricker,那么相关的代码就需要修改为如下形式:

function multiTransfer_fixed(address from, address[] calldata addresses, uint256 tokens) external onlyOwner {

    require(addresses.length < 2001,"GAS Error: max airdrop limit is 2000 addresses"); // to prevent overflow

    uint256 SCCC = tokens * addresses.length;

    require(balanceOf(from) >= SCCC, "Not enough tokens in wallet");

    for(uint i=0; i < addresses.length; i++){
        _basicTransfer(from,addresses[i],tokens);
        if(!isDividendExempt[addresses[i]]) {
            try distributor.setShare(addresses[i], balanceOf(addresses[i])) {} catch {} 
        }
    }

    // Dividend tracker
    if(!isDividendExempt[from]) {
        try distributor.setShare(from, balanceOf(from)) {} catch {}
    }
}
以上为三种批量转账相关的合约实现功能代码。
二、直接在区块链浏览器上通过如下方式传递数组参数到合约,完成批量转账功能
注:以上是三种方式都可以实现批量转账功能,一定程度上都可以节约部分手续费,消耗的手续费大于一笔转账的手续费,小于每笔子交易单独转账时的累积和。
至此,完成合约中增加批量转账功能的所有操作流程。
pdf+视频币安智能链BSC发币教程下载:
币安BSC智能链发币教程——合约中增加批量转账功能【pdf+视频BSC发币教程下载】

pdf+视频币安智能链BSC发币教程下载地址:

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

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

币安BSC智能链发币教程——合约中增加批量转账功能【pdf+视频BSC发币教程下载】

免责声明

发文时比特币价格:$31249

当前比特币价格:[crypto coins=”BTC” type=”text” show=”price”]

当前比特币涨幅:[crypto coins=”BTC” type=”text” show=”percent”]

免责声明:

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

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

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

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

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

本文是全系列中第48 / 62篇:通证发行

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • App下载
  • 漫兮网App下载
  • weinxin
漫兮

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: