swapExactTokensForETH

function swapExactTokensForETH(
    uint _amountIn, 
    uint _amountOutMin, 
    address[] calldata _path, 
    address _to, 
    uint _deadline
) external virtual ensure(_deadline) returns (uint[] memory amounts)

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

Parameters

TypeValueDescription

uint

_amountIn

swap์— ์‚ฌ์šฉ ํ•  ํ† ํฐ ๊ฐœ์ˆ˜

uint

_amountOutMin

swap์—์„œ ํš๋“ ํ•  ์ตœ์†Œ ์ฝ”์ธ ๊ฐœ์ˆ˜ (Slippage ๊ฐ’ ์ด์šฉ)

address[]

_path

swap์— ์‚ฌ์šฉ ๋  ํ† ํฐ ์Œ ์ฃผ์†Œ

address

_to

swap ํ•  ๊ณ„์ • ์ฃผ์†Œ

uint

_deadline

ํŠธ๋žœ์žญ์…˜ ์ตœ๋Œ€ ์‹œ๊ฐ„ (ํ˜„์žฌ์‹œ๊ฐ„+์ข…๋ฃŒ์‹œ๊ฐ„, sec๋‹จ)

Return Values

TypeValueDescription

uint[]

amounts

swap ๋œ ํ† ํฐ ๊ฐœ์ˆ˜

Example

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

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

2022.12.23

Last updated