I'm trying to implement a simple card game. Actually, everything is working fine. Until I tried to move from 0.4.0 to 0.4.22. Any idea what is going wrong? Thanks a lot. And here the code:

pragma solidity ^0.4.22;
import "./InterfaceCardToDefense.sol";
contract CardToDefense is InterfaceCardToDefense{
mapping(int => mapping (int => int)) public AttackPosition2Defense;
mapping(int => string) public CardType2String;
mapping(int => string) public AttackType2String;
mapping(int => string) public Position2String;

function setAttackPositionToDefense(int attack, int position, int defense) public {
    AttackPosition2Defense[attack][position] = defense;
function setCardType2String(int _id, string name) public {
    CardType2String[_id] = name;
function setAttackType2String(int _id, string name) public {
    AttackType2String[_id]= name;
function setPosition2String(int _id, string name) public {
    Position2String[_id]= name;

PS: Getting this error message through truffle test. Right now even the original version doesn't work. Maybe it is unrelated to the pragma statement. Still a bit confusing

Deploying CardToDefense... ... 0x86f3f37d18cff4bcc9b91da5ce63c923eca5567243c52d84018d6f612f94db0d Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: The contract code couldn't be stored, please check your gas amount.

PPS: Just found out. If the interface is removed the contract can be deployed. Any Idea what that might be? Here is the interface:

contract InterfaceCardToDefense {
function AttackPosition2Defense(int, int) public returns(int);

I suspect that the interface is somehow wrong.

  • 1
    There are several breaking changes in 0.4.21 (and possibly before that as well, so you might wanna catch up on that. Solc 0.4.0 is pretty old. Oct 23, 2018 at 19:57
  • In addition, if you expect anyone here to refer to your specific problems, then you might wanna consider POSTING them here. Oct 23, 2018 at 20:00
  • Hi there, I added the error message- Thanks for your comment! Oct 23, 2018 at 20:22
  • That sounds like an network error, try deploying and interacting with the contract on something like remix, that might help.
    – GrandFleet
    Oct 23, 2018 at 21:13
  • A simple notice : truffle sends back the gas amount error as a generic error when it doesn't know what is the problem with the node, network or contract it is dealing with. It could be even an overflow or a mismatched argument types that can not be caught by truffle. Oct 24, 2018 at 9:35

1 Answer 1


The issue is the Byzantium hard fork.

A complete understanding of the details isn't important to resolve the issue. It's about compatibility. The gist is he upgrade changes the encoding of arguments send and received. For example, adding expected length arguments to support dynamic sized strings and arrays.

Therefore, to be compatible with the new backing nodes, the Solidity compiler also required a corresponding upgrade that is Byzantium-aware. This is 0.4.22.

Therefore, to deploy code compiled with 0.4.21 or lower, use a down-rev node client on a pre-fork blockchain. To deploy code on a post-fork geth client connected to a post-fork blockchain (all the public chains, if I'm not mistaken), you must use a compiler 0.4.22 or higher.

Main takeaway: It sounds like you're trying to deploy bytecode that expects Byzantium backing to a chain that doesn't offer it. Upgrade your node, chain, testrpc, ganache-cli, etc., to the latest version and the bytecode should deploy.

Hope it helps.

  • Thanks that helps a lot. Is there any chance to find out which component is making problems. I just upgraded everything (at least I hope).Truffle v4.1.14 (core: 4.1.14) Solidity v0.4.24 (solc-js), ganache-cli Ganache CLI v6.1.8 (ganache-core: 2.2.1) Oct 27, 2018 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.