messages
is a template of the response transaction that will be generated by the AA. It follows the structure of a regular Obyte transaction but its sections between curly braces {} contain code that makes the resulting transaction dependent on the triggering (activating) transaction. This is similar to how PHP code can be inserted into HTML to make the resulting page dependent on the request. The language autonomous agents are written in is called Oscript.trigger.address
is the address of the sender who activated the AA. trigger.output
allows to find the amounts in different currencies sent to the AA, trigger.output[[asset=base]]
is the amount in the base asset -- bytes.payment
. At least one payment is mandatory in every transaction, it is necessary to at least pay fees. Another app is data
. This type of message delivers an arbitrary json object that can contain any data:payload
is the data this message delivers.trigger.data
and its action can depend on the data received:trigger.data.withdrawal_amount
bytes back to the sender. withdrawal_amount
is a field in the data message of the triggering transaction:withdrawal_amount
is greater than the balance that the AA has (including the amount received from the triggering transaction), the AA's response will fail. When an AA fails to handle a trigger transaction for any reason, it rolls back all changes and attempts to send back to sender all the received funds, in all assets, less the bounce fees. By default, the bounce fees are 10000 bytes for "base" asset and 0 for all other assets. This is also the minimum. The default can be overridden by adding a bounce_fees
field in the autonomous agent definition:"n9y3VomFeWFeZZ2PcSEcmyBb/bI7kzZduBJigNetnkY="
if it has to bounce back a triggering transaction. Sending less than 20000 bytes to the AA will result in the AA silently eating the coins (they are not enough even for the bounce fees). When non-zero amount of asset "n9y3VomFeWFeZZ2PcSEcmyBb/bI7kzZduBJigNetnkY="
is sent to the AA, it should also be at least 100, otherwise the AA eats the coins.payment
is the most common message but other messages can be sent as well by any address, AA included.data_feed
messages, data
messages:trigger.data
will be expanded into an object and added as value of initial_data
field.JVUJQ7OPBJ7ZLZ57TTNFJIC3EW7AE2RY
) happens to be an AA, its execution will start only after the execution of the current AA is finished. There is no reentrancy issue.||
is the operator for string concatenation.data
.!
is a logical NOT
operator;otherwise
is an operator that returns the first operand if it is truthy (anything except false, 0, and empty string) or the second operand otherwise;cap
parameter is not passed then cap
in payload
evaluates to an empty string, therefore cap
is removed from asset definition and an asset with infinite supply will be defined;attestor1
, attestor2
, attestor3
fields was set, the attestors
array becomes empty and will be excluded from the final definition.7XZSBB32I5XPIAVWUYCABKO67TZLHKZW
if Charlotte Hornets won and to FDZVVIOJZZVFAP6FLW6GMPDYYHI6W4JG
otherwise TKT4UESIKTTRALRRLWS4SENSTJX6ODCW
is the address of a sports oracle that posts the results of sports events.amount
field in the output is omitted, which means that the entire AA balance will be paid out.JEDZYC2HMGDBIDQKG3XSTXUSHMCBK725
and his Steem reputation is at least 50. Otherwise, it "pays" 0 bytes. Trying to pay 0 amount results in the output being removed. Since it is the only output in this case and it is removed, the resulting response transaction would produce no effect, therefore it is not created at all.var
to access and assign state variables:state
. This message must have a single other field called state
which is a set of Oscript statements. These statements are allowed to assign state variables. The state message is not included in the final response transaction, it can only affect state by modifying the state variables.var
is accessed, it evaluates to false
.if
field in the first message. When var['previous_address']
is not initialized yet (first call), the if
oscript evaluates to false
and the entire first message is excluded from the transaction.if
field. If the Oscript in the if
evaluates to true or any truthy value (anything except false, 0, and empty string), the enclosing object is included in the final response, otherwise, it is excluded.if
field itself is of course always removed from the final response.if
, any object can have an init
field that includes initialization code:;
) whose value becomes the value of the Oscript.if
(if it is present and evaluated to true
of course) and before everything else. It is often used to set local constants that are used later.if
and init
are also available in all other Oscripts of the current and nested objects. In the above example, $amount1
and $amount2
were set in init
of the message object, and they are used in payload/outputs/output-0/amount of this message.if
are also available in the corresponding init
.cases
:messages
array is replaced with an object with a single element called cases
. cases
is an array that lists several mutually exclusive alternatives. Every alternative except the last must have an if
field. The first alternative whose if
evaluates to true
defines the messages
that will take the place of the higher-level messages
field.if
s may not be mutually exclusive but the alternative that is listed earlier in the list takes precedence. Only one alternative is always taken.trigger.data
has no define
field but has a truthy issue
field, the 2nd alternative is selected, and the original object folds into:if
, init
, and local constants, applies to cases
as well.return
.return
in a return-value Oscript, it must return a value:return
in a statements-only Oscript, such as init, doesn't return any value, it just interrupts the script:bounce
:require
:timestamp
is roughly the current timestamp (number of seconds since Jan 1, 1970 00:00:00 UTC).