Skip to content

Instantly share code, notes, and snippets.

@traderbagel
Created September 4, 2018 16:04
Show Gist options
  • Save traderbagel/51d6832e4104193825025246bc24e6d4 to your computer and use it in GitHub Desktop.
Save traderbagel/51d6832e4104193825025246bc24e6d4 to your computer and use it in GitHub Desktop.
bnb_transfer_solidity
/* event定義中的 keyword `indexed` 會被放在 topics當成參數做查詢, topics最多有四個, 第一個保留為 event的 hash值(識別用) */
event Transfer(address indexed from, address indexed to, uint256 value);
/* Send coins */
function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment