Skip to content

Instantly share code, notes, and snippets.

@ordishs
ordishs / snippet-blackjack.ts
Created March 5, 2026 11:50
BlackjackBet contract in Rúnar
class BlackjackBet extends StatefulSmartContract {
readonly playerPubKey: PubKey;
readonly housePubKey: PubKey;
readonly oraclePubKey: RabinPubKey;
readonly betAmount: bigint;
// ...
public settleBlackjack(outcomeType: bigint, rabinSig: RabinSig,
padding: ByteString, playerSig: Sig) {
// Natural 21: player takes everything (2.5x bet)
@ordishs
ordishs / snippet-oracle.ts
Created March 5, 2026 11:50
Oracle settlement in Rúnar
public settle(outcomeType: bigint, rabinSig: RabinSig,
padding: ByteString, playerSig: Sig) {
// Verify the oracle attests to this outcome
const msg = num2bin(outcomeType, 8n);
assert(verifyRabinSig(msg, rabinSig, padding, this.oraclePubKey));
// Verify it's a win
assert(outcomeType == 1n);
// Player authorises the spend
@ordishs
ordishs / snippet-rabin.txt
Created March 5, 2026 11:50
Rabin signature formula
signature² mod publicKey == SHA-256(message || padding)
@ordishs
ordishs / snippet-p2pkh-go.go
Created March 5, 2026 11:50
P2PKH in Rúnar Go
type P2PKH struct {
runar.SmartContract
PubKeyHash runar.Addr `runar:"readonly"`
}
func (c *P2PKH) Unlock(sig runar.Sig, pubKey runar.PubKey) {
runar.Assert(runar.Hash160(pubKey) == c.PubKeyHash)
runar.Assert(runar.CheckSig(sig, pubKey))
}
@ordishs
ordishs / snippet-p2pkh-sol.sol
Created March 5, 2026 11:50
P2PKH in Rúnar Solidity-like
pragma runar ^0.1.0;
contract P2PKH is SmartContract {
Addr immutable pubKeyHash;
constructor(Addr _pubKeyHash) {
pubKeyHash = _pubKeyHash;
}
function unlock(Sig sig, PubKey pubKey) public {
require(hash160(pubKey) == pubKeyHash);
require(checkSig(sig, pubKey));
}
@ordishs
ordishs / snippet-p2pkh-ts.ts
Created March 5, 2026 11:50
P2PKH in Rúnar TypeScript
class P2PKH extends SmartContract {
readonly pubKeyHash: Addr;
constructor(pubKeyHash: Addr) {
super(pubKeyHash);
this.pubKeyHash = pubKeyHash;
}
public unlock(sig: Sig, pubKey: PubKey) {
assert(hash160(pubKey) === this.pubKeyHash);
assert(checkSig(sig, pubKey));
}
@ordishs
ordishs / snippet-opcodes.txt
Created March 5, 2026 11:50
P2PKH opcodes
Locking script: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
Unlocking script: <signature> <publicKey>
@ordishs
ordishs / runar-medium-article.md
Last active March 5, 2026 12:06
From TypeScript to Bitcoin Script: How Rúnar Makes Smart Contracts on BSV Actually Work

From TypeScript to Bitcoin Script: How Rúnar Makes Smart Contracts on BSV Actually Work

Write in the language you know. Deploy to the chain that scales.

If you've ever looked at raw Bitcoin Script and thought "nobody in their right mind would write this by hand," you're not wrong. Bitcoin Script is a stack-based, Forth-like language with no variables, no functions, and no loops. It was designed to be verified by miners, not written by developers.

And yet — Bitcoin Script is one of the most powerful smart contract execution environments in existence. Every node on the Bitcoin SV network can verify your contract. No virtual machine. No gas fees. No separate "smart contract layer." Just raw, deterministic script evaluation baked into every transaction.

The problem has always been the developer experience. Until now.

@ordishs
ordishs / verify.js
Last active March 15, 2024 00:30
Small example of the steps needed to verify the merkle proofs of a transaction provided by WhatsOnChain.
const crypto = require('crypto')
const assert = require('assert')
function sha256 (buffer) {
assert(Buffer.isBuffer(buffer), `Argument must be a buffer, received ${typeof buffer}`)
const hash = crypto.createHash('sha256')
hash.update(buffer)
return hash.digest()
}