1

How can I send tokens to a token holders from inside a smart contract with solidity? It means how can send reward to token holders?

M.Alaghemand
  • 105
  • 2
  • 6
  • Hi @M.Alaghemand - it would be much appreciated if you could upvote my answer if you find it useful. Thank you. – Dev Nov 14 '21 at 11:14

2 Answers2

1

Have a list of addresses and loop through them while calling native erc transfer method. You can't really iterate through a mapping without knowing the access keys (if you're thinking about pulling addresses from smth like balances).

Whytecrowe
  • 31
  • 3
0

I am assuming you want to send Ether to another Smart Contract or an EOA (e.g. Metamask). You can write a Smart Contract such as the below and use the Remix Ethereum (an IDE) to send Ether to an external party. Use the public function - transferEther.

//SPDX-License-Identifier: GPL-3.0
 
pragma solidity >= 0.6.0 < 0.9.0;
 
contract Sample{
    
    address public owner;
    
    constructor() {
        owner = msg.sender;
    }
    
    receive() external payable { 
    }
    
    fallback() external payable {
    }
    
    function getBalance() public view returns (uint){
        return address(this).balance;
    }

    // this function is for sending the wei/ether OUT from this smart contract (address) to another contract/external account.
    function transferEther(address payable recipient, uint amount) public returns(bool){
        require(owner == msg.sender, "transfer failed because you are not the owner."); // 
        if (amount <= getBalance()) {
            recipient.transfer(amount);
            return true;
        } else {
            return false;
        }
    }
}
Dev
  • 665
  • 1
  • 4
  • 12