Skip to content

Impossible to make it work #148

@PHPCreed

Description

@PHPCreed

I'm following the sdk but it's impossible for me to make the software work.

Im using this code:

   const priceRoute = await paraSwapMin.swap.getRate({
        srcToken: USDT,
        destToken: CAKE,
        amount: srcAmount,
        userAddress: wallet.address,
        side: SwapSide.SELL,
        options: {
            otherExchangePrices: true,
        }
    });

    console.log(priceRoute)

    const { bestRoute, others } = priceRoute;
    const swapExchange = bestRoute[0]?.swaps[0]?.swapExchanges[0];
    console.log("Swap Exchange: " + swapExchange.exchange)
    console.log("GAS USD: " + swapExchange.data.gasUSD)


    const destAmountFixed = new BigNumber(priceRoute.destAmount).times(0.99).toFixed(0); //get a little lower.
    const txParams = await paraSwapMin.swap.buildTx(
        {
            USDT,
            CAKE,
            srcAmount,
            destAmountFixed,
            priceRoute,
            userAddress: wallet.address,
            partner: 'sdk-test',
        }
    );

    const transaction = {
        ...txParams,
        gasPrice: '0x' + new BigNumber(txParams.gasPrice).toString(16),
        gasLimit: '0x' + new BigNumber(5000000).toString(16),
        value: '0x' + new BigNumber(txParams.value).toString(16),
    };

const txResponse = await wallet.sendTransaction(transaction);
    console.log(txResponse)
    const receipt = await txResponse.wait()

and although it's exact like the manual (and the test) i get data: { error: 'Validation failed: "srcToken" is required' }
I tried to add the key names as well, and it bypasses this error but then later i get

reason: 'chainId address mismatch',
code: 'INVALID_ARGUMENT',
argument: 'transaction',

Don't know what is the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions