# Help transfering a percentage of an amount to addresses in an array by their amounts

**URL:** <https://forum.openzeppelin.com/t/help-transfering-a-percentage-of-an-amount-to-addresses-in-an-array-by-their-amounts/9431>\
**Category:** Support\
**Tags:** erc20\
**Created:** [May 29, 2021, 4:39pm UTC](https://forum.openzeppelin.com/t/help-transfering-a-percentage-of-an-amount-to-addresses-in-an-array-by-their-amounts/9431 "2021-05-29T16:39:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scwolves10](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/scwolves10/32/6034_2.png) [@scwolves10](https://forum.openzeppelin.com/u/scwolves10)\
**Post date:** [May 29, 2021, 4:39pm UTC](https://forum.openzeppelin.com/t/help-transfering-a-percentage-of-an-amount-to-addresses-in-an-array-by-their-amounts/9431/1 "2021-05-29T16:39:18Z")

</div>

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:  
User1 has 25  
User2 has 25  
User2 has 50  
Total of 100

Amount sent 10  
User1 gets 2.5  
User2 gets 2.5  
User2 gets 5

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:

> [@Help with calculating rewards for addresses during transfer](https://forum.openzeppelin.com/t/help-with-calculating-rewards-for-addresses-during-transfer/9399):
>
> 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](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…

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [May 29, 2021, 9:43pm UTC](https://forum.openzeppelin.com/t/help-transfering-a-percentage-of-an-amount-to-addresses-in-an-array-by-their-amounts/9431/2 "2021-05-29T21:43:02Z")

</div>

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.

> <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/adc50d465cb028841ac3017a802788126c352874/contracts/finance/PaymentSplitter.sol>

---

<div class="post-metadata">

**Author:** ![scwolves10](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/scwolves10/32/6034_2.png) [@scwolves10](https://forum.openzeppelin.com/u/scwolves10)\
**Post date:** [May 30, 2021, 1:39am UTC](https://forum.openzeppelin.com/t/help-transfering-a-percentage-of-an-amount-to-addresses-in-an-array-by-their-amounts/9431/3 "2021-05-30T01:39:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![frangio](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/frangio/32/15251_2.png) [@frangio](https://forum.openzeppelin.com/u/frangio)\
**Post date:** [May 30, 2021, 2:51am UTC](https://forum.openzeppelin.com/t/help-transfering-a-percentage-of-an-amount-to-addresses-in-an-array-by-their-amounts/9431/4 "2021-05-30T02:51:04Z")

</div>

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.
