I'm working on a simple Bridge. Whenever I try to deposit on the foreign chain to the foreign bridge contract, it works well. But whenever I tried to deposit token to the native chain bridge contract.
I get this error:
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error.
{
"code": 3,
"message": "execution reverted: BEP20: burn amount exceeds balance",
"data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002242455032303a206275726e20616d6f756e7420657863656564732062616c616e6365000000000000000000000000000000000000000000000000000000000000"
}
My bridge Deposit function:
function _deposit(
address token, // token that user send (if token address < 32, then send native coin)
uint256 value, // tokens value
uint256 toChainId // destination chain Id where will be claimed tokens
)
internal
returns (address pair_token)
{
Token memory pair = tokenPair[toChainId][token];
require(pair.token != address(0), "There is no pair");
pair_token = pair.token;
uint256 fee = msg.value;
if (token <= MAX_NATIVE_COINS) {
require(value <= msg.value, "Wrong value");
fee -= value;
} else {
if(pair.isWrapped) {
IBEP20TokenCloned(token).burnFrom(msg.sender, value);
} else {
tokenDeposits[token] += value;
token.safeTransferFrom(msg.sender, address(this), value);
}
}
if (fee != 0) {
feeTo.safeTransferETH(fee);
emit Fee(msg.sender, fee);
}
}
My BEP20Cloned Contract for mint.
// initialize contract. Used instead of constructor in cloned contract
function initialize(address newOwner, string calldata name, string calldata symbol, uint8 decimals) external {
require(!_isInitialized, "Already Initialized");
_isInitialized = true;
minter = _msgSender(); // set bridge as minter
emit SetMinter(address(0), minter);
_name = name;
_symbol = symbol;
_decimals = decimals;
_owner = newOwner;
emit OwnershipTransferred(address(0), newOwner);
}
Best Answer
You should check the balance of the account. It seems there is not enough tokens in that wallet (thats what it usually means when it throws that message). You should put a check there to see if the balance is enough to cover the fees and revert if not. That would give you a hint and help you debug.