0

I am calling the quote api, and when passing its response to ethereum.request() for making a transaction, MetaMask pops up a very high tx fees- 1.89 BNB! which is way too high fees for this basic swap function.

Just to add this is in bsc network, and I'm swapping from USDT to BEP20 custom token.

Can someone please help here.

API URL: https://bsc.api.0x.org/swap/v1/quote?sellToken=0x55d398326f99059ff775485246999027b3197955&buyToken=0xaf3889ba617ac973b358513d9031778d2bc783df&sellAmount=1000000000000000000&slippagePercentage=0.10&takerAddress=0x06125e1457f833E29D5aebAaCdF8eED8A6Febaee

Response:

{
    "chainId": 56,
    "price": "1548581.394730707",
    "guaranteedPrice": "1393723.255257636",
    "estimatedPriceImpact": null,
    "to": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
    "data": "0xc43c9ef600000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000004f3957b8b7a240000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000055d398326f99059ff775485246999027b3197955000000000000000000000000af3889ba617ac973b358513d9031778d2bc783df869584cd00000000000000000000000010000000000000000000000000000000000000110000000000000000000000000000000000000000000000c8cac72d8861f9a286",
    "value": "0",
    "gas": "543981",
    "estimatedGas": "543981",
    "from": "0x06125e1457f833e29d5aebaacdf8eed8a6febaee",
    "gasPrice": "5000000000",
    "protocolFee": "0",
    "minimumProtocolFee": "0",
    "buyTokenAddress": "0xaf3889ba617ac973b358513d9031778d2bc783df",
    "sellTokenAddress": "0x55d398326f99059ff775485246999027b3197955",
    "buyAmount": "1548581394730707",
    "sellAmount": "1000000000000000000",
    "sources": [
        {
            "name": "BakerySwap",
            "proportion": "0"
        },
        {
            "name": "Belt",
            "proportion": "0"
        },
        {
            "name": "DODO",
            "proportion": "0"
        },
        {
            "name": "DODO_V2",
            "proportion": "0"
        },
        {
            "name": "Ellipsis",
            "proportion": "0"
        },
        {
            "name": "Mooniswap",
            "proportion": "0"
        },
        {
            "name": "MultiHop",
            "proportion": "0"
        },
        {
            "name": "Nerve",
            "proportion": "0"
        },
        {
            "name": "Synapse",
            "proportion": "0"
        },
        {
            "name": "PancakeSwap",
            "proportion": "0"
        },
        {
            "name": "PancakeSwap_V2",
            "proportion": "1"
        },
        {
            "name": "SushiSwap",
            "proportion": "0"
        },
        {
            "name": "Smoothy",
            "proportion": "0"
        },
        {
            "name": "ApeSwap",
            "proportion": "0"
        },
        {
            "name": "CafeSwap",
            "proportion": "0"
        },
        {
            "name": "CheeseSwap",
            "proportion": "0"
        },
        {
            "name": "JulSwap",
            "proportion": "0"
        },
        {
            "name": "LiquidityProvider",
            "proportion": "0"
        },
        {
            "name": "WaultSwap",
            "proportion": "0"
        },
        {
            "name": "FirebirdOneSwap",
            "proportion": "0"
        },
        {
            "name": "JetSwap",
            "proportion": "0"
        },
        {
            "name": "ACryptoS",
            "proportion": "0"
        },
        {
            "name": "KyberDMM",
            "proportion": "0"
        }
    ],
    "orders": [
        {
            "makerToken": "0xaf3889ba617ac973b358513d9031778d2bc783df",
            "takerToken": "0x55d398326f99059ff775485246999027b3197955",
            "makerAmount": "1548581394730707",
            "takerAmount": "1000000000000000000",
            "fillData": {
                "tokenAddressPath": [
                    "0x55d398326f99059ff775485246999027b3197955",
                    "0xaf3889ba617ac973b358513d9031778d2bc783df"
                ],
                "router": "0x10ed43c718714eb63d5aa57b78b54704e256024e"
            },
            "source": "PancakeSwap_V2",
            "sourcePathId": "0x7fd9558bff4261870d22f918a3aac9c40a582fa7aa7d561d29dd84f4ae1339aa",
            "type": 0
        }
    ],
    "allowanceTarget": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
    "sellTokenToEthRate": "379.528873271830081228",
    "buyTokenToEthRate": "0"
}

1 Answer 1

1

It is likely your transaction is failing and Metamask incorrectly calculates the gas as the entire blocks gas.

Looking at the output here I can currently see it is producing an error, https://bsc.api.0x.org/swap/v1/quote?sellToken=0x55d398326f99059ff775485246999027b3197955&buyToken=0xaf3889ba617ac973b358513d9031778d2bc783df&sellAmount=1000000000000000000&slippagePercentage=0.10&takerAddress=0x06125e1457f833E29D5aebAaCdF8eED8A6Febaee

{
    code: 105,
    reason: "IncompleteTransformERC20Error",
    values: {
        outputToken: "0xaf3889ba617ac973b358513d9031778d2bc783df",
        outputTokenAmount: "1373091610763976",
        minOutputTokenAmount: "1398576787535538"
    }
}

At this time 0xAPI only works with standard ERC20/BEP20 tokens which does not include tokens (like SHIBIC) that take a fee on transfer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.