Created
June 13, 2022 06:36
-
-
Save fzn0x/1625cc3d27bf5ff9f2207d0119e7d6ff to your computer and use it in GitHub Desktop.
Axie composition and valuation sample script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { AbortController } = require("node-abort-controller"); | |
const HttpsProxyAgent = require("https-proxy-agent"); | |
const { ua, randomElement } = require("../config/userAgent.js"); | |
async function runRequestAxieBriefList(options, type = "") { | |
const timeout = 60000; | |
const controller = new AbortController(); | |
const id = setTimeout(() => controller.abort(), timeout); | |
const valuationQuery = | |
"query GetAxieBriefList( $auctionType: AuctionType $criteria: AxieSearchCriteria $from: Int $sort: SortBy $size: Int ) { axies( auctionType: $auctionType criteria: $criteria from: $from sort: $sort size: $size ) { results { ...AxieDetail } } } fragment AxieDetail on Axie { auction { ...AxieAuction } } fragment AxieAuction on Auction { currentPrice currentPriceUSD }"; | |
const ownerQuery = | |
"query GetAxieBriefList( $auctionType: AuctionType $criteria: AxieSearchCriteria $from: Int $sort: SortBy $size: Int $owner: String ) { axies( auctionType: $auctionType criteria: $criteria from: $from sort: $sort size: $size owner: $owner ) { total results { ...AxieDetail } } } fragment AxieDetail on Axie { id image class chain name genes owner birthDate bodyShape class sireId sireClass matronId matronClass stage region title breedCount level figure { atlas model image __typename } parts { ...AxiePart __typename } stats { ...AxieStats __typename } auction { ...AxieAuction __typename } ownerProfile { name __typename } battleInfo { ...AxieBattleInfo __typename } children { id name class image title stage __typename } __typename } fragment AxieBattleInfo on AxieBattleInfo { banned banUntil level __typename } fragment AxiePart on AxiePart { id name class type specialGenes stage abilities { ...AxieCardAbility __typename } __typename } fragment AxieCardAbility on AxieCardAbility { id name attack defense energy description backgroundUrl effectIconUrl __typename } fragment AxieStats on AxieStats { hp speed skill morale __typename } fragment AxieAuction on Auction { startingPrice endingPrice startingTimestamp endingTimestamp duration timeLeft currentPrice currentPriceUSD suggestedPrice seller listingIndex state __typename }"; | |
try { | |
const init = { | |
method: "POST", | |
headers: { | |
"content-type": "application/json", | |
"User-Agent": ua[randomElement], | |
}, | |
body: JSON.stringify({ | |
operationName: "GetAxieBriefList", | |
variables: options, | |
query: type === "valuation" ? valuationQuery : ownerQuery, | |
}), | |
signal: controller.signal, | |
}; | |
init.agent = new HttpsProxyAgent( | |
"Secret Hahahah" | |
); | |
const response = await fetch( | |
"https://graphql-gateway.axieinfinity.com/graphql", | |
init | |
); | |
const contentType = response.headers.get("content-type"); | |
if (contentType && contentType.indexOf("application/json") !== -1) { | |
const json = await response.json(); | |
return json; | |
} | |
} catch (e) { | |
throw e; | |
} finally { | |
clearTimeout(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
const { ua, randomElement } = require("../config/userAgent.js");