¿Cómo puedo hacer que un contrato envíe un porcentaje a una billetera específica (siempre)? Ejemplo de que cada vez que se realiza una transacción desde este token, el 1% va a la billetera X.
Gracias.
Ok, felix dolderer, gracias por hacer esto por mí, hermano, realmente lo aprecio.
No sé en qué parte del código poner el código que ya programó por favor.
mira, dejo mi contrato real original en este enlace, ¿cómo puedo integrar tu código a este contrato, por favor, puedes integrar el código que haces para mí en 2 ejemplos (contrato 1 y contrato 2)?
CÓDIGO DE MI CONTRATO https://pastebin.com/MEmaiVh1
gracias
Preparé dos contratos para ti, porque no sé qué caso estás tratando de modelar.
El primer contrato funciona en la situación en la que su contrato recibe ether directamente y una parte de ese ether se reenviará a su dirección de destino (billetera X).
El segundo contrato es un contrato simbólico. Con cada transferencia de tokens, una parte de la transferencia se reenviará a su dirección de destino.
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
}
}
Segundo contrato:
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);
}
}
buena vibración