...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Saturday, February 10, 2018

Solidity and Truffle Tips and Tricks - overriding built-in functions


Some items in solidity like the type address has a couple of built in function for transferring ether or querying balance. The functions are the followings:

<address>.balance (uint256):
balance of the Address in Wei

<address>.transfer(uint256 amount):
send given amount of Wei to Address, throws on failure

<address>.send(uint256 amount) returns (bool):
send given amount of Wei to Address, returns false on failure
 
you can not make inheritance from a built in type, however what you can do is to define the same functions in a custom class, indirectly overwriting these functions. 

contract ExtAddress{

  function balance (uint256){
  }

  function transfer(uint256 amount){
  }

  function send(uint256 amount) returns (bool){
  }
}

They do not directly overwrite the address functions, however in certain situations the functions can be exchanged for the first site.