Solidity:我怎样才能获得我的 ERC20 的一系列所有者,并制定一个在不超过 Gas 限制的情况下使用它的智能合约?

问题描述 投票:0回答:1

我正在尝试制定一个智能合约,该合约需要一堆地址及其对我的 ERC20 的相应所有权。但是,我找不到自动编译这些数据的方法,所以我现在手动进行。所以,我的问题是:

1:有吗。一种自动编译的方法? 2:如果没有,有没有办法在不超过gas limit的情况下访问数据? 3:是否有其他方法可以根据地址拥有的 ERC20 数量按比例分配 ERC20?

现在,我正在尝试使用抽象合约来访问控制器中的所有内容。

abstract contract InterestInterface { ...

里面有2个数组:

string[] public holderAddresses = ['0x58ee92c366f197e434a1267a38e28e8c08cd27e7' ...
uint256[] private holderBalances = [50317379983, 24224355398, 5000000001,

这些是在 python 中手动收集和格式化的,并且取自 Etherscan。我希望的是 100,000,这是 Etherscan 的限制,但它甚至无法处理 500。我尝试使用像 bitquery 这样的东西,但我不是一家公司。

剩下的就是功能了:

function _collectdistributiondata() public { ...
        
function _distribute() public { ...

collectdistributiondata函数是看我需要分发多少,distribution函数就是分发。

我的流程的工作方式是 for 循环:

for (accountnumber = 1; accountnumber < holderAddresses.length && accountnumber < 100000; accountnumber++) {
            currentaddress = address(bytes20(bytes(holderAddresses[accountnumber])));
            currentbalance = (holderBalances[accountnumber]) / 128;
            token.transfer(currentaddress, currentbalance * 10 ** 18);
        }

我将 ERC20 发送到合约地址,这样它就可以将其发送出去,因为 TransferFrom 不起作用。

都可以在这里访问:

import "contracts/InterestInterface.sol";
contract Interest is InterestInterface{

    InterestInterface inter; 

    constructor (address interfaceaddress) {
        inter = InterestInterface(interfaceaddress);
    }

    function collectdistributiondata() public {
        
        inter._collectdistributiondata();
    }

    function distribute() public {

        inter._distribute();
    }
}

我可以做些什么不同的事情吗?另一种分配硬币的方式?

database solidity erc20
1个回答
0
投票
1.  Automate Data Compilation: Use Web3.jsor Web3.py to automatically track Transfer events of your ERC20 token. This generates a real-time list of holder addresses and balances, removing the need for manual updates.
2.  Off-chain Calculations: Perform the distribution calculations off-chain. Calculate how much each holder should receive based on their token balance.
3.  Use Merkle Tree for Distribution: Create a Merkle tree from your list of distributions. Deploy a smart contract that holds the Merkle root and allows token holders to claim their distribution by providing a Merkle proof. This minimizes on-chain data and gas costs.
4.  Batch Transactions for Distribution: Utilize a contract that supports batch transactions to distribute tokens to holders. This approach reduces the number of transactions and saves gas.
© www.soinside.com 2019 - 2024. All rights reserved.