-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsettle-order.js
More file actions
55 lines (47 loc) · 1.53 KB
/
settle-order.js
File metadata and controls
55 lines (47 loc) · 1.53 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
import { buyMarketplaceOrder, approveWETH, createProvider } from "axie-tools";
import { formatEther, Wallet } from "ethers";
import "dotenv/config";
async function buyAxie() {
if (
!process.env.PRIVATE_KEY ||
!process.env.MARKETPLACE_ACCESS_TOKEN ||
!process.env.SKYMAVIS_API_KEY
) {
throw new Error(
"Please set your PRIVATE_KEY, MARKETPLACE_ACCESS_TOKEN, and SKYMAVIS_API_KEY in a .env file",
);
}
// Initialize provider and wallet
const provider = createProvider(process.env.SKYMAVIS_API_KEY);
const wallet = new Wallet(process.env.PRIVATE_KEY, provider);
const address = await wallet.getAddress();
console.log(`📬 Wallet address: ${address}`);
// Get RON balance
const balance = await provider.getBalance(address);
console.log(`💰 RON Balance: ${formatEther(balance)}`);
// Get axie id from command line args
const args = process.argv.slice(2);
if (args.length === 0) {
throw new Error("Please provide an axie ID as argument");
}
const axieId = parseInt(args[0]);
try {
console.log(`🛒 Approving WETH for marketplace...`);
await approveWETH(wallet);
console.log(`🛒 Buying Axie ${axieId}...`);
const receipt = await buyMarketplaceOrder(
axieId,
wallet,
process.env.MARKETPLACE_ACCESS_TOKEN,
process.env.SKYMAVIS_API_KEY,
);
if (receipt) {
console.log(
"🔗 View transaction: https://app.roninchain.com/tx/" + receipt.hash,
);
}
} catch (error) {
console.error("❌ Error:", error.message);
}
}
buyAxie();