-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtransfer-all.js
More file actions
78 lines (63 loc) · 2.19 KB
/
transfer-all.js
File metadata and controls
78 lines (63 loc) · 2.19 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
import { utils, Wallet, formatEther } from "ethers";
import {
getAxieIdsFromAccount,
batchTransferAxies,
createProvider,
} from "axie-tools";
import "dotenv/config";
async function batchTransfer() {
const privateKey = process.env.PRIVATE_KEY;
const skyMavisApiKey = process.env.SKYMAVIS_API_KEY;
if (!privateKey || !skyMavisApiKey) {
throw new Error(
"Please set your PRIVATE_KEY and SKYMAVIS_API_KEY in a .env file",
);
}
const provider = createProvider(skyMavisApiKey);
const wallet = new Wallet(privateKey, provider);
const fromAddress = await wallet.getAddress();
console.log(`📬 From address: ${fromAddress}`);
// Get RON balance
const balance = await provider.getBalance(fromAddress);
const balanceInRON = formatEther(balance);
console.log(`💰 RON Balance: ${balanceInRON}`);
if (parseFloat(balanceInRON) < 0.001) {
throw new Error("Not enough RON to pay for the transaction");
}
// Get addressTo from command line args and validate
const args = process.argv.slice(2);
if (args.length === 0) {
throw new Error("Please provide a recipient address as argument");
}
const toAddress = args[0].replace("ronin:", "0x");
if (!utils.isAddress(toAddress)) {
throw new Error("Invalid recipient address");
}
console.log(`📫 To address: ${toAddress}`);
// Get all axies ids from the account
const axieIds = await getAxieIdsFromAccount(fromAddress, provider);
console.log(`🐾 Number of Axies: ${axieIds.length}`);
if (axieIds.length === 0) {
console.log("No axies to transfer");
return;
}
if (axieIds.length > 100) {
console.log(
"⚠️ Warning: Can only transfer up to 100 Axies at once, only transferring the first 100",
);
axieIds = axieIds.slice(0, 100);
}
console.log(`🆔 Transferring Axie IDs: ${axieIds.join(", ")}`);
const receipt = await batchTransferAxies(wallet, toAddress, axieIds);
if (!receipt) {
throw new Error("Transaction failed");
}
console.log("✅ Transfer successful!");
console.log(
`🔗 View transaction: https://app.roninchain.com/tx/${receipt.hash}`,
);
}
batchTransfer().catch((error) => {
console.error("❌ Error:", error.message);
process.exit(1);
});