Home Bitcoin blockchain – How transactions script work?

blockchain – How transactions script work?

0
blockchain – How transactions script work?

[ad_1]

You possibly can consider a “locking script” as operate definition, and the “unlocking script” as operate arguments that may make the operate consider to true.

The generally used P2PKH handle is mostly a little program connected to the UTXO which has a operate definition like f_p2pkh(public_key, signature, sighash_flags). An UTXO retains some BTC locked with that operate. The spender then creates a transaction which references a specific occasion of the operate f_p2pkh and offers the three arguments public_key, signature, and sighash_flags.

Right here the operate definition hard-codes the general public key hash so you may’t signal with any key however should use the particular key outlined as a continuing within the operate itself.

However what “message” does the signature signal? The operate will name a local operate (OP_CHECKSIG) which constructs a message from the transaction context it is being spent in utilizing the instruction encoded within the “sighash_flag” argument. This lets the spender not simply unlock the UTXO but additionally determine precisely the place the unlocked BTC can transfer to (new outputs).

The signature “message” is constructed from the transaction physique in keeping with supported recipes, encoded by sighash flags. With P2PKH, the spender will get to decide on the recipe – which permits for some flexibility in what outputs to require: SIGHASH_ALL, SIGHASH_NONE, SIGHASH_SINGLE, and in addition offers signer the choice to permit others so as to add extra inputs by utilizing SIGHASH_ANYONECANPAY.

Every UTXO is sort of a little field that holds some BTC and locked with a sensible lock, and our operate definition is the lock’s firmware, and the firmware can “see” different components of the transaction. We spend by feeding the good lock the data required to open, which then releases the BTC and strikes it to some new containers.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here