Conversion from BNB to WBNB failing

Hi, I am making a contract that will swap tokens on DEXes, but to test my functionality I need to convert BNB to WBNB. If I am correct, I will get WBNB when I transfer BNB to WBNB contract address(or call the `deposit` function with transaction value), but when I try to do that, the transaction reverts. I am testing the contract on local ganache testnet that forks BSC mainnet.
Here is my contract:
// SPDX-License-Identifier: UNLICENSED

pragma solidity >0.7.0;

import “./Ownable.sol”;
import “./IERC20.sol”;
import “./DEXIface.sol”;

contract Trader is Ownable {
mapping(string => address) public DEXRouters;

event Received(address, uint);

receive() external onlyOwner payable {
emit Received(msg.sender, msg.value);

function swap(string memory _exch, address[] memory _path, uint _amountIn, uint _amountOutMin) public onlyOwner {
_swap(_exch, _path, _amountIn, _amountOutMin);

function _swap(string memory _exch, address[] memory _path, uint _amountIn, uint _amountOutMin) internal {
IDEXV2Router01 exchClient = IDEXV2Router01(DEXRouters[_exch]);

IERC20 buyToken = IERC20(_path[0]);

require(buyToken.approve(DEXRouters[_exch], _amountIn), ‘approve failed.’);

exchClient.swapExactTokensForTokens(_amountIn, _amountOutMin, _path, msg.sender, block.timestamp);

buyToken.approve(DEXRouters[_exch], 0);

function transfer(address payable receiver, uint amount) external payable onlyOwner {

function addDEXRouter(string calldata name, address routerAddress) external onlyOwner {
DEXRouters[name] = routerAddress;

function deleteDEXRouter(string calldata name) external onlyOwner {
delete DEXRouters[name];
I am calling the `transfer` function with WBNB address. Thank you for any help.

What do you think?

10 Points
Upvote Downvote

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

One Comment

Cryptocurrencies are surprisingly similar to Medieval relics | by Ugo Bardi | INSURGE intelligence

Newly listed options chains. Or in other words, where you can find the next NEGG.