From 41439690cfd0cc09871aa456a99791c28390b08c Mon Sep 17 00:00:00 2001 From: Erick Levandoski <157233531+Erick-IL@users.noreply.github.com> Date: Wed, 25 Jun 2025 10:47:36 -0300 Subject: [PATCH] Update bidAuction.js - Adjustments to obsolete fields in prepareBidInput - englishAuctionId -> auctionId - Automatic auctionid processing, Now send the full Id (Ex: EnglishAuction:64017db5-29f6-4e34-9ad5-36548bb422b7 --- examples/bidAuction.js | 50 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/examples/bidAuction.js b/examples/bidAuction.js index e0bcdf5..42912c6 100644 --- a/examples/bidAuction.js +++ b/examples/bidAuction.js @@ -1,39 +1,42 @@ -const { GraphQLClient, gql } = require('graphql-request'); -const { signLimitOrder } = require('@sorare/crypto'); -const crypto = require('crypto'); -const yargs = require('yargs'); +import { GraphQLClient, gql } from 'graphql-request'; +import crypto from 'crypto'; +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; import { authorizationRequestFragment, buildApprovals, -} from '../authorizations'; +} from './authorizations.js'; -const { auctionId, token, privateKey, jwtAud } = yargs +const argv = yargs(hideBin(process.argv)) .command( 'bidAuctionWithEth', 'Make the minimum next bid on an english auction.' ) .option('auctionId', { - description: 'The auction id.', + description: 'The auction id with "EnglishAuction:" prefix.', type: 'string', - required: true, + demandOption: true, }) .option('token', { description: 'The JWT or OAuth token.', type: 'string', - required: true, + demandOption: true, }) .option('private-key', { description: 'Your Starkware private key', type: 'string', - required: true, + demandOption: true, }) .option('jwt-aud', { description: 'The JWT audience (required if using a JWT token).', type: 'string', }) .help() - .alias('help', 'h').argv; + .alias('help', 'h') + .parse(); + +const { auctionId: auctionUuid, token, privateKey, jwtAud } = argv; const Config = gql` query ConfigQuery { @@ -84,28 +87,27 @@ const Bid = gql` async function main() { const graphQLClient = new GraphQLClient( - 'https://api.sorare.dev/graphql', + 'https://api.sorare.com/graphql', { headers: { Authorization: `Bearer ${token}`, 'JWT-AUD': jwtAud, - // 'APIKEY': '' + 'APIKEY': token }, } ); const configData = await graphQLClient.request(Config); + const exchangeRateId = configData['config']['exchangeRate']['id']; - console.log('Using exchange rate id', exchangeRateId); const englishAuctionData = await graphQLClient.request(EnglishAuction, { - auctionId: auctionId, + auctionId: auctionUuid.replace("EnglishAuction:", ""), // to search not use prefix }); const bidAmountInWei = englishAuctionData['tokens']['auction']['minNextBid']; - console.log('Minimum next bid is', bidAmountInWei, 'wei'); const prepareBidInput = { - englishAuctionId: auctionId, + auctionId: auctionUuid, // to bid, use prefix amount: bidAmountInWei, settlementInfo: { currency: 'WEI', @@ -113,11 +115,14 @@ async function main() { exchangeRateId: exchangeRateId, }, }; + + const prepareBidData = await graphQLClient.request(PrepareBid, { input: prepareBidInput, }); + const prepareBid = prepareBidData['prepareBid']; - if (prepareBid['errors'].length > 0) { + if (prepareBid['errors'] && prepareBid['errors'].length > 0) { prepareBid['errors'].forEach(error => { console.error(error['message']); }); @@ -129,7 +134,7 @@ async function main() { const bidInput = { approvals, - auctionId: `EnglishAuction:${auctionId}`, + auctionId: auctionUuid, amount: bidAmountInWei, settlementInfo: { currency: 'WEI', @@ -143,14 +148,15 @@ async function main() { console.log(bidData); const bid = bidData['bid']; - if (bid['errors'].length > 0) { + if (bid['errors'] && bid['errors'].length > 0) { bid['errors'].forEach(error => { console.error(error['message']); }); process.exit(2); } - console.log('Success!'); } -main().catch(error => console.error(error)); +main().catch(error => { + console.error(error) +});