3

I'm trying to swap 0.1 Eth to buy LINK token, don't know how to write the parameter "amountIn", my code:

const amountIn = 100000000000000000 // 0.1 * 10^18 == 0.1 Eth

const trade = new Trade(
    route, 
    new TokenAmount(wETH, amountIn), // <------ check direction
    TradeType.EXACT_INPUT) 

// ... 

// transaction
const tx = await uniswap.swapExactETHForTokens(
    JSBI.toNumber(amountOutMin),
    path,
    to,
    deadline,
    { 
        value,
        gasLimit: 300000,
        gasPrice: ethers.utils.parseUnits("15", "gwei") 
    }
)

It shows error at function uniswap.swapExactETHForTokens:

Error: overflow (fault="overflow", operation="BigNumber.from", 
  value=572968729169762500000, code=NUMERIC_FAULT, version=bignumber/5.4.0)
at: ...
  reason: 'overflow',
  code: 'NUMERIC_FAULT',
  fault: 'overflow',
  operation: 'BigNumber.from',
  value: 572968729169762500000

I tried const amountIn = 1, then the transaction works fine, etherscan shows the transaction value is 1 wei.

How to transfer 0.1 Eth?

BTW, why need the syntax of the extra json after params for swapExactETHForTokens, where can I find the document about that?

const tx = await uniswap.swapExactETHForTokens(
    ... arguments,
    { // <------ What's this json for ?
        value,
        gasLimit: 300000,
        gasPrice: ethers.utils.parseUnits("15", "gwei") 
    }
)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.