0

how can I make a contract send a percentage to a specific wallet (always)? Example that whenever a transaction is made from this token the 1% go to X wallet.

Thank you.

Ok felix dolderer thanks for do this for me brother a really apreciate this.

I dont know in what part of code put the code you already programed please.

look i leave my original actual contracto in this link how can i integrate your code to this contract please, can you integrate the code you do for me in 2 examples (contract1 & contract2) ??

CODE OF MY CONTRACT https://pastebin.com/MEmaiVh1

thanks

  • Please share your code, your thoughts, your progress and the specific point of the problem which you are trying to solve (assuming that you are indeed trying to solve it). – goodvibration Dec 1 '18 at 9:39
0

I prepared two contracts for you, because I don't know which case you are trying to model.

The first contract works in the situation that your contract directly receives ether and a portion of that ether will be forwarded to your target address (X wallet).

The second contract is a token contract. With every transfer of tokens a portion of the transfer will be forwarded to your target address.

pragma solidity ^0.5.0;

contract PercentageEther{

    // Pay the 1% to this address
    address payable target = 0x158de12EE547EAe06Cbdb200A017aCa6B75D230D;

    // Deal with incoming ether 
    function () payable external{
        //Send 1% to the target
        target.transfer(msg.value/100);

        //Do whatever you want to do with the rest
    }

}

Second contract:

pragma solidity ^0.5.0;

contract PercentageToken{

    // Pay the 1% to this address
    address payable target = 0x158de12EE547EAe06Cbdb200A017aCa6B75D230D;

    // necessary variables for your token
    mapping (address => uint) public balanceOf;
    uint public totalSupply;

    // create a token with a specified supply and assign all the tokens to the creator
    constructor(uint _totalSupply) public {
        totalSupply = _totalSupply;
        balanceOf[msg.sender] = totalSupply;
    }

    // your standard token transfer function with the addition of the share that
    // goes to your target address
    function transfer(address _to, uint amount) public {

        // calculate the share for your target address
        uint shareForX = amount/100;

        // store the previous balance of the sender for later assertion
        // (check that all works as intended)
        uint senderBalance = balanceOf[msg.sender];
        // check the sender actually has enough tokens to send
        require(senderBalance >= amount);
        // reduce sender balance first to avoid that the sender sends more than
        // he owns by submitting multiple transactions.
        balanceOf[msg.sender] -= amount;
        // store the previous balance of the receiver for later assertion
        // (check that all works as intended)
        uint receiverBalance = balanceOf[_to];

        // add the amount of tokens to the receiver but deduce the share for your
        // target address
        balanceOf[_to] += amount-shareForX;
        // add the share to your target address
        balanceOf[target] += shareForX;

        // check that everything works as intended, specifically checking that
        // the sum of tokens in all reladed accounts is the same before and after
        // the transaction. 
        assert(balanceOf[msg.sender] + balanceOf[_to] + shareForX ==
            senderBalance + receiverBalance);
    }
}
  • Hello felix please check my updated question.. – upracha Dec 1 '18 at 15:37
  • StackExchange is not really about implementing solutions for others, it's about answering general questions and problems. For you, the second contract in my answer is relevant. Just look at the function transfer and add all lines where shareForX is mentioned to your transfer and transferFrom functions. (You can ignore the line that begins with assert) – Felix Dolderer Dec 1 '18 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.