Router v2
PancakeSwap is based on Uniswap v2. Read the Uniswap v2 documentation. For more in-depth information on the core contract logic, read the Uniswap v2 Core whitepaper.

Contract info

Contract name: PancakeRouter Contract address: 0x10ED43C718714eb63d5aA57B78B54704E256024E

Read functions

WETH

function WETH() external pure returns (address);
Returns the canonical address for Binance: WBNB token (WETH being a vestige from Ethereum network origins).

factory

function factory() external pure returns (address);
Returns the canonical address for PancakeFactory.
For explanations of the following, view the Uniswap v2 Internal Functions documentation.

getAmountOut

function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut);

getAmountIn

function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn);

getAmountsOut

function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts);

getAmountsIn

function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts);

quote

function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB);

Write functions

addLiquidity

1
function addLiquidity(
2
address tokenA,
3
address tokenB,
4
uint amountADesired,
5
uint amountBDesired,
6
uint amountAMin,
7
uint amountBMin,
8
address to,
9
uint deadline
10
) external returns (uint amountA, uint amountB, uint liquidity);
Copied!
Adds liquidity to a BEP20⇄BEP20 pool.
Name
Type
Text
tokenA
address
The contract address of one token from your liquidity pair.
tokenB
address
The contract address of the other token from your liquidity pair.
amountADesired
uint
The amount of tokenA you'd like to provide as liquidity.
amountBDesired
uint
The amount of tokenA you'd like to provide as liquidity.
amountAMin
uint
The minimum amount of tokenA to provide (slippage impact).
amountBMin
uint
The minimum amount of tokenB to provide (slippage impact).
to
address
Address of LP Token recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

addLiquidityETH

1
function addLiquidityETH(
2
address token,
3
uint amountTokenDesired,
4
uint amountTokenMin,
5
uint amountETHMin,
6
address to,
7
uint deadline
8
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
Copied!
Adds liquidity to a BEP20⇄WBNB pool.
Name
Type
Text
addLiquidityETH
uint
The payable amount in BNB.
token
address
The contract address of the token to add liquidity.
amountTokenDesired
uint
The amount of the token you'd like to provide as liquidity.
amountTokenMin
uint
The minimum amount of the token to provide (slippage impact).
amountETHMin
uint
The minimum amount of BNB to provide (slippage impact).
to
address
Address of LP Token recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

removeLiquidity

1
function removeLiquidity(
2
address tokenA,
3
address tokenB,
4
uint liquidity,
5
uint amountAMin,
6
uint amountBMin,
7
address to,
8
uint deadline
9
) external returns (uint amountA, uint amountB);
Copied!
Removes liquidity from a BEP20⇄BEP20 pool.
Name
Type
Text
tokenA
address
The contract address of one token from your liquidity pair.
tokenB
address
The contract address of the other token from your liquidity pair.
liquidity
uint
The amount of LP Tokens to remove.
amountAMin
uint
The minimum amount of tokenA to remove (slippage impact).
amountBMin
uint
The minimum amount of tokenB to remove (slippage impact).
to
address
Address of LP Token recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

removeLiquidityETH

1
function removeLiquidityETH(
2
address token,
3
uint liquidity,
4
uint amountTokenMin,
5
uint amountETHMin,
6
address to,
7
uint deadline
8
) external returns (uint amountToken, uint amountETH);
Copied!
Removes liquidity from a BEP20⇄WBNB pool.
Name
Type
Text
token
address
The contract address of the token to remove liquidity.
liquidity
uint
The amount of LP Tokens to remove.
amountTokenMin
uint
The minimum amount of the token to remove (slippage impact).
amountETHMin
uint
The minimum amount of BNB to remove (slippage impact).
to
address
Address of LP Token recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

removeLiquidityETHSupportingFeeOnTransferTokens

1
function removeLiquidityETHSupportingFeeOnTransferTokens(
2
address token,
3
uint liquidity,
4
uint amountTokenMin,
5
uint amountETHMin,
6
address to,
7
uint deadline
8
) external returns (uint amountETH);
Copied!
Removes liquidity from a BEP20⇄WBNB for tokens that take a fee on transfer.
Name
Type
Text
token
address
The contract address of the token to remove liquidity.
liquidity
uint
The amount of LP Tokens to remove.
amountTokenMin
uint
The minimum amount of the token to remove (slippage impact).
amountETHMin
uint
The minimum amount of BNB to remove (slippage impact).
to
address
Address of LP Token recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

removeLiquidityETHWithPermit

1
function removeLiquidityETHWithPermit(
2
address token,
3
uint liquidity,
4
uint amountTokenMin,
5
uint amountETHMin,
6
address to,
7
uint deadline,
8
bool approveMax, uint8 v, bytes32 r, bytes32 s
9
) external returns (uint amountToken, uint amountETH);
Copied!
Removes liquidity from a BEP20⇄WBNB and receives BNB, without pre-approval, via permit.
Name
Type
Text
token
address
The contract address of the token to remove liquidity.
liquidity
uint
The amount of LP Tokens to remove.
amountTokenMin
uint
The minimum amount of the token to remove (slippage impact).
amountETHMin
uint
The minimum amount of BNB to remove (slippage impact).
to
address
Address of LP Token recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.
approveMax
bool
Whether or not the approval amount in the signature is for liquidity or uint(-1).
v
uint8
The v component of the permit signature.
r
bytes32
The r component of the permit signature.
s
bytes32
The s component of the permit signature.

removeLiquidityETHWithPermitSupportingFeeOnTransferTokens

1
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
2
address token,
3
uint liquidity,
4
uint amountTokenMin,
5
uint amountETHMin,
6
address to,
7
uint deadline,
8
bool approveMax, uint8 v, bytes32 r, bytes32 s
9
) external returns (uint amountETH);
Copied!
Removes liquidity from a BEP20⇄WBNB and receives BNB via permit for tokens that take a fee on transfer.
Name
Type
Text
token
address
The contract address of the token to remove liquidity.
liquidity
uint
The amount of LP Tokens to remove.
amountTokenMin
uint
The minimum amount of the token to remove (slippage impact).
amountETHMin
uint
The minimum amount of BNB to remove (slippage impact).
to
address
Address of LP Token recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.
approveMax
bool
Whether or not the approval amount in the signature is for liquidity or uint(-1).
v
uint8
The v component of the permit signature.
r
bytes32
The r component of the permit signature.
s
bytes32
The s component of the permit signature.

removeLiquidityWithPermit

1
function removeLiquidityWithPermit(
2
address tokenA,
3
address tokenB,
4
uint liquidity,
5
uint amountAMin,
6
uint amountBMin,
7
address to,
8
uint deadline,
9
bool approveMax, uint8 v, bytes32 r, bytes32 s
10
) external returns (uint amountA, uint amountB);
Copied!
Removes liquidity from a BEP20⇄BEP20, without pre-approval, via permit.
Name
Type
Text
tokenA
address
The contract address of one token from your liquidity pair.
tokenB
address
The contract address of the other token from your liquidity pair.
liquidity
uint
The amount of LP Tokens to remove.
amountTokenMin
uint
The minimum amount of the token to remove (slippage impact).
amountETHMin
uint
The minimum amount of BNB to remove (slippage impact).
to
address
Address of LP Token recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.
approveMax
bool
Whether or not the approval amount in the signature is for liquidity or uint(-1).
v
uint8
The v component of the permit signature.
r
bytes32
The r component of the permit signature.
s
bytes32
The s component of the permit signature.

swapETHForExactTokens

1
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
2
external
3
payable
4
returns (uint[] memory amounts);
Copied!
Receive an exact amount of output tokens for as little BNB as possible.
Name
Type
Text
swapETHForExactTokens
uint
Payable BNB amount.
amountOut
uint
The amount tokens to receive.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

swapExactETHForTokens

1
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
2
external
3
payable
4
returns (uint[] memory amounts);
Copied!
Receive as many output tokens as possible for an exact amount of BNB.
Name
Type
Text
swapExactETHForTokens
uint
Payable BNB amount.
amountOutMin
uint
The minimum amount tokens to receive.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

swapExactETHForTokensSupportingFeeOnTransferTokens

1
function swapExactETHForTokensSupportingFeeOnTransferTokens(
2
uint amountOutMin,
3
address[] calldata path,
4
address to,
5
uint deadline
6
) external payable;
Copied!
Receive as many output tokens as possible for an exact amount of BNB. Supports tokens that take a fee on transfer.
Name
Type
Text
swapExactETHForTokensSupportingFeeOnTransferTokens
uint
Payable BNB amount.
amountOutMin
uint
The minimum amount tokens to receive.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

swapExactTokensForETH

1
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
2
external
3
returns (uint[] memory amounts);
Copied!
Receive as much BNB as possible for an exact amount of input tokens.
Name
Type
Text
amountIn
uint
Payable amount of input tokens.
amountOutMin
uint
The minimum amount tokens to receive.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

swapExactTokensForETHSupportingFeeOnTransferTokens

1
function swapExactTokensForETHSupportingFeeOnTransferTokens(
2
uint amountIn,
3
uint amountOutMin,
4
address[] calldata path,
5
address to,
6
uint deadline
7
) external;
Copied!
Receive as much BNB as possible for an exact amount of tokens. Supports tokens that take a fee on transfer.
Name
Type
Text
amountIn
uint
Payable amount of input tokens.
amountOutMin
uint
The minimum amount tokens to receive.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

swapExactTokensForTokens

1
function swapExactTokensForTokens(
2
uint amountIn,
3
uint amountOutMin,
4
address[] calldata path,
5
address to,
6
uint deadline
7
) external returns (uint[] memory amounts);
Copied!
Receive as many output tokens as possible for an exact amount of input tokens.
Name
Type
Text
amountIn
uint
Payable amount of input tokens.
amountOutMin
uint
The minimum amount tokens to receive.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

swapExactTokensForTokensSupportingFeeOnTransferTokens

1
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
2
uint amountIn,
3
uint amountOutMin,
4
address[] calldata path,
5
address to,
6
uint deadline
7
) external;
Copied!
Receive as many output tokens as possible for an exact amount of input tokens. Supports tokens that take a fee on transfer.
Name
Type
Text
amountIn
uint
Payable amount of input tokens.
amountOutMin
uint
The minimum amount tokens to receive.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

swapTokensForExactETH

1
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
2
external
3
returns (uint[] memory amounts);
Copied!
Receive an exact amount of ETH for as few input tokens as possible.
Name
Type
Text
amountOut
uint
Payable amount of input tokens.
amountInMax
uint
The minimum amount tokens to input.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

swapTokensForExactTokens

1
function swapTokensForExactTokens(
2
uint amountOut,
3
uint amountInMax,
4
address[] calldata path,
5
address to,
6
uint deadline
7
) external returns (uint[] memory amounts);
Copied!
Receive an exact amount of output tokens for as few input tokens as possible.
Name
Type
Text
amountOut
uint
Payable amount of input tokens.
amountInMax
uint
The minimum amount tokens to input.
path (address[])
address
An array of token addresses. path.length must be >= 2. Pools for each consecutive pair of addresses must exist and have liquidity.
to
address
Address of recipient.
deadline
uint
Unix timestamp deadline by which the transaction must confirm.

Interface

1
import '@uniswap/v2-core/contracts/interfaces/IPancakeRouter.sol';
Copied!
1
pragma solidity >=0.6.2;
2
3
interface IPancakeRouter01 {
4
function factory() external pure returns (address);
5
function WETH() external pure returns (address);
6
7
function addLiquidity(
8
address tokenA,
9
address tokenB,
10
uint amountADesired,
11
uint amountBDesired,
12
uint amountAMin,
13
uint amountBMin,
14
address to,
15
uint deadline
16
) external returns (uint amountA, uint amountB, uint liquidity);
17
function addLiquidityETH(
18
address token,
19
uint amountTokenDesired,
20
uint amountTokenMin,
21
uint amountETHMin,
22
address to,
23
uint deadline
24
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
25
function removeLiquidity(
26
address tokenA,
27
address tokenB,
28
uint liquidity,
29
uint amountAMin,
30
uint amountBMin,
31
address to,
32
uint deadline
33
) external returns (uint amountA, uint amountB);
34
function removeLiquidityETH(
35
address token,
36
uint liquidity,
37
uint amountTokenMin,
38
uint amountETHMin,
39
address to,
40
uint deadline
41
) external returns (uint amountToken, uint amountETH);
42
function removeLiquidityWithPermit(
43
address tokenA,
44
address tokenB,
45
uint liquidity,
46
uint amountAMin,
47
uint amountBMin,
48
address to,
49
uint deadline,
50
bool approveMax, uint8 v, bytes32 r, bytes32 s
51
) external returns (uint amountA, uint amountB);
52
function removeLiquidityETHWithPermit(
53
address token,
54
uint liquidity,
55
uint amountTokenMin,
56
uint amountETHMin,
57
address to,
58
uint deadline,
59
bool approveMax, uint8 v, bytes32 r, bytes32 s
60
) external returns (uint amountToken, uint amountETH);
61
function swapExactTokensForTokens(
62
uint amountIn,
63
uint amountOutMin,
64
address[] calldata path,
65
address to,
66
uint deadline
67
) external returns (uint[] memory amounts);
68
function swapTokensForExactTokens(
69
uint amountOut,
70
uint amountInMax,
71
address[] calldata path,
72
address to,
73
uint deadline
74
) external returns (uint[] memory amounts);
75
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
76
external
77
payable
78
returns (uint[] memory amounts);
79
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
80
external
81
returns (uint[] memory amounts);
82
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
83
external
84
returns (uint[] memory amounts);
85
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
86
external
87
payable
88
returns (uint[] memory amounts);
89
90
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
91
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
92
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
93
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
94
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
95
}
96
97
// File: contracts\interfaces\IPancakeRouter02.sol
98
99
pragma solidity >=0.6.2;
100
101
interface IPancakeRouter02 is IPancakeRouter01 {
102
function removeLiquidityETHSupportingFeeOnTransferTokens(
103
address token,
104
uint liquidity,
105
uint amountTokenMin,
106
uint amountETHMin,
107
address to,
108
uint deadline
109
) external returns (uint amountETH);
110
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
111
address token,
112
uint liquidity,
113
uint amountTokenMin,
114
uint amountETHMin,
115
address to,
116
uint deadline,
117
bool approveMax, uint8 v, bytes32 r, bytes32 s
118
) external returns (uint amountETH);
119
120
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
121
uint amountIn,
122
uint amountOutMin,
123
address[] calldata path,
124
address to,
125
uint deadline
126
) external;
127
function swapExactETHForTokensSupportingFeeOnTransferTokens(
128
uint amountOutMin,
129
address[] calldata path,
130
address to,
131
uint deadline
132
) external payable;
133
function swapExactTokensForETHSupportingFeeOnTransferTokens(
134
uint amountIn,
135
uint amountOutMin,
136
address[] calldata path,
137
address to,
138
uint deadline
139
) external;
140
}
Copied!