To start working with orders, we need to parse them. The most convenient way to do this is by using the OrderFactory contract address, gathering outgoing transactions containing StateInit. There are a few ways to do this, like using third-party APIs. I believe the optimal solution would be to gather and categorize all available orders within your database.
Once we've collected all the order addresses, we'll need to check them out:
{ index:16,// Internal identifier status:1,// Order active kind:2,// JETTON to TON rate:190400000000000000000000000000000000000n, fee:500,// 0.2% creator: UQDYzZmfsrGzhObKJUw4gzdeIxEai3jAFbiGKGwxvxHinf4K, maker_amount:115854388n,// 115.854388 (decimal = 6) maker_jetton: EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs // USDT}
While the decimals value for Jettons is commonly set to 9, to ensure accurate calculations, it's recommended to retrieve the decimals value using the following method:
As a safety precaution, we advise manually confirming the token balance of the order contract before initiating a maker transaction.
Taker trade examples:
Order kind == 1 or 3 (Maker sending JETTON)
// jetton to sendconstjettonMasterAddress=Address.parse("EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs");constjettonWallet=tonClient.open(awaitjettonMaster.getWallet(wallet.address));// prepare message body for transferconstpreparedBody=Order.createTakerJettonBody(60000000n, orderAddress,wallet.address,toNano('0.118'), {queryId:777, recipientAddress: recipientAddr});// sending jetton to orderawaitjettonWallet.sendTransferWithPreparedBody(wallet.sender(keys.secretKey),toNano("0.153"), preparedBody);
Order kind == 2 (Taker sending TON)
// sending ton to orderawaitorder.sendTakerTransfer(wallet.sender(keys.secretKey),toNano('10.5'), {recipientAddress: recipientAddr});
If the recipientAddress is not specified, the funds will be sent to the Taker's address.