swapExactETHForTokens


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

์ฝ”์ธ->ํ† ํฐ์œผ๋กœ swap (FROM->TO)
โ€ป ์ฝ”์ธ์€ msg.value ํ˜•ํƒœ๋กœ ์ถ”๊ฐ€ 

Parameters
TypeValueDescription

uint

_amountOutMin

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

address[]

_path

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

address

_to

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

uint

_deadline

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


Return Values
TypeValueDescription

uint[]

amounts

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


Example
// 5000 ETH swapconst overrides = {    gasLimit: 9999999,    value : 5000}// ํ† ํฐ ๊ฑฐ๋ž˜์— ๋Œ€ํ•œ ํ—ˆ์šฉawait mockToken0Contract.approve(routerContract.address, MaxUint256)// swapawait swapRouterContract.swapExactETHForTokens(    0,    [WMATICContract.address, mockToken0Contract.address],    accounts[0].address,    MaxUint256,    overrides)

2022.12.22

Last updated