Chapter 16 : Built-ins
We need a Flux Capacitor, don’t ask me why, you wouldn’t get it. Just buy it!
A LIGO smart contract can query part of the state of the Tezos blockchain by means of built-in values. In this section you will find how those built-ins can be utilized.
A few built-ins
Tezos.balance : Get the balance for the contract.
Tezos.amount : Get the amount of tez provided by the sender to complete this transaction.
Tezos.sender : Get the address that initiated the current transaction.
Tezos.self_address : Get the address of the currently running contract.
Tezos.source : Get the originator (address) of the current transaction. That is, if a chain of transactions led to the current execution get the address that began the chain. Not to be confused with Tezos.sender, which gives the address of the contract or user which directly caused the current transaction.
Tezos.chain_id : Get the identifier of the chain to distinguish between main and test chains.
ℹ️ A more complete list is available on ligolang.org
The keyword failwith throws an exception and stop the execution of the smart contract
This example shows how Tezos.source can be used to deny access to an entrypoint.
const owner : address = (“tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx”: address);
function main (const action : parameter; const store : storage) : return is
if Tezos.source =/= owner then (failwith (“Access denied.”) : return)
else ((nil : list (operation)), store)
<string_message> must be a string value
1- Check that the originitor address is indeed our ship_address, or fail with “Access denied”
2- Check that the sent amount corresponds to the purchase_price, or fail with “Incorrect amount”
Type your solution above and validate your answer