Deploy BEP token to BSC

Hello @abcoathup
Can you help me for this functionality on Binance Smart Chain too?

I did follow your way to check transferFrom functionality and I have error transaction .

contract TestVault is BEP20{
    using SafeBEP20 for IBEP20;
    using Address for address;
    using SafeMath for uint256;

    IBEP20 public token;
    
    event DoneStuff(address from ,address to ,uint256 amount);

    uint256 public min = 10000;
    uint256 public constant max = 10000;

    address public governance;
    address public controller;
    
      constructor(address _token, address _controller)
        public
        BEP20(
            string(abi.encodePacked("Test ", BEP20(_token).name())),
            string(abi.encodePacked("test", BEP20(_token).symbol()))
        )
    {
        token = IBEP20(_token);
        governance = msg.sender;
        controller = _controller;
    }
    
    function balance() public view returns(uint256){
        return token.balanceOf(address(this));
    }
    
    function doStuff() external{
        address from = msg.sender;
        address to = address(this);
        uint256 amount = 1e18;
        
        token.transferFrom(from,to,amount);
        emit DoneStuff(from,to,amount);
    }
    
    function deposit(uint256 _amount) public {
        // uint256 _pool = balance();
        // uint256 _before = token.balanceOf(address(this));
        token.safeTransferFrom(msg.sender,address(this), _amount);
        // uint256 _after = token.balanceOf(address(this));
        // _amount = _after.sub(_before); // Additional check for deflationary tokens
        // uint256 shares = 0;
        // if (totalSupply() == 0) {
        //     shares = _amount;
        //     // 
        // } else {
        //     shares = (_amount.mul(totalSupply())).div(_pool);
        // }
        // _mint(msg.sender, shares);
    }
}
1 Like

Hi @Denis9k,

Welcome to the community :wave:

I am not familiar with BEP20 and I am not really sure what you are trying to do in your contract. I assume take payment in a token?

If so, you may want to look at: Example on how to use ERC20 token in another contract

1 Like

Hello @abcoathup .
Thanks for being with me for now. I just have seen your great message for me . I really am appreciate for your help. So what do I want to try?
I want to send some my own token to contract (this is vault contract) . so example : users deposit their crypto assets in vault . then vault contract locked the assets . but I can not send my own token or BNB,CAKE ,BUSD to the contract . This is my problem for now. Approval is working well. but when I deposit , I have transaction issue every time. but one
is interest . If I deposit zero amount, it is working .
Here are my issue .

So I have read your article carefully and I was impression for that .That’s why I wanted to add doStuff code like your code to see how it will work . but It is not going well in my side with BSC .
when I send amount in my wallet , it has amount in contract correctly. but if I use deposit function, it is nothing to lock .
Can you embrace for this issue once more? Thanks

1 Like

Hi @Denis9k,

I suggest trying a simple example first such as Example on how to use ERC20 token in another contract