How Can We Help?
Smart contract example: Stateful contract for loan matching
A stateful contract can also be used to implement similar functionality for a lending platform.
Unlike the stateless contract example, transactions in this example with the proper input will not always be valid. If all the proper inputs are provided, the transaction will be valid if the contract is in the active state, but the transaction will not be valid if the contract is in the intermediate state.
When a transaction is confirmed, it updates the smart contract state. Similar to an account, a stateful contract has an active state and references a smart contract program (static definition object on the ledger) that describes how transactions update the state. Since there is an intermediate state, the contract is able to gain some additional functionality. For example, it can be used to register inputs in the order the contract receives them, so that loan request from B is added to the contract first before the loan pledge from A is sent to the contract. The verification process must retrieve the intermediate states. This is harder for stateless validators (in Phase II) to process.