want to swap all the eth on my contract per busd... how to input that balance in swapExactETHForTokens{ value: msg.value }???

May 28, 2021, 9:12 PM
thanks
hi, how to know how many x tokens are on my smart contract??
How is that function? with uint amount = address(this).balance; I get only eth or bnb amount.
May 28, 2021, 9:27 PM
IERC20(token).balanceOf(address(this))
need to use interface IERC20
define IERC20 public token; then call the balanceOf the contract as shown above
May 28, 2021, 9:37 PM
using this IERC20(token).balanceOf(address(this)) should i provide token address on "token"?
should i use IERC20 from openzeppelin, right?
May 28, 2021, 9:41 PM
yes
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
May 28, 2021, 9:49 PM
fine
May 28, 2021, 9:52 PM
might not need it all, depends what you are trying to do
May 28, 2021, 9:52 PM
have you even used this fucntion ? swapExactTokensForETH
May 28, 2021, 9:52 PM
yes
May 28, 2021, 9:52 PM

© 2024 Draquery.com All rights reserved.