2

MY CONTRACT :

pragma solidity ^0.4.6;

contract TestContract{
    string coaf;
    string choice;
    string info;
    string isin;
    string recordDate;
    string exDate;

    function TestContract(string _coaf, string _choice, string _info,string _isin,string _recordDate,string _exdate){
        coaf = _coaf;
        choice = _choice;
        info = _info;
        isin =_isin;
        recordDate=_recordDate;
        exDate=_exdate;
    }


    function getFields() constant returns(string, string, string,string,string,string){
        return(coaf,choice,info,isin,recordDate,exDate);

    }
   function SetFields(string _coaf,string _choice,string _info,string _isin,string _recordDate,string _exdate){
     coaf=_coaf;
     choice=_choice;
     info=_info;
     isin=_isin;
     recordDate=_recordDate;
     exDate=_exdate;
   }
    function setChoice(string _choice) {
        info = _choice;
    }

}

MY CALL :

 TestContract.deployed().then(function(instance) {
    return instance.SetFields(coaf,choice,info,isin,exDate,recordDate,{gas:3000000},{from:web3.eth.accounts[1]});
  }).then(function(result) {
    save_th(result.tx,type);
    console.log("Transaction:", result.tx);
    console.log("Finished!");
    //done();
  }).catch(function(e) {
    console.log(e);
  //done();
  });

MY DEPLOYMENT :

    var TestContract=artifacts.require('TestContract');
    module.exports = function(deployer) {
    // Pass 42 to the contract as the first constructor parameter
    deployer.deploy(TestContract,"Default","Default","Default","Default","Default","Default");
};

NEED URGENT HELP !!!!

  • 1
    Please format your code to make it more readable. Where does your contract fail? Is it at deploy,or is it at calling a method? Where are you testing? Is it at a private testnet, or testnet or mainnet? Processing string is expensive you can try increasing the gas passed to deployment and transactions. – Ismael Jul 3 '17 at 7:29
  • Its when i call the method set fields. I increased the gas limit nothing works – Rohan Khanna Jul 3 '17 at 10:12
3

Too many strings? Strings a very expensive in the EVM. Try bytes or try to avoid strings. I had similar problems with my dApp and Smart Contract. I removed all strings (thus redesigned) and now all works just fine.

  • one more thing: also if you have typ problems, e.g. the input type (when calling the function) is not string, this error can occur. I would also check this. Also had that quite often, even though I though types were correct, they weren't. If you are used to programming in Eclipse or so, you might get a warning from the IDE. Here, you don't (if you are just using web web3 console for example) – Stefan Richter Jul 3 '17 at 12:04
  • If you're using testrpc, do a $ truffle migrate --reset. It's normal for the blockchain to loose the deployed contracts when you restart truffle. – Rob Hitchens - B9lab Jul 3 '17 at 19:53
  • this may be a noob question but will bytes be able to handle the string inputs ? – Rohan Khanna Jul 4 '17 at 7:38
  • hmmm, your contract definitely works fine. I tried it in Remix. – Stefan Richter Jul 4 '17 at 7:52
  • Just go to remix.ethereum.org copy and paste your code, select environment "JavaScript VM", create a instance of your contract, then use the funciton "SetFields"...you will see it works. Thus, your deployment and/or call function might be the reason. Remix gives you nice deploy code (see field "Web3 deploy"). In Geth (I assume you are using it), simply call the function with contractObject.SetFields(...) Thus, the string stuff might be a problem, but not the major reason here. The function "SetFields" gas costs are: Transaction cost: 91182 gas. Execution cost: 63958 gas. – Stefan Richter Jul 4 '17 at 8:09

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.