2

关于众筹课程,众筹失败退款问题

 2 years ago
source link: https://learnblockchain.cn/question/2144
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
关于众筹课程,众筹失败退款问题 | 登链社区 | 技术问答

关于众筹课程,众筹失败退款问题

function checkToken() public payable{
        require(now >= time);
        if (amount >= target){
            // 说明ICO成功,记录金额大于等于目标金额,给用户发送代币,并且把以太币都给受益人
            for(uint i=0;i<=UserAddress.length;i++){
                address addr = UserAddress[i];
                TransferToken.transfer(addr,UserToken[addr] / 1e18);
            }
            beneficiary.transfer(amount);
        }else{
            // 不成功,将以太金额返回给用户
            for(uint i=0;i<=UserAddress.length;i++){
                address payable addr = UserAddress[i];
                addr.transfer(UserEth[addr]);
            }
        }
    }

说明下上述变量:
UserToken[]:是mapping类型,存用户地址和应得到Token数量
UserEth[]:是mapping类型,存用户地址和支付ETH数量
UserAddress:是列表,存放所有参与用户的地址

我的目的是想统一在众筹结束以后,将列表中的用户的地址提取出来,并且给他们的地址transfer相应的代币或失败后的ETH。

但是当我执行时会报错
image.png

我知道循环很耗gas,但我的gas limit无论设多大都没用,如果想避免使用循环的话,那么应该有什么其他办法能实现同样的目的,请解惑


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK