Skip to content

Units and globally available variables

Julian Konchunas edited this page Aug 31, 2020 · 1 revision

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 Units

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

Time Variables

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

Block and Transaction Properties

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 Encoding and Decoding Functions

abi.decode => bytes_unpack
abi.encode => bytes_pack
abi.encodePacked => bytes_pack
abi.encodeWithSelector => bytes_pack
abi.encodeWithSignature => bytes_pack

Error Handling

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.

Mathematical and Cryptographic Functions

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)

Members of Address Types

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)

Contract Related

address(this) => self_address
this => get_contract(self_address)

Destruct functions (suicide, selfdestruct) are not supported by Ligo.