Built-in functions and operations in Arkade Script
Experimental Technology
The Arkade Language is experimental technology in active development. All code and examples presented here are for exploration and proof of concept purposes only. Do not use in production environments.
Arkade Script provides a comprehensive set of built-in functions for common operations in Bitcoin smart contracts. These functions abstract away the complexity of Bitcoin Script while providing powerful capabilities for contract development.
Verifies a signature against a public key:
Parameters:
signature
: The signature to verifypubkey
: The public key to verify againstReturns:
bool
: True if the signature is valid, false otherwiseExample:
Verifies multiple signatures against multiple public keys:
Parameters:
pubkeys
: Array of public keyssignatures
: Array of signaturesReturns:
bool
: True if all signatures are valid, false otherwiseExample:
Verifies a signature against a message and public key:
Parameters:
signature
: The signature to verifypubkey
: The public key to verify againstmessage
: The message that was signedReturns:
bool
: True if the signature is valid, false otherwiseExample:
Computes the SHA-256 hash of data:
Parameters:
data
: The data to hashReturns:
bytes32
: The SHA-256 hashExample:
Computes the RIPEMD-160 hash of data:
Parameters:
data
: The data to hashReturns:
bytes20
: The RIPEMD-160 hashExample:
Computes the Hash160 (SHA-256 followed by RIPEMD-160) of data:
Parameters:
data
: The data to hashReturns:
bytes20
: The Hash160 resultExample:
Computes the double SHA-256 hash of data:
Parameters:
data
: The data to hashReturns:
bytes32
: The double SHA-256 hashExample:
Verifies that the transaction’s locktime meets a requirement:
Parameters:
locktime
: The minimum required locktimeReturns:
bool
: True if the transaction’s locktime is greater than or equal to the specified locktimeExample:
Verifies that the input’s sequence number meets a requirement:
Parameters:
sequence
: The minimum required sequenceReturns:
bool
: True if the input’s sequence is greater than or equal to the specified sequenceExample:
Converts an integer to a byte array:
Parameters:
value
: The integer to convertReturns:
bytes
: The byte representation of the integerExample:
Converts a byte array to an integer:
Parameters:
bytes
: The byte array to convertReturns:
int
: The integer valueExample:
Creates a Pay-to-Public-Key-Hash (P2PKH) script:
Parameters:
pubkey
: The public key to create the script forReturns:
bytes
: The P2PKH scriptExample:
Creates a Pay-to-Script-Hash (P2SH) script:
Parameters:
redeemScript
: The redeem script to hashReturns:
bytes
: The P2SH scriptExample:
Creates a Pay-to-Witness-Public-Key-Hash (P2WPKH) script:
Parameters:
pubkey
: The public key to create the script forReturns:
bytes
: The P2WPKH scriptExample:
Creates a Pay-to-Witness-Script-Hash (P2WSH) script:
Parameters:
witnessScript
: The witness script to hashReturns:
bytes
: The P2WSH scriptExample:
Creates a Pay-to-Taproot (P2TR) script:
Parameters:
internalKey
: The internal key for the Taproot outputscriptTree
(optional): The script tree for the Taproot outputReturns:
bytes
: The P2TR scriptExample:
Tweaks a public key with a value:
Parameters:
pubkey
: The public key to tweaktweak
: The value to tweak withReturns:
pubkey
: The tweaked public keyExample:
Aggregates multiple public keys into a single key:
Parameters:
pubkeys
: Array of public keys to aggregateReturns:
pubkey
: The aggregated public keyExample:
Returns the length of an array:
Example:
Concatenates two arrays:
Parameters:
array1
: The first arrayarray2
: The second arrayReturns:
Example:
Enforces a condition, failing if it’s not met:
Parameters:
condition
: The condition to checkmessage
(optional): Error message if the condition failsExample:
Returns the minimum of two values:
Parameters:
a
: First valueb
: Second valueReturns:
Example:
Returns the maximum of two values:
Parameters:
a
: First valueb
: Second valueReturns:
Example:
Verifies a Taproot signature:
Parameters:
signature
: The signature to verifypubkey
: The public key to verify againstmessage
: The message that was signedleafHash
: The leaf hash for the Taproot script pathReturns:
bool
: True if the signature is valid, false otherwiseExample:
Computes a Merkle root from a list of hashes:
Parameters:
hashes
: Array of hashes to include in the Merkle treeReturns:
bytes32
: The Merkle rootExample:
These built-in functions provide the building blocks for creating sophisticated Bitcoin smart contracts with Arkade Script. By combining these functions with the language’s syntax and type system, you can create secure and efficient contracts for a wide range of use cases.
For more advanced use cases, you may also need to use the new opcodes described in the Arkade Script documentation.