I'm trying to develop a DApp using React and Solidity using an ERC20 contract, I've deployed my smart contract on Rinkeby and am able to interact with it using name()
and symbol()
, however, I cannot execute payable functions like transfer()
, the following error is displayed each time:
MetaMask - RPC Error: execution reverted {code: -32000, message: 'execution reverted'}
I have tried simply calling contract.transfer( ... )
and putting quotes around the amount being sent, neither works.
JS:
await contract.transfer.call(account, 50)
Sol:
interface IERC20 {
function transfer(address recipient, uint256 amount) external returns (bool);
// Omitted other functions...
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract MyCoin is IERC20 {
function transfer(address receiver, uint256 numTokens) public override returns (bool) {
require(numTokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(numTokens);
balances[receiver] = balances[receiver].add(numTokens);
emit Transfer(msg.sender, receiver, numTokens);
return true;
}
}