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

TypeValueDescription

uint

_amountOut

swap을 톡해 νšλ“ ν•  토큰 개수 (Slippage κ°’ 이용)

address[]

_path

swap에 μ‚¬μš© 될 토큰 쌍 μ£Όμ†Œ

address

_to

swap ν•  계정 μ£Όμ†Œ

uint

_deadline

νŠΈλžœμž­μ…˜ μ΅œλŒ€ μ‹œκ°„ (ν˜„μž¬μ‹œκ°„+μ’…λ£Œμ‹œκ°„, sec단)

Return Values

TypeValueDescription

uint[]

amounts

swap 된 토큰 개수

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