Apparently it's possible to take a flash loan on PancakeSwap, being that it's a fork of Uniswap. However, I haven't found any examples anywhere of a flash loan on PancakeSwap, nor do the docs mention it anywhere.

What's the simplest example of a contract taking a flash loan from PancakeSwap?

The flash loan would:

  1. Borrow a certain amount of some token (say CAKE) from PancakeSwap
  2. Pay back the required amount of the token

1 Answer 1


PancakeSwap is a fork of Uniswap V2, which allows flashswaps. An example of flashswap using Uniswap V2 can be found here: https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/examples/ExampleFlashSwap.sol

it is invoked by calling the swap function of the Uniswap V2 pair you wish to take the loan from, which will call a callback function in your contract. It originates from this line in the UniswapV2Pair.sol contract(source: https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2Pair.sol):

if (data.length > 0) IUniswapV2Callee(to).uniswapV2Call(msg.sender, amount0Out, amount1Out, data);

In pancake everything is the same, except instead the name of the callback which becomes pancakeCall (instead of uniswapV2Call)

if (data.length > 0) IPancakeCallee(to).pancakeCall(msg.sender, amount0Out, amount1Out, data);

All you need to do is change the the function signature in your FlashLoan Receiver method from this:

function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external override { ... }

to this

function pancakeCall(address sender, uint amount0, uint amount1, bytes calldata data) external override { ... }

Edit: link to the pancakeswap pool contract here: https://github.com/pancakeswap/pancake-swap-core/blob/master/contracts/PancakePair.sol

you will need to specify the address of the pool you wish to take the loan from

  • Edited the terminology (it's a flash swap, not a flash loan) + it's a callback function (where the flashswapped token is used) Dec 8, 2021 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.