I got this error:
ERC20InsufficientAllowance
Parameters:
{
"spender": {
"value": "0xb31BA5cDC07A2EaFAF77c95294fd4aE27D04E9CA",
"documentation": "Address that may be allowed to operate on tokens without being their owner."
},
"allowance": {
"value": "0",
"documentation": "Amount of tokens a `spender` is allowed to operate with."
},
"needed": {
"value": "10",
"documentation": "Minimum amount required to perform a transfer."
}
}
You may want to cautiously increase the gas limit if the transaction went out of gas.
My Contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
contract xBTCWrapper is ERC20, ERC20Wrapper {
IERC20 public _underlying;
constructor(IERC20 underlyingToken)
ERC20("Wrapped xBTC", "wxBTC")
ERC20Wrapper(underlyingToken)
{
_underlying = underlyingToken;
}
function getUnderlyingBalance() public view returns(uint256) {
return _underlying.balanceOf(_msgSender());
}
function decimals() public view virtual override(ERC20Wrapper, ERC20) returns (uint8) {
return 18;
}
}
Note I've tried to send it with only transfer but this time I got ERC20InsufficentBalance Error, which is weird because I've tokens.
using SafeERC20.transfer instead of transferFrom
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
contract xBTCWrapper is ERC20, ERC20Wrapper {
IERC20 public _underlying;
constructor(IERC20 underlyingToken)
ERC20("Wrapped xBTC", "wxBTC")
ERC20Wrapper(underlyingToken)
{
_underlying = underlyingToken;
}
function depositFor(address account, uint256 value) public virtual override(ERC20Wrapper) returns (bool) {
address sender = _msgSender();
if (sender == address(this)) {
revert ERC20InvalidSender(address(this));
}
if (account == address(this)) {
revert ERC20InvalidReceiver(account);
}
SafeERC20.safeTransfer(_underlying, address(this), value);
_mint(account, value);
return true;
}
function getUnderlyingBalance() public view returns(uint256) {
return _underlying.balanceOf(_msgSender());
}
function decimals() public view virtual override(ERC20Wrapper, ERC20) returns (uint8) {
return 18;
}
}
The other error:
ERC20InsufficientBalance
Parameters:
{
"sender": {
"value": "0x7C4e30a43ecC4d3231b5B07ed082329020D141F3",
"documentation": "Address whose tokens are being transferred."
},
"balance": {
"value": "0",
"documentation": "Current balance for the interacting account."
},
"needed": {
"value": "10",
"documentation": "Minimum amount required to perform a transfer."
}
}
You may want to cautiously increase the gas limit if the transaction went out of gas.
balanceOf(sender)
, you can get balance by constructor or provide mint function for owner/admin. Btw, please provide all full steps you did run through, it will help everyone can understand your concept.