swapETHForExactTokens

function swapETHForExactTokens(
    uint _amountOut, 
    address[] calldata _path, 
    address _to, 
    uint _deadline
) external virtual payable ensure(_deadline) returns (uint[] memory amounts)

์ฝ”์ธ->ํ† ํฐ์œผ๋กœ swap (TO->FROM)

โ€ป ์ฝ”์ธ์€ value ํ˜•ํƒœ๋กœ ์ถ”๊ฐ€

Parameters

Return Values

Example

// swap price
let amountsIn = await routerContract.getAmountsIn(
    5000, 
    [WMATICContract.address, mockToken0Contract.address]
)

const overrides = {
    gasLimit: 9999999,
    value : amountsIn[0]
}

// ํ† ํฐ ๊ฑฐ๋ž˜์— ๋Œ€ํ•œ ํ—ˆ์šฉ
await mockToken0Contract.approve(routerContract.address, MaxUint256)

// swap
await swapRouterContract.connect(accounts[0]).swapETHForExactTokens(
    5000,
    [WMATICContract.address, mockToken0Contract.address],
    accounts[0].address,
    MaxUint256,
    overrides
)

2022.12.23

Last updated