To unlock, the lock script is 15 and the maximum value is smaller than 8. Therefore, Python performed this script, replicated the top 3, checked whether it was under 15 years of age, and checked for less than 15.
ex2a_txout_scriptPubKey = (OP_3DUP,OP_8,OP_LESSTHAN,OP_VERIFY,OP_8,OP_LESSTHAN,OP_VERIFY,OP_8,OP_LESSTHAN,OP_VERIFY,OP_ADD,OP_ADD,OP_15,OP_EQUALVERIFY)
Send it with this function response = send_from_P2PKH_transaction(amount_to_send, txid_to_spend, utxo_index, ex2a_txout_scriptPubKey)
def send_from_P2PKH_transaction(amount_to_send, txid_to_spend, utxo_index, txout_scriptPubKey):
# Step 1: Create the txin
txin = CMutableTxIn(COutPoint(lx(txid_to_spend), utxo_index)) #now we have txin
# Step 2: Create the txout
txout = CMutableTxOut(amount_to_send * COIN, CScript(txout_scriptPubKey))
# Step 3: Create the transaction
tx = CMutableTransaction((txin), (txout))
# Step 4: Create the txin_scriptPubKey (from the address holding the UTXO)
txin_scriptPubKey = my_address.to_scriptPubKey()
# Step 5: Create the signature
sig = create_OP_CHECKSIG_signature(tx, txin_scriptPubKey, my_private_key)
# Step 6: Set the txin's scriptSig value (signature + public_key)
txin.scriptSig = CScript((sig, my_public_key))
# Verify the transaction
VerifyScript(txin.scriptSig, txin_scriptPubKey, tx, 0, (SCRIPT_VERIFY_P2SH,))
# Broadcast the transaction
return broadcast_transaction(tx)
It works at Classic P2PKH, but when using txout_scriptpubKey, the response is as follows.
`400 Bad Request sendrawtransaction RPC error -26: scriptpubkey`
Thank you for your help. I don’t know where I was wrong on the script. I used 8 first, but I thought I had to use OP_8, but it still doesn’t work. Edit: Also not accept it "(OP_5, OP_EQUAL)"
. You can’t accept anything other than p2pkh.