@@ -26,7 +26,9 @@ def get_env_val(key):
2626payment_vkey = PaymentVerificationKey .from_signing_key (payment_skey )
2727
2828chain_context = BlockFrostChainContext (
29- project_id = get_env_val ("BLOCKFROST_ID" ), network = NETWORK
29+ project_id = get_env_val ("BLOCKFROST_ID" ),
30+ network = NETWORK ,
31+ base_url = "https://cardano-preview.blockfrost.io/api" ,
3032)
3133
3234
@@ -67,7 +69,7 @@ def create_collateral(target_address, skey):
6769 script_hex = f .read ()
6870 forty_two_script = cbor2 .loads (bytes .fromhex (script_hex ))
6971
70- script_hash = plutus_script_hash (forty_two_script )
72+ script_hash = plutus_script_hash (PlutusV1Script ( forty_two_script ) )
7173
7274script_address = Address (script_hash , network = NETWORK )
7375
@@ -94,11 +96,20 @@ def create_collateral(target_address, skey):
9496# Put integer 42 (the secret that unlocks the fund) in the redeemer.
9597redeemer = Redeemer (RedeemerTag .SPEND , 42 )
9698
97- utxo_to_spend = chain_context .utxos (str (script_address ))[0 ]
99+ utxo_to_spend = None
100+ for utxo in chain_context .utxos (str (script_address )):
101+ if utxo .output .datum_hash == datum_hash (datum ):
102+ utxo_to_spend = utxo
103+ break
104+
105+ if utxo_to_spend is None :
106+ raise Exception ("Can't find utxo to spend! Please try again later." )
98107
99108builder = TransactionBuilder (chain_context )
100109
101- builder .add_script_input (utxo_to_spend , forty_two_script , datum , redeemer )
110+ builder .add_script_input (
111+ utxo_to_spend , PlutusV1Script (forty_two_script ), datum , redeemer
112+ )
102113
103114# Send 5 ADA to taker address. The remaining ADA (~4.7) will be sent as change.
104115take_output = TransactionOutput (taker_address , 5000000 )
0 commit comments