Smart Contracts Playground - Functions
Since 1.3, we introduced the capability to have some public functions in to smart contract code.
The playground have been updated to support this feature and be able to test it by calling those functions.
Let's create a small smart contract that use function to export some data to the user
@version 1
condition triggered_by: transaction, on: increment(), as: []
actions triggered_by: transaction, on: increment() do
counter = String.to_number(contract.content) + 1
Contract.set_content String.from_number(counter)
end
export fun counter() do
Json.to_string([counter: contract.content])
end
Firstly, we initiate a transaction to increment the counter and update the contract
Now to test the function, we are going to open the function panel by clicking on the function button:
We can see the function panel on the left with the list of function availables to be called
After clicking on "Execute", we can see in the console the return of the function