forked from yug49/PyPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-create-blockchain-order.js
More file actions
106 lines (93 loc) · 3.69 KB
/
Copy pathtest-create-blockchain-order.js
File metadata and controls
106 lines (93 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const {
createWalletClient,
createPublicClient,
http,
privateKeyToAccount,
} = require("viem");
const { worldchainSepolia } = require("viem/chains");
async function createBlockchainOrder() {
console.log("🔗 Creating Real Blockchain Order");
console.log("=================================");
const rpcUrl = "https://testnet.evm.nodes.onflow.org";
const contractAddress = "0x756523eDF6FfC690361Df3c61Ec3719F77e9Aa1a";
const privateKey =
"6c1db0c528e7cac4202419249bc98d3df647076707410041e32f6e9080906bfb"; // Test private key
// Create account and clients
const account = privateKeyToAccount(`0x${privateKey}`);
const publicClient = createPublicClient({
chain: worldchainSepolia,
transport: http(rpcUrl),
});
const walletClient = createWalletClient({
account,
chain: worldchainSepolia,
transport: http(rpcUrl),
});
console.log(`📋 Account: ${account.address}`);
// Contract ABI for createOrder function
const contractABI = [
{
inputs: [
{ internalType: "uint256", name: "_amount", type: "uint256" },
{
internalType: "uint256",
name: "_startPrice",
type: "uint256",
},
{ internalType: "uint256", name: "_endPrice", type: "uint256" },
{
internalType: "string",
name: "_recipientUpiAddress",
type: "string",
},
],
name: "createOrder",
outputs: [
{ internalType: "bytes32", name: "orderId", type: "bytes32" },
],
stateMutability: "nonpayable",
type: "function",
},
];
try {
// Order parameters
const amount = "100000000000000000000"; // 100 INR in wei
const startPrice = "90000000000000000000"; // 90 INR in wei
const endPrice = "80000000000000000000"; // 80 INR in wei
const recipientUpi = "testblockchain@upi";
console.log("📤 Creating order on blockchain...");
console.log(` Amount: ${amount} (100 INR)`);
console.log(` Token: PYUSD (hardcoded in contract)`);
console.log(` Start Price: ${startPrice} (90 INR)`);
console.log(` End Price: ${endPrice} (80 INR)`);
console.log(` UPI: ${recipientUpi}`);
// Send transaction to create order
const txHash = await walletClient.writeContract({
address: contractAddress,
abi: contractABI,
functionName: "createOrder",
args: [amount, startPrice, endPrice, recipientUpi],
});
console.log(`✅ Transaction sent: ${txHash}`);
console.log("⏳ Waiting for confirmation...");
// Wait for transaction receipt
const receipt = await publicClient.waitForTransactionReceipt({
hash: txHash,
});
console.log(`✅ Order created! Block: ${receipt.blockNumber}`);
// Extract order ID from logs if available
if (receipt.logs && receipt.logs.length > 0) {
console.log(`📋 Logs:`, receipt.logs);
}
console.log("\n🎯 Expected Result:");
console.log(" ✅ Resolver bot should detect this new order");
console.log(" ✅ Resolver will attempt to accept it");
console.log(" ✅ We should see debugging output from backend");
} catch (error) {
console.error("❌ Failed to create blockchain order:", error.message);
if (error.details) {
console.error(" Details:", error.details);
}
}
}
createBlockchainOrder().catch(console.error);