Help with rewards distribution

I'm trying to create a simple token where it's only function is to calculate how much usdc is in my wallet and distribute the usdc evenly across all token holder. Ideally it would calculate once a week and distribute the rewards over the week slowly. I am very new to this and any help would be greatly appreciated.

:1234: Code to reproduce


:computer: Environment

Hi,

Let's take this step by step and see what we can do.

I'm trying to create a simple token

Since it's a token, I'm assuming it's a fungible token and therefore can benefit by implementing ERC 20 standard.

where it's only function

The ERC 20 has some additional functions, you might need to mute them off by overriding without a definition.

calculate how much usdc is in my wallet

All ERC 20 standards (including USDC) has a balanceOf that you can use to find the balance. You can create a function to find the balanceOf your address.

distribute the usdc evenly across all token holder

First, you need to store the holders in an array or mapping. Whatever is comfortable for you to enter and retrieve data.

Secondly, I don't recommend allowing the contract to transfer on behalf of an EOA (Externally Owned Account - Non Contract account) but rather do them all in the contract itself. (Make sure to implement a withdraw function), but if you don't, then you need to Approve the USDC contract to transfer tokens via the newly created contract on your behalf.
The two functions you should check are :

function approve(address _spender, uint256 _value) public returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);

Ideally it would calculate once a week and distribute the rewards over the week slowly

There aren't really timed events you can implement from the contract itself, but you can make sure the function gets called per week by implementing a caller using JS, python or anything.

I hope that helped you in getting started.

1 Like