Wie kann ich einen Vertrag veranlassen, einen Prozentsatz (immer) an eine bestimmte Brieftasche zu senden? Beispiel: Jedes Mal, wenn eine Transaktion von diesem Token durchgeführt wird, gehen die 1 % an die X-Brieftasche.
Danke schön.
Ok, Felix Dolderer, danke, dass du das für mich getan hast, Bruder, ich weiß das wirklich zu schätzen.
Ich weiß nicht, in welchen Teil des Codes Sie den bereits programmierten Code einfügen.
Schauen Sie, ich hinterlasse meinen ursprünglichen Vertrag in diesem Link. Wie kann ich Ihren Code in diesen Vertrag integrieren? Können Sie den Code, den Sie für mich erstellen, in 2 Beispiele (Vertrag1 und Vertrag2) integrieren?
CODE MEINES VERTRAGES https://pastebin.com/MEmaiVh1
Danke
Ich habe zwei Verträge für Sie vorbereitet, weil ich nicht weiß, welchen Fall Sie zu modellieren versuchen.
Der erste Vertrag funktioniert in der Situation, dass Ihr Vertrag direkt Ether erhält und ein Teil dieses Ethers an Ihre Zieladresse (X-Wallet) weitergeleitet wird.
Der zweite Vertrag ist ein Token-Vertrag. Bei jeder Übertragung von Token wird ein Teil der Übertragung an Ihre Zieladresse weitergeleitet.
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
}
}
Zweiter Vertrag:
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);
}
}
gute Stimmung