-
Notifications
You must be signed in to change notification settings - Fork 4
Units and globally available variables
There are some specific variables and functions in Solidity and Ligo that are commonly used for smart contract development. The list of such Solidity entities can be found in the appropriate article. And current page discuss their counterparts in Ligo.
Ether and Tez have different precision. The smallest part of Ethereum is wei, 1ether == 1e18wei, meanwhile, the smallest part of Tez is mutez, 1tez = 1e6mutez. So we use the following convention:
szabo => 1mutez
finney => 1_000mutez
ether => 1_000_000mutez
In the solidity time is calculated based on the assumption that 1 second sequels 1. Then for Ligo the logic is the same.
1 seconds => 1
1 minutes => 60
1 hours => 3600
1 days => 86400
1 weeks => 604800
Not all variables are presented on Ligo. Currently, only the following ones can be transpiled:
msg.sender => sender
tx.origin => source
block.timestamp => now
msg.value => amount
now => now
And other parametrs are not accesible in the contract:
blockhash(uint blockNumber)
block.blockhash(uint blockNumber)
block.coinbase
block.difficulty
block.gaslimit
block.number
gasleft()
msg.data
msg.sig
msg.gas
tx.gasprice
abi.decode => bytes_unpack
abi.encode => bytes_pack
abi.encodePacked => bytes_pack
abi.encodeWithSelector => bytes_pack
abi.encodeWithSignature => bytes_pack
assert(bool condition) => if condition then skip else failwith(string error_msg)
require(bool condition) => if condition then skip else failwith(string error_msg)
revert() => failwith(string error_msg)
Note: other dialects allow assert syntax.
Ligo doesn't support all solidity mathematical functions:
addmod(uint x, uint y, uint k) => (x + y) % k
mulmod(uint x, uint y, uint k) => (x * y) % k
sha256(bytes memory) => sha_256
Not supported:
ecrecover(bytes msg, bytes32 v, bytes32 r, bytes32 s) => address (may be replaced with crypto_check(pk: key, signed: signature, msg: bytes) => bool)
keccak256
ripemd160
sha3 (may be replaced with blake2b)
Allowed Solidity actions:
<address payable>.transfer(uint256 amount)
Partially supported actions:
<address>.balance => balance (of current contract only)
Unsupported actions:
<address payable>.send(uint256 amount)
<address>.call(bytes memory)
<address>.staticcall(bytes memory)
<address>.delegatecall(bytes memory)
address(this) => self_address
this => get_contract(self_address)
Destruct functions (suicide
, selfdestruct
) are not supported by Ligo.