Building a custom script

As mentioned before, we can define our own scripts instead of using the standards. In the following example, we will define a non-standard bitcoin script based on a simple equation, X+13=15. Therefore, to spend our transaction, the recipient needs to come up with a ScriptSig presenting the correct solution, which is obviously 2, in order to solve the equation and spend the output.

If we translate this equation into bitcoin scripts, we get the following:

Locking Script (ScriptPubKey): "x+13=15"

OP_X OP_13 OP_ADD OP_15 OP_EQUAL

Unlocking Script (ScriptSig): "2"

OP_2

Bitcore enables us to create transactions with custom script. Hence, in the following example, we will create a non-standard transaction ...

Get Blockchain By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.