forked from yug49/PyPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-contract-call.js
More file actions
162 lines (150 loc) · 5.73 KB
/
test-contract-call.js
File metadata and controls
162 lines (150 loc) · 5.73 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const { createPublicClient, http } = require("viem");
async function testContractCall() {
console.log("🔧 Testing Direct Contract Call...");
try {
const rpcUrl = "https://testnet.evm.nodes.onflow.org";
const contractAddress = "0x756523eDF6FfC690361Df3c61Ec3719F77e9Aa1a";
const orderId =
"0x2e3ca2e75fd1b193a8df070bcc33f03d6aa3edfa0e29fe418d881837e0f6da1c";
console.log("📋 Order ID:", orderId);
console.log("🏗️ Contract:", contractAddress);
console.log("🌐 RPC:", rpcUrl);
// Create public client
const publicClient = createPublicClient({
chain: {
id: 4801,
name: "Worldchain Sepolia",
network: "worldchain-sepolia",
nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
rpcUrls: {
default: { http: [rpcUrl] },
public: { http: [rpcUrl] },
},
blockExplorers: {
default: {
name: "Explorer",
url: "https://testnet.evm.nodes.onflow.org",
},
},
},
transport: http(rpcUrl),
});
console.log("✅ Public client created");
// Simple ABI for getOrder
const abi = [
{
inputs: [
{
internalType: "bytes32",
name: "_orderId",
type: "bytes32",
},
],
name: "getOrder",
outputs: [
{
components: [
{
internalType: "address",
name: "maker",
type: "address",
},
{
internalType: "address",
name: "taker",
type: "address",
},
{
internalType: "string",
name: "recipientUpiAddress",
type: "string",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
{
internalType: "address",
name: "token",
type: "address",
},
{
internalType: "uint256",
name: "startPrice",
type: "uint256",
},
{
internalType: "uint256",
name: "acceptedPrice",
type: "uint256",
},
{
internalType: "uint256",
name: "endPrice",
type: "uint256",
},
{
internalType: "uint256",
name: "startTime",
type: "uint256",
},
{
internalType: "uint256",
name: "acceptedTime",
type: "uint256",
},
{
internalType: "bool",
name: "accepted",
type: "bool",
},
{
internalType: "bool",
name: "fullfilled",
type: "bool",
},
],
internalType: "struct OrderProtocol.Order",
name: "",
type: "tuple",
},
],
stateMutability: "view",
type: "function",
},
];
console.log("📞 Calling getOrder...");
// Call contract
const result = await publicClient.readContract({
address: contractAddress,
abi: abi,
functionName: "getOrder",
args: [orderId],
});
console.log("✅ Contract call successful!");
console.log("📋 Raw result:", result);
// Parse result
const order = {
maker: result[0],
taker: result[1],
recipientUpiAddress: result[2],
amount: result[3].toString(),
token: result[4],
startPrice: result[5].toString(),
acceptedPrice: result[6].toString(),
endPrice: result[7].toString(),
startTime: Number(result[8]),
acceptedTime: Number(result[9]),
accepted: result[10],
fullfilled: result[11],
};
console.log("📊 Parsed order:");
console.log(JSON.stringify(order, null, 2));
} catch (error) {
console.error("❌ Error calling contract:");
console.error("Message:", error.message);
console.error("Details:", error);
}
}
testContractCall();