I have tried creating contracts in ethereum wallet but sometimes it shows an error while executing those contracts. The error says It seems this transaction will fail. If you submit it, it may consume all the gas you provide
. Can anyone help me with this issue?
My smart contract is like:
pragma solidity ^0.4.18;
contract MyToken {
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
}
contract TransferToken{
function sendTheToken(address _from, address _to, uint256 _value)public returns(string) {
address tokenContractAddress = <MyTokenaddress>
MyToken token = MyToken (tokenContractAddress);
bool sendSuccess = token.transferFrom(_from, _to, _value);
if(sendSuccess=true) return 'success';
else return 'Failure';
}
}
In the above contract MyToken is a contract that I have created earlier for crypto-currencies.
pragma solidity ^0.4.18;
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
contract MyToken {
string public name;
string public symbol;
uint8 public decimals = 2;
uint256 public totalSupply;
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 value);
function MyToken(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals);
balanceOf[msg.sender] = totalSupply;
name = tokenName;
symbol = tokenSymbol;
}
function _transfer(address _from, address _to, uint _value) internal {
require(_to != 0x0);
require(balanceOf[_from] >= _value);
require(balanceOf[_to] + _value > balanceOf[_to]);
uint previousBalances = balanceOf[_from] + balanceOf[_to];
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]);
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
}
require
checks or your contractthrows
. Mist provides max gas limit much more than your transaction needs (aI am not sure of the exact figure, you can see this while sending tx) so when the estimated gas of the transaction becomes equal to max gas supplied, Mist gives this error.