I am trying to deploy my contract using geth on my private network. When i use truffle mirate --reset shows that is has been deployed but the metamask gives me an error( ALERT: Transaction Error. Exception thrown in contract code metamask). So i am using this command eth.getTransactionReceipt with the transaction hash to see if it's ok but the transactionIndex = 0. I read that if transactionIndex = 0 the contract is not deployed. Right? Can you help? I tried to deployed in remix with the provider of my netowrk and it gives me this error (gas required exceeds allowance (8000000) or always failing transaction)
Below i have the contract code.
pragma solidity ^0.5.8;
contract Creation {
struct hero {
string name;
int life;
int lvl;
int xp;
int attack;
int winCount;
int trophies;
int lossCount;
}
hero[] public heroes;
struct enemy {
string name;
int life;
int lvl;
int xp;
int attack;
}
int basiclife=50;
enemy[] public enemies;
mapping (uint => address) public herotoowner;
mapping (address => uint) public heroCount;
mapping (uint => address) public monstertoowner;
uint public monsterCount;
function createhero(string memory _name) payable public {
require(heroCount[msg.sender] == 0);
uint id= heroes.push(hero(_name,basiclife,1,0,20,0,0,0))-1;
herotoowner[id] = msg.sender;
heroCount[msg.sender]++;
}
function enemyRage(int _herolvl) public {
uint id=enemies.push(enemy("Rage",20*_herolvl,_herolvl,7*_herolvl,5*_herolvl))-1;
monstertoowner[id] = msg.sender;
monsterCount++;
}
function enemyDerpina(int _herolvl) public {
uint id=enemies.push(enemy("Derpina",40*_herolvl,_herolvl,14*_herolvl,10*_herolvl))-1;
monstertoowner[id] = msg.sender;
monsterCount++;
}
function getHerosByOwner(address owner) external view returns( uint ) {
uint result =3;
for (uint i = 0; i < 3; i++) {
if (herotoowner[i] == owner) {
result = i;
break;
}
}
return result;
}
function getmonstersByOwner(address owner) external view returns( uint ) {
uint result =0;
for (uint i = enemies.length ; i > 0 ; i--) {
if (monstertoowner[i] == owner) {
result = i;
break;
}
}
return result;
}
uint nonce=0;
function randNum(int _num) private returns(int) { //sinartisi gia tixaies times
int randomnumber = int(keccak256(abi.encodePacked(now, msg.sender, nonce))) % _num;
if (randomnumber <=0) {
randomnumber=(-1)*randomnumber;
}
nonce++;
return randomnumber;
}
function attack_hero(uint _heroid, uint _monsterid, int _num ) external {
hero storage myhero = heroes[_heroid];
enemy storage monster = enemies[_monsterid];
int attackofhero=0;
if(_num==0) {
attackofhero=randNum(myhero.attack);
}
monster.life=monster.life - attackofhero;
int attackofmonster=randNum(monster.attack);
myhero.life=myhero.life - attackofmonster;
if (monster.life <= 0 && myhero.life >0) {
myhero.winCount++;
myhero.xp+=monster.xp;
if (randNum(100) > 50 ){
myhero.trophies++;
}
}
if (myhero.xp>=10+2*myhero.lvl){
myhero.lvl++;
myhero.xp=0; //reset you xp
myhero.life=basiclife*myhero.lvl;
myhero.attack=myhero.attack*myhero.lvl;
}
if (myhero.life <= 0 ) { //ita
myhero.lossCount++;
}
}
function resurrection(uint _heroid) public {
hero storage myhero = heroes[_heroid];
myhero.life=basiclife*myhero.lvl;
}
}
status
field in the receipt to check if a transaction was successful.