Erc-20

如何手動批量轉移 erc 20 代幣?

  • April 6, 2022

誰能幫助我如何手動批量轉移代幣?因為我必須將代幣轉移到多個 ETH 地址,但不能浪費時間一一轉移。

下面的合約程式碼將允許您將代幣發送到多個 eth 地址。最適用於奇偶校驗。

pragma solidity ^0.4.16;

contract Ownable {

 address public owner;

 function Ownable() public {
   owner = msg.sender;
 }

 modifier onlyOwner() {
   require(msg.sender == owner);
   _;
 }

 function transferOwnership(address newOwner) public onlyOwner {
   require(newOwner != address(0));
   owner = newOwner;
 }
}

interface Token {
 function transfer(address _to, uint256 _value) public returns (bool);
 function balanceOf(address _owner) constant public returns (uint256 balance);
}

contract AirDrop is Ownable {

 Token token;

 event TransferredToken(address indexed to, uint256 value);
 event FailedTransfer(address indexed to, uint256 value);

 modifier whenDropIsActive() {
   assert(isActive());

   _;
 }

 function AirDrop () public {
     address _tokenAddr = 0x0F513fFb4926ff82D7F60A05069047AcA295C413; //here pass address of your token
     token = Token(_tokenAddr);
 }

 function isActive() public constant returns (bool) {
   return (
       tokensAvailable() > 0 // Tokens must be available to send
   );
 }
 //below function can be used when you want to send every recipeint with different number of tokens
 function sendTokens(address[] dests, uint256[] values) whenDropIsActive onlyOwner external {
   uint256 i = 0;
   while (i < dests.length) {
       uint256 toSend = values[i] * 10**18;
       sendInternally(dests[i] , toSend, values[i]);
       i++;
   }
 }

 // this function can be used when you want to send same number of tokens to all the recipients
 function sendTokensSingleValue(address[] dests, uint256 value) whenDropIsActive onlyOwner external {
   uint256 i = 0;
   uint256 toSend = value * 10**18;
   while (i < dests.length) {
       sendInternally(dests[i] , toSend, value);
       i++;
   }
 }  

 function sendInternally(address recipient, uint256 tokensToSend, uint256 valueToPresent) internal {
   if(recipient == address(0)) return;

   if(tokensAvailable() >= tokensToSend) {
     token.transfer(recipient, tokensToSend);
     TransferredToken(recipient, valueToPresent);
   } else {
     FailedTransfer(recipient, valueToPresent); 
   }
 }   


 function tokensAvailable() public constant returns (uint256) {
   return token.balanceOf(this);
 }

 function destroy() public onlyOwner {
   uint256 balance = tokensAvailable();
   require (balance > 0);
   token.transfer(owner, balance);
   selfdestruct(owner);
 }
}

https://github.com/crowdstartcapital/XSC/blob/master/XSC_AirDrop_public_functions.sol

您是否可以控制契約本身(在部署之前)?如果是,您可以編寫一個函式來為您完成。

如果不支持並且契約不支持批量功能(可能是這種情況),那麼您沒有太多選擇。你只需要使用合約提供的任何功能,這可能只是transfer功能。所以你必須以某種方式編寫腳本呼叫它。或者可能編寫自己的合約來執行代幣轉移。

引用自:https://ethereum.stackexchange.com/questions/46445