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