123456788940 / AAVENOMICS

0 stars 0 forks source link

TokenDistribution.sol #1

Open 123456788940 opened 8 months ago

123456788940 commented 8 months ago

// SPDX-License-Identifier: MIT pragma solidity ^0.8;

import "./erc20.sol";

contract tokenDistribution { erc20 public token; address[] public beneficiaries;

constructor(address _tokenAddress, address[] memory _beneficiaries) {
    token = erc20(_tokenAddress);
    beneficiaries = _beneficiaries;

}

function distributeTokens() external {
    require(beneficiaries.length > 0, "No beneficiaries specified");
    uint totalTokens = token.balanceOf(address(this));
    uint tokensPerBeneficiary = totalTokens/beneficiaries.length;
    for (uint i = 0; i < beneficiaries.length; i++) {
        token.transfer(beneficiaries[i], tokensPerBeneficiary);

    }
}

function addBeneficiary(address newBeneficiary) external {
    beneficiaries.push(newBeneficiary);
}

function getBeneficiary() external view returns(address[] memory) {
    return beneficiaries;
}

}

123456788940 commented 8 months ago

Token Distribution Contract

This Solidity smart contract, named tokenDistribution, facilitates the distribution of ERC-20 tokens among a list of beneficiaries. The contract accepts the ERC-20 token's address and an array of beneficiary addresses during deployment. The main functionalities include:

  1. Constructor:

    • Initializes the contract with the ERC-20 token address and an array of beneficiary addresses.
  2. Distribute Tokens:

    • The distributeTokens function equally distributes the available tokens among the specified beneficiaries.
  3. Add Beneficiary:

    • The addBeneficiary function allows adding new beneficiaries to the distribution list.
  4. Get Beneficiaries:

    • The getBeneficiaries function retrieves the list of current beneficiaries.

Usage:

  1. Deploy the contract with the ERC-20 token address and an initial list of beneficiaries.
  2. Execute the distributeTokens function to distribute tokens equally among the beneficiaries.
  3. Add new beneficiaries using the addBeneficiary function as needed.
  4. Retrieve the current list of beneficiaries with the getBeneficiaries function.

Ensure that you have the necessary permissions and provide ample gas when interacting with the contract on the Ethereum blockchain. Customize the contract based on your specific token distribution requirements.