# make a contract send a percentage to a specific wallet (always)

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

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

// 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

// 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
function transfer(address _to, uint amount) public {

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)

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