forked from OmakaseaNFT/chia-nft-util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createOffers.js
54 lines (45 loc) · 1.38 KB
/
createOffers.js
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
const { getNFTs } = require("./utils/rpcCalls")
const { RPCAgent } = require("chia-agent");
const { create_offer_for_ids } = require("chia-agent/api/rpc");
const fs = require("fs").promises
const path = require("path")
const {
WALLET_ID,
WALLET_FINGERPRINT,
OFFER_AMOUNT_MOJOS,
OFFER_IGNORE_LIST
} = require("./utils/constants")
const {
login
} = require("./utils/rpcCalls")
const agent = new RPCAgent({
service: "wallet",
});
async function createOffer(launcherID, index) {
const params = {
offer: {
// assumes 1 is ID for XCH wallet
"1": OFFER_AMOUNT_MOJOS,
// launcher coin ID
[launcherID]: -1
},
// only need a fee to expedite offer acceptance, not absolutely necessary
// fee: 50000000,
}
const result = await create_offer_for_ids(agent, params)
await fs.writeFile(path.join(__dirname, "offers", `offer_${index}.offer`), result.offer)
return result
}
async function bulkCreateOffers() {
await login(WALLET_FINGERPRINT)
const nfts = await getNFTs(WALLET_ID)
const nftsLength = nfts.nft_list.length
const offerDir = await fs.readdir(path.join(__dirname, "offers"))
const maxOfferIndex = offerDir.length - 1
for (let i=maxOfferIndex + 1; i<nftsLength; i++) {
const launcherID = nfts.nft_list[i].launcher_id
if (launcherID in OFFER_IGNORE_LIST) continue
await createOffer(launcherID, i)
}
}
bulkCreateOffers()