I have my ExampleToken contract from Openzeppelin:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol';
contract ExampleToken is ERC20 {
address public owner;
constructor() ERC20('ExampleToken', 'EXM') {
_mint(msg.sender, 1000000 * 10**18);
owner = msg.sender;
}
}
And I want my other contract to manage those tokens.
I was trying to create function which will send 100 of my ExampleToken to anyone who call this function.
And even if remix output showed that transaction was correct, I couldn't see any balance changes either on my contract balance, or msg.sender balance.
Here is my other contract:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
import './ExampleToken.sol';
contract MyContract {
address public owner;
uint public EXMbalance;
ExampleToken public exampleToken;
constructor() {
owner = msg.sender;
exampleToken = new ExampleToken();
EXMbalance = exampleToken.balanceOf(address(this));
}
function getBalanceOf(address adr) public view returns(uint) {
return exampleToken.balanceOf(adr) / 10**18;
}
function contractBalance() public view returns(uint) {
return address(this).balance ;
}
function requestEXM(uint quantity) public {
require(quantity <= 100 && quantity > 0);
exampleToken.approve(address(this), quantity);
exampleToken.transferFrom(address(this), msg.sender, quantity);
EXMbalance -= quantity;
}
function invest() external payable {
}
}

transferfunction totransferFromcause it seemed like it's not working too, I couldn't see balance of my coin, it was still 0. Now I realized that I was sending 100 WEI and I was reading the balance converted to ETH (* 10**18).I moved back to
– BlackH3art Jan 24 '22 at 13:48transferfunction, fixed the converting problem, and it's working fine. Thanks.