2

I guess this error is related to following closed issue, which still exists. The issue closed recommending us to use remix-alpha, but remix-alpha still has the same error or I might be doing something wrong.

=> Is there anyone else facing with similar problem?

Deployed file names:

Lib.sol         # Library contract //uses around 1,600,000 GAS to be deployed.
myContract.sol  # Main contract    //uses around 3,400,000 GAS to be deployed.

I have tested my contract and it works perfectly fine on populus and remix's JavaScript VM mode. So there is no issue on the contract's code and its implementation.

But whenever I deployed my contract on the remix-alpha; and tested my code on the deployed code as on Web3 Provide mode, if there is a call to Library function, the function call crashes (thrown) at that point.

I really don't know what causes this problem. This error is pretty annoying costing me hours and ether for each deployment, and facing contract does not work as it should be.

As simplified, I have an emptied Library function call:

Lib.sol:

/* Simple Library function */
function constructCluster() public {

}

When there is a call to that function; the function call is reverted().

myContract.sol: cluster.constructCluster(); //Contract is reverted()

[Q] Is there anyway to fix this issue? I am out ot options. The only solution comes to my mind to merge main contact and Library contract but when I merge them I face with following error: SolcError: InternalCompilerError: Static memory load of more than 32 bytes requested.

=> Instead of using remix browser, if I deploy my contract from geth-console would it help to fix the problem?


Please note that: I have tried shorten the contract's name and deploy at http://remix.ethereum.org/. But the exact same contract gives same linkage problem on JavaScript VM mode at remix.ethereum.org that actually works at https://ethereum.github.io/browser-solidity 's JavaScript VM mode.

  • Didn't you mention a problem with long filenames? The link you provide says name "lib.sol" works and you use the same name. Did you accidentally write the new working filename in this question? – Lauri Peltonen Apr 16 '18 at 7:25
  • I assume problem might be related with something else. I tried short files names, and it somehow used works at remix.org. But now, the exactly same contract works on remix-alpha's JavaScript VM mode but does not work (failing on Library function call) on remix's JavaScript VM mode. Hence since it now does not work on remix's JavaScript VM mode, its deployed version on Web3 Provide mode also does not work even I use shorter files names. @Lauri Peltonen – alper Apr 16 '18 at 7:41
0

Please note that, this is an alternative solution to deploy your contract using geth-console and solc compiler. I was not able to fix the bug or find its reason on the remix browser.

In my opinion using geth-console and solc compiler to deploy contract our best option. I tried following solution and everything work all fine, I did not face with and Library linkage issue. Hence, remix may have some unsolved errors/issues related to Library linkage so I do not recommend it to use it if you have any library contract.

Following guide is followed (How can I deploy a contract with reference to a library contract without using a graphical user interface like Browser Solidity?). Some updates has been made for the geth version (Geth/v1.8.0-unstable).

$ solc --version
solc, the solidity compiler commandline interface
Version: 0.4.17+commit.bdeb9e52.Darwin.appleclang

myContract.sol:

library Lib {
    struct clusterData {
        bool isRunning; 
    }
  function constructCluster(clusterData storage self){
      self.isRunning         = true;
  }
}

contract Array {
  using Lib for Lib.clusterData;
  address[] clusterAddresses;
  mapping(address => Lib.clusterData) clusterContract;

  function registerCluster(){
     clusterContract[msg.sender].constructCluster();
     clusterAddresses.push(msg.sender);
  }

 function getClusterAddresses() public view
    returns (address[])
   {
    return clusterAddresses;
   }
}

$ echo "var testOutput=`solc --optimize --combined-json abi,bin,interface myContract.sol`" > myContract.js

Open geth-console.

loadScript("myContract.js")

var myLib = web3.eth.contract(JSON.parse(testOutput.contracts["myContract.sol:Lib"].abi))

var linkedListLib = myLib.new({ from: eth.accounts[0], data: "0x" + testOutput.contracts["myContract.sol:Lib"].bin, gas: 4700000},
  function (e, contract) {
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Lib mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
  }
);
Lib mined! address: 0xa766ab8683e7899f52c28484dd94e50cf4ad7747 transactionHash: 0xc7fb4550eb8c546cc9134a2771bb21d58a67ead4a6c62f51400323c777e7c097

First wait Lib.sol to be deployed. Then replace the __myContract.sol:Lib__________________* text with the above address removing 0x at the beginning.

var arrayCode = testOutput.contracts["myContract.sol:myContract"].bin.replace(/__myContract.sol:Lib__________________+/g, "a766ab8683e7899f52c28484dd94e50cf4ad7747")

var myArray = web3.eth.contract(JSON.parse(testOutput.contracts["myContract.sol:Array"].abi));

var myContract = myArray.new({ from: eth.accounts[0], data: "0x" + arrayCode, gas: 4700000},
  function (e, contract) {
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('myContract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
  }
);
myContract mined! address: 0xaa88aff84b259219c789e72a36aeaf0c57f98089 transactionHash: 0x9b52d196c47e5bf1add01ef9c35cff35f48baabf36313c787e27cc1caaff063e

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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