ERC20 Token Smart Contract:
contract ERC20token is IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) public _balances;
uint256 private _totalSupply;
uint256 private _cap=10000;
address public owner;
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
_mint(msg.sender, 2000);
owner=msg.sender;
}
/* other functions */
/**Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
* Requirements
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 _amount) public virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, _amount);
_totalSupply = _totalSupply.add(_amount);
_balances[account] = _balances[account].add(_amount);
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {
if (from == address(0)) { // When minting tokens
require(totalSupply().add(amount) <= _cap, "ERC20Capped: cap exceeded");
}
}
}
Test Smart Contract:
contract Test
{
address owner;
ERC20token ec;
constructor () public {
owner=msg.sender;
}
function Asset_mint(uint _amount) public
{
// some conditions
ec._mint(msg.sender, _amount);
}
}
When function Asset_mint()
is called with an amount more than msg.sender's balance, transaction is reverted with the error:
- The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance.
is it not possible to call a function in a smart contract from another smart contract by passing a numeric value?
anotherContract.someFunction{value:<somevalue>}();
?