Basically, I need to take an amount and send it to addresses that are in an array. The amount would be distributed by the percentage of the tokens they have from the total amount of coins.
Example:
Amount sent 10
I cant figure out how to get the addresses in the array with their amounts and their percentage of tokens.
I posted about this yesterday with the code I've been working on:
  
  
    I'm having trouble with working out how to calculate the reward and send the amount to the stakeholders. I can deploy to the initial wallet but it fails when I try to send any to another address. I used some of the code from this guide: 
https://hackernoon.com/implementing-staking-in-solidity-1687302a82cf  
Here's my code that I'm having trouble with: 
contract CHAR is Context, IERC20, Ownable {
    using SafeMath for uint256;
    using Address for address;
    mapping (address => uint256) priva…
   
 
             
            
              
            
           
          
            
            
              Iterating over an array is not a good idea, unless the array will have a known fixed length.
You can take a look at PaymentSplitter for a pull-based model that implements basically the same thing you’re trying to do.
  
  
    
    // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Address.sol";
import "../utils/Context.sol";
import "../utils/math/SafeMath.sol";
/**
 * @title PaymentSplitter
 * @dev This contract allows to split Ether payments among a group of accounts. The sender does not need to be aware
 * that the Ether will be split in this way, since it is handled transparently by the contract.
 *
 * The split can be in equal parts or in any other arbitrary proportion. The way this is specified is by assigning each
 * account to a number of shares. Of all the Ether that this contract receives, each account will then be able to claim
 * an amount proportional to the percentage of total shares they were assigned.
 *
 * `PaymentSplitter` follows a _pull payment_ model. This means that payments are not automatically forwarded to the
 * accounts but kept in this contract, and the actual transfer is triggered as a separate step by calling the {release}
 * function.
show original 
   
  
    
    
  
  
 
             
            
              
            
           
          
            
            
              You’re right. That’s perfect for my problem. How do I use it alongside my contract? Import it and call the events? I’ve never used contracts together like this.
             
            
              1 Like 
            
            
           
          
            
            
              It’s a standalone contract. You deploy it and then you send ETH to it, or the native token in whatever chain you’re on. It does not work with ERC20, you would have to write a similar one for that.
             
            
              1 Like