X2Y2-io / x2y2-sdk

X2Y2 Node.js SDK.
MIT License
26 stars 26 forks source link

SDK returning Error: bad response #5

Closed tster closed 2 years ago

tster commented 2 years ago

Describe the bug When following the instructions to make an offer as described at https://github.com/X2Y2-io/x2y2-sdk#making-offers--collection-offers, an Error: bad response is thrown.

Code sample

const offerResponse = await offer({
        network,
        signer: WALLET, // Signer of the buyer
        isCollection: false, // bool, set true for collection offer
        tokenAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', // string, contract address of NFT collection
        tokenId: '2491', // string, token ID of the NFT, use empty string for collection offer
        currency: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // string, contract address of WETH, '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
        price: '10', // string, eg. '1000000000000000000' for 1 WETH
        expirationTime: 1657273865, // number, the unix timestamp when the listing will expire, in seconds
      })
    } catch (error) {
        console.log(error)
    }

Expected behavior The API should return a 200 status code. If something is wrong with the order, one of the custom error codes should be thrown.

tster commented 2 years ago

I've managed to diagnose this error. The issue was having not having enough WETH for the offer in the wallet.

I think the error handling for this case should be improved, with the creation of a dedicated insufficient funds error code.

shermiexyz commented 2 years ago

Now for insufficient funds, the api will return 2014 error code.