rawstate
Manually Maintain Mutable State
One way to implement state in contract is dividing the contract in the locking script into two parts: data and code. Data part is the state. Code part contains the business logic of a contract that encodes rules for state transition.
sCrypt offers stateful contracts. Let us look at a simple example of a stateful contract: a counter contract tracking how many times its function increment() has been called. Its code is shown below with comments inline.
OP_RETURN data of the contract locking script can be accessed by using an accessor named dataPart, for example:
After that, the counter.lockingScript would include the data part automatically. You can use it to calculate preimage.
If you want to access the code part of the contract's locking script including the trailing OP_RETURN, use:
Last updated