Smart Contract Triggers

A smart contract trigger is a mechanism that triggers the execution of smart contracts. There are four triggers introduced in the NEO smart contract，Verification, Application， VerificationR, and ApplicationR.

Verification

A validation trigger is used to call the contract as a verification function, which can accept multiple parameters and should return a valid Boolean value, indicating the validity of the transaction or block.

When you transfer assets from account A to account B, a verification contract is triggered. All the nodes that received the transaction (including normal nodes and blue consensus nodes) verify account A's contract. If the return value is true, the transfer is completed successfully. If false is returned, the transfer is failed.

If the execution of the verification contract is failed, the transaction will not be recorded in the blockchain.

The following is a code sample of a simple verification contract. When condition A is met, it returns true, indicating the transfer is successful. Otherwise, it returns false, indicating the transfer is failed.

Based on the above code, the following code adds a condition to determine the running trigger type. Only when the trigger is a verification trigger, the verification part of the code is executed. This is useful for complex smart contracts. If a smart contract implements multiple triggers, the trigger should be evaluated in the Main method.

Unlike the verification trigger which is triggered by a transfer, an application trigger is triggered by a special transaction InvocationTransaction. If the application (Web/App) calls a smart contract, an InvocationTransaction is constructed, and then signed and broadcast in the program. After the InvocationTransaction transaction is confirmed, the smart contract is executed by the consensus node. The common node does not execute the smart contract when forwarding the transaction.

Since the application contract is executed after InvocationTransaction is confirmed, the transaction is recorded in the blockchain no matter the execution of the application contract is successful or not.

The success and failure of InvocationTransaction is not necessarily related to the success or failure of execution of smart contracts.