@@ -143,7 +143,7 @@ async function submitOrder(): bool {
143
143
});
144
144
const parsedResponse = await response .json () as { success: bool };
145
145
146
- return fetchedOrders ;
146
+ return parsedResponse . success ;
147
147
}
148
148
```
149
149
@@ -152,13 +152,20 @@ async function submitOrder(): bool {
152
152
153
153
``` python
154
154
import requests
155
+ import json
155
156
156
157
API_URL = " https://orders.catalyst.exchange/"
157
158
158
- def get_orders ():
159
- response = requests.post(API_URL + " submitOrder/" , data)
159
+ def submit_order (): bool :
160
+ order = {}
161
+ signature = " 0x..."
162
+ data = {
163
+ " order" : order,
164
+ " signature" : signature
165
+ }
166
+ response = requests.post(API_URL + " submitOrder/" , json = data)
160
167
fetched_orders = response.json()
161
- return fetched_orders
168
+ return fetched_orders.get( " success " )
162
169
```
163
170
164
171
</TabItem >
@@ -212,10 +219,8 @@ async function getOrders(): getOrdersFetch {
212
219
``` python
213
220
import requests
214
221
215
- API_URL = " https://orders.catalyst.exchange/getOrders"
216
-
217
222
def get_orders ():
218
- response = requests.get(API_URL )
223
+ response = requests.get(API_URL + " orders/ " )
219
224
fetched_orders = response.json()
220
225
return fetched_orders
221
226
```
@@ -268,8 +273,53 @@ async function initiateOrder() {
268
273
</TabItem >
269
274
<TabItem label = " Python" >
270
275
271
- ``` sh
272
- pnpm create astro --template starlight
276
+ ``` python
277
+ from web3 import Web3
278
+
279
+ rpc_url = " "
280
+ web3 = Web3(Web3.HTTPProvider(eth_node_url))
281
+
282
+ # Your ABI and signer details
283
+ reactor_abi = " ..."
284
+ signer_private_key = " your_private_key_here"
285
+ signer_address = web3.eth.account.from_key(signer_private_key).address
286
+
287
+
288
+ def initiate_order ():
289
+ # Get an order
290
+ orders = get_orders()
291
+ order = orders[' orders' ][0 ]
292
+
293
+ # Define the reactor we will call. You can get the reactor address from the order
294
+ reactor_address = order[' order' ][' settlementContract' ]
295
+ reactor = web3.eth.contract(address = reactor_address, abi = reactor_abi)
296
+
297
+ # TODO : there needs to be set approvals for the reactorAddress for all inputs & collateral.
298
+ # This will depend on the specific ERC20 tokens you're using, you need to call approve() on the ERC20 token contracts
299
+
300
+ # Clean the order data by removing the type field
301
+ cleaned_order_data = order[' order' ][' orderData' ].copy()
302
+ cleaned_order_data.pop(' type' )
303
+ cleaned_order = {** order[' order' ], ' orderData' : cleaned_order_data}
304
+ signature = order[' signature' ]
305
+ filler_data = " 0x" # We will touch on the later.
306
+
307
+ # Build the transaction
308
+ txn = reactor.functions.initiate(cleaned_order, signature, filler_data).build_transaction({
309
+ ' from' : signer_address,
310
+ ' nonce' : web3.eth.get_transaction_count(signer_address)
311
+ })
312
+
313
+ # Sign the transaction
314
+ signed_txn = web3.eth.account.sign_transaction(txn, private_key = signer_private_key)
315
+
316
+ # Send the transaction
317
+ tx_hash = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
318
+
319
+ # Wait for the transaction receipt
320
+ receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
321
+
322
+ return receipt
273
323
```
274
324
275
325
</TabItem >
0 commit comments