axie-ronin-ethers-js-tools
Version:
A set of functions that make it easier for developers to interact with their Axies on the Ronin network and the maketplace.
43 lines (38 loc) • 971 B
text/typescript
import { confirm, number } from '@inquirer/prompts';
export async function apiRequest<T>(
url: string,
body: BodyInit | null = null,
headers: Record<string, string> = {},
method: 'GET' | 'POST' = 'POST',
) {
const response = await fetch(url, {
method,
headers: {
'Content-Type': 'application/json',
...headers
},
...(method === 'GET' ? {} : { body })
})
const res: T = await response.json()
return res
}
export const askToContinue = async () => {
const continueUsing = await confirm({
message: '🔄 Would you like to do something else?'
});
if (!continueUsing) {
console.log('👋 Goodbye!');
process.exit(0);
}
};
export const getAxieId = async () => {
const axieId = await number({
message: '🆔 Enter Axie ID:',
validate: (value) => value !== undefined && !isNaN(value)
});
if (axieId === undefined) {
console.log('❌ Invalid Axie ID!');
return null;
}
return axieId;
};