Skip to main content
Experimental TechnologyThe 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 Functions

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.

Signature Verification

checkSig

Verifies a signature against a public key:
Parameters:
  • signature: The signature to verify
  • pubkey: The public key to verify against
Returns:
  • bool: True if the signature is valid, false otherwise
Example:

checkMultisig

Verifies multiple signatures against multiple public keys:
Parameters:
  • pubkeys: Array of public keys
  • signatures: Array of signatures
Returns:
  • bool: True if all signatures are valid, false otherwise
Example:

checkSigFromStack

Verifies a signature against a message and public key:
Parameters:
  • signature: The signature to verify
  • pubkey: The public key to verify against
  • message: The message that was signed
Returns:
  • bool: True if the signature is valid, false otherwise
Example:

Hash Functions

sha256

Computes the SHA-256 hash of data:
Parameters:
  • data: The data to hash
Returns:
  • bytes32: The SHA-256 hash
Example:

ripemd160

Computes the RIPEMD-160 hash of data:
Parameters:
  • data: The data to hash
Returns:
  • bytes20: The RIPEMD-160 hash
Example:

hash160

Computes the Hash160 (SHA-256 followed by RIPEMD-160) of data:
Parameters:
  • data: The data to hash
Returns:
  • bytes20: The Hash160 result
Example:

hash256

Computes the double SHA-256 hash of data:
Parameters:
  • data: The data to hash
Returns:
  • bytes32: The double SHA-256 hash
Example:

Timelock Functions

checkLockTime

Verifies that the transaction’s locktime meets a requirement:
Parameters:
  • locktime: The minimum required locktime
Returns:
  • bool: True if the transaction’s locktime is greater than or equal to the specified locktime
Example:

checkSequence

Verifies that the input’s sequence number meets a requirement:
Parameters:
  • sequence: The minimum required sequence
Returns:
  • bool: True if the input’s sequence is greater than or equal to the specified sequence
Example:

Conversion Functions

int2bytes

Converts an integer to a byte array:
Parameters:
  • value: The integer to convert
Returns:
  • bytes: The byte representation of the integer
Example:

bytes2int

Converts a byte array to an integer:
Parameters:
  • bytes: The byte array to convert
Returns:
  • int: The integer value
Example:

Script Generation

new P2PKH

Creates a Pay-to-Public-Key-Hash (P2PKH) script:
Parameters:
  • pubkey: The public key to create the script for
Returns:
  • bytes: The P2PKH script
Example:

new P2SH

Creates a Pay-to-Script-Hash (P2SH) script:
Parameters:
  • redeemScript: The redeem script to hash
Returns:
  • bytes: The P2SH script
Example:

new P2WPKH

Creates a Pay-to-Witness-Public-Key-Hash (P2WPKH) script:
Parameters:
  • pubkey: The public key to create the script for
Returns:
  • bytes: The P2WPKH script
Example:

new P2WSH

Creates a Pay-to-Witness-Script-Hash (P2WSH) script:
Parameters:
  • witnessScript: The witness script to hash
Returns:
  • bytes: The P2WSH script
Example:

new P2TR

Creates a Pay-to-Taproot (P2TR) script:
Parameters:
  • internalKey: The internal key for the Taproot output
  • scriptTree (optional): The script tree for the Taproot output
Returns:
  • bytes: The P2TR script
Example:

Key Functions

tweakKey

Tweaks a public key with a value:
Parameters:
  • pubkey: The public key to tweak
  • tweak: The value to tweak with
Returns:
  • pubkey: The tweaked public key
Example:

aggregateKeys

Aggregates multiple public keys into a single key:
Parameters:
  • pubkeys: Array of public keys to aggregate
Returns:
  • pubkey: The aggregated public key
Example:

Array Functions

length

Returns the length of an array:
Example:

concat

Concatenates two arrays:
Parameters:
  • array1: The first array
  • array2: The second array
Returns:
  • Array containing all elements from both input arrays
Example:

Utility Functions

require

Enforces a condition, failing if it’s not met:
Parameters:
  • condition: The condition to check
  • message (optional): Error message if the condition fails
Example:

min

Returns the minimum of two values:
Parameters:
  • a: First value
  • b: Second value
Returns:
  • The smaller of the two values
Example:

max

Returns the maximum of two values:
Parameters:
  • a: First value
  • b: Second value
Returns:
  • The larger of the two values
Example:

Advanced Functions

verifyTaprootSignature

Verifies a Taproot signature:
Parameters:
  • signature: The signature to verify
  • pubkey: The public key to verify against
  • message: The message that was signed
  • leafHash: The leaf hash for the Taproot script path
Returns:
  • bool: True if the signature is valid, false otherwise
Example:

computeMerkleRoot

Computes a Merkle root from a list of hashes:
Parameters:
  • hashes: Array of hashes to include in the Merkle tree
Returns:
  • bytes32: The Merkle root
Example:

Conclusion

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 Compiler documentation.