# Smart Contract Template

# Single Signature Verification Contract

var publicKey pubkey = "e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78"

func unlockWithSig(signnature sig) {
  verify(check_tx_sig(publicKey, signnature))
}

Verify whether it is a signature with the specified public key

  • The bytecode : 6c767c6b786c767c6bae7cac6c767c6b54796c767c6bae7cac6975
  • The machine code:
   0 FROMALTSTACK
   1 DUP
   2 SWAP
   3 TOALTSTACK
   4 OVER
   5 FROMALTSTACK
   6 DUP
   7 SWAP
   8 TOALTSTACK
   9 TXSIGHASH
  10 SWAP
  11 CHECKSIG
  12 FROMALTSTACK
  13 DUP
  14 SWAP
  15 TOALTSTACK
  16 4
  17 PICK
  18 FROMALTSTACK
  19 DUP
  20 SWAP
  21 TOALTSTACK
  22 TXSIGHASH
  23 SWAP
  24 CHECKSIG
  25 VERIFY
  26 DROP

# Example of if statement

func If(b int64, c int64) {
  var a int64
  if b> c {
    a = b
  } else {
    a = c
  }
}

Pass in two parameters and assign the larger parameter to the internal variable of the function

  • The bytecode: 040000000052795279a091616400000018757663000000187578
  • The machine code:
   0 DATA_4
   1 0
   5 2
   6 PICK
   7 2
   8 PICK
   9 GREATERTHAN
  10 NOT
  11 NOP
  12 JUMPIF
  13 24
  17 DROP
  18 DUP
  19 JUMP
  20 24
  24 DROP
  25 OVER

# Examples of global variables

var a int64 = 1

func globalParaAdd(b int64) {
  a = a + b
}
  • The bytecode: 6c767c6b7893
  • The machine code:
   0 FROMALTSTACK
   1 DUP
   2 SWAP
   3 TOALTSTACK
   4 OVER
   5 ADD
Last Updated: 11/2/2021, 4:26:38 PM