• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

spending – learn me how to spend nonstandard script. mainnet. 25k sats

Moussa by Moussa
January 11, 2024
in Bitcoin
0
peer discovery – how to obtain the IP addresses of nodes for mining pools?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


I used chatgpt to construct this code in python. i learned very hard, but i just can’t understand how to spend with no errors.
all necessary data for creating raw transaction is provided below.
i was trying to spend first op_if condition.
posting my code here. if some one could do it (spend it) means i should learn more and harder.
Final transaction in hexadecimal form: 01000000000101ab7aa08e72a03e837be7a75c35cc65fd0ff074ad3826a33202d976b091b2b1a1a400000000feffffff01b1140000000000002200206cadc53e5157ac4f0c8e98d0011fd8ccd14378b846b1b944478b3437324b992e04483045022100afc1e86ecc7f00027fcea34eed154241977d4989ee0e5c6288dc303000cdc4ae022072c3a973a6d32a0b3fa4ff28c3f45a0c269b1cad8360127a4c7f60978024408f0121024e24d2aff4e1c51eaf122e0e5a6dfe218f7b3b883d1eb537ce9a7e040b329ca5010155630320830cb17521024e24d2aff4e1c51eaf122e0e5a6dfe218f7b3b883d1eb537ce9a7e040b329ca5ac6703b0830cb17521030618b7d1a6747cb13bba78611646a8d08c3683e14a0d2a4483c877561e1416efac6820830c00

import hashlib
import ecdsa

def dSHA256(raw):
    return hashlib.sha256(hashlib.sha256(raw).digest()).digest()

def create_signature(private_key_hex, message):
    try:
        private_key_bytes = bytes.fromhex(private_key_hex)
        signing_key = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1)
        signature = signing_key.sign_digest(message, sigencode=ecdsa.util.sigencode_der_canonize)
        return signature  # Do not append SIGHASH_ALL here
    except Exception as e:
        print(f"Error creating signature: {e}")
        return None

# Transaction version
version = (2).to_bytes(4, byteorder="little", signed=False)

# Input transaction (Outpoint)
txid = (bytes.fromhex("a1b1b291b076d90232a32638ad74f00ffd65cc355ca7e77b833ea0728ea07aab"))[::-1]
index = (164).to_bytes(4, byteorder="little", signed=False)
outpoint = txid + index

# Hashed outpoint
hashPrevOut = dSHA256(outpoint)

# Sequence
sequence = (0xfffffffe).to_bytes(4, byteorder="little", signed=False)  # Use a value less than 0xffffffff
hashSequence = dSHA256(sequence)

# Amount being spent
amount = (int(0.00025297 * 100000000)).to_bytes(8, byteorder="little", signed=True)

# Output to the specified address
value = (int(0.00005297 * 100000000)).to_bytes(8, byteorder="little", signed=True)
scriptPubKey_hex = "00206cadc53e5157ac4f0c8e98d0011fd8ccd14378b846b1b944478b3437324b992e"
scriptPubKey = bytes.fromhex(scriptPubKey_hex)
output = value + (len(scriptPubKey)).to_bytes(1, byteorder="little", signed=False) + scriptPubKey

# Hashed output
hashOutput = dSHA256(output)

# nLockTime
nLockTime = (820000).to_bytes(4, byteorder="little", signed=False)

# Sighash type
sighash = bytes.fromhex("01000000")

# Public and private keys
private_key_hex = "2BF933A3FC415D4BA19D07F3F5FF641E645D1BDF70CFE1674D54C0E66AAA681F"
verifying_key = ecdsa.SigningKey.from_string(bytes.fromhex(private_key_hex), curve=ecdsa.SECP256k1).get_verifying_key()
x_cor = bytes.fromhex(verifying_key.to_string().hex())[:32]
y_cor = bytes.fromhex(verifying_key.to_string().hex())[32:]
public_key = bytes.fromhex("02" + x_cor.hex()) if int.from_bytes(y_cor, byteorder="big", signed=True) % 2 == 0 else bytes.fromhex("03" + x_cor.hex())

# WitnessScript
witnessScript = bytes.fromhex("630320830cb17521024e24d2aff4e1c51eaf122e0e5a6dfe218f7b3b883d1eb537ce9a7e040b329ca5ac6703b0830cb17521030618b7d1a6747cb13bba78611646a8d08c3683e14a0d2a4483c877561e1416efac68")
scriptCode = witnessScript

# Transaction digest for signature
bip_143 = version + hashPrevOut + hashSequence + outpoint + scriptCode + amount + sequence + hashOutput + nLockTime + sighash
hashed_bip_143 = dSHA256(bip_143)

# Signature
signature = create_signature(private_key_hex, hashed_bip_143)

# Print the DER-encoded signature in hexadecimal form
print("Signature (DER-encoded) in hexadecimal form:", signature.hex())

# Append SIGHASH_ALL to the signature
signature += bytes.fromhex("01")

# Witness construction for the first branch of OP_IF
minimal_true = bytes.fromhex("01")  # Minimal push of true
witness = (
    bytes.fromhex("04")  # Number of elements in the witness
    + (len(signature)).to_bytes(1, byteorder="little", signed=False) + signature
    + (len(public_key)).to_bytes(1, byteorder="little", signed=False) + public_key
    + (len(minimal_true)).to_bytes(1, byteorder="little", signed=False) + minimal_true
    + (len(witnessScript)).to_bytes(1, byteorder="little", signed=False) + witnessScript
)

# Transaction input and output counts
tx_in_count = (1).to_bytes(1, byteorder="little", signed=False)
tx_out_count = (1).to_bytes(1, byteorder="little", signed=False)

# Marker and Flag for SegWit
marker = bytes.fromhex("00")
flag = bytes.fromhex("01")

# Final transaction assembly
final_tx = (
    version
    + marker
    + flag
    + tx_in_count
    + outpoint
    + (0).to_bytes(1, byteorder="little", signed=False)  # ScriptSig is empty for SegWit inputs
    + sequence
    + tx_out_count
    + output
    + witness
    + nLockTime
)

# Print the final transaction hex
print("Final transaction in hexadecimal form:", final_tx.hex())



Source link

Related articles

Bitcoin Historical Performance Shows How Low The Price Will Go Before A Bottom

Bitcoin Historical Performance Shows How Low The Price Will Go Before A Bottom

January 31, 2026
Tennessee Lawmakers Weigh Strategic Bitcoin Reserve Bill

Tennessee Lawmakers Weigh Strategic Bitcoin Reserve Bill

January 31, 2026
Share76Tweet47

Related Posts

Bitcoin Historical Performance Shows How Low The Price Will Go Before A Bottom

Bitcoin Historical Performance Shows How Low The Price Will Go Before A Bottom

by Moussa
January 31, 2026
0

Crypto analyst Maelius has alluded to Bitcoin’s historical performance to provide insights into how low the flagship crypto could drop...

Tennessee Lawmakers Weigh Strategic Bitcoin Reserve Bill

Tennessee Lawmakers Weigh Strategic Bitcoin Reserve Bill

by Moussa
January 31, 2026
0

Tennessee lawmakers are considering legislation that would allow the state to hold bitcoin as part of its public financial reserves. ...

Ghana Further Formalizes Digital Asset Sector with Education Campaign

Ghana Further Formalizes Digital Asset Sector with Education Campaign

by Moussa
January 31, 2026
0

Following the passage of the virtual asset service providers (VASP) Act (Act 1154), the Bank of Ghana has launched the...

How do Bitcoin mining pools typically handle payout frequency versus thresholds?

java – Where to find old BitCoinJ versions

by Moussa
January 31, 2026
0

where to find the old BitCoinJ version 0.1 and 0.2 and 0.3 This appears to be more of a question...

Trump Says New Fed Chair Will Cut Rates After Warsh Nomination

Trump Says New Fed Chair Will Cut Rates After Warsh Nomination

by Moussa
January 31, 2026
0

Join Our Telegram channel to stay up to date on breaking news coverage US President Donald Trump said Friday that...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSUzQ2RpdiUyMGNsYXNzJTNEJTIydG5wJTIwdG5wLXN1YnNjcmlwdGlvbiUyMiUzRSUwQSUzQ2Zvcm0lMjBtZXRob2QlM0QlMjJwb3N0JTIyJTIwYWN0aW9uJTNEJTIyaHR0cHMlM0ElMkYlMkZhcHByb3gub3JnJTJGJTNGbmElM0RzJTIyJTNFJTBBJTBBJTNDaW5wdXQlMjB0eXBlJTNEJTIyaGlkZGVuJTIy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aXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News