Skip to content

Instantly share code, notes, and snippets.

@fzn0x
Created June 13, 2022 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzn0x/1625cc3d27bf5ff9f2207d0119e7d6ff to your computer and use it in GitHub Desktop.
Save fzn0x/1625cc3d27bf5ff9f2207d0119e7d6ff to your computer and use it in GitHub Desktop.
Axie composition and valuation sample script
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);
}
}
@fzn0x
Copy link
Author

fzn0x commented Jun 13, 2022

const { ua, randomElement } = require("../config/userAgent.js");

const ua = [
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15",
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0",
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
];

module.exports.ua = ua;
module.exports.randomElement = Math.floor(Math.random() * ua.length);
// const { ua, randomElement } = require("./userAgent.js");
// usage: ua[randomElement]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment