2

When I develop in solidity combined with web3.js, I face some problem recently. I create a contract code below

//setContractDetail(index,bool isConsentItem,uint8[] detailItems)
function setContractDetail(uint8 index,bool isConsentItem,uint8[] detailItems) public checkOwner{
    consentForm.items[index].isConsent= isConsentItem;
    consentForm.items[index].itemDetail = detailItems;
    /* emit SetContractDetailEvent(msg.sender,index,isConsentItem,detailItems,now); */
}
function setContractDetail2(uint8 index,bool isConsentItem) public checkOwner{
    consentForm.items[index].isConsent = isConsentItem;
}
function setContractDetail3(uint8[] index,bool isConsentItem,uint8[] detailItems) public checkOwner{
    for(uint i=0;i<index.length;i++){
        uint pointer = index[i];
        consentForm.items[pointer].isConsent= isConsentItem;
        consentForm.items[pointer].itemDetail = detailItems;
    }
    /* emit SetContractDetailEvent(msg.sender,index,isConsentItem,detailItems,now); */
}
function setContractDetail4(bool isTest,uint8[] index,bool isConsentItem,uint8[] detailItems) public checkOwner{
    for(uint i=0;i<index.length;i++){
        uint pointer = index[i];
        consentForm.items[pointer].isConsent= isConsentItem;
        consentForm.items[pointer].itemDetail = detailItems;
    }
    /* emit SetContractDetailEvent(msg.sender,index,isConsentItem,detailItems,now); */
}

When I pass the first parameter as an array (setContractDetail3), I always get an error-message - ERROR Error: Error: gas required exceeds allowance or always failing transaction. However, when I set non-array value as first parameter, the function call will be well performed. Does anyone know what is the reason for this issue?

p.s I could successfully compile on the remix, but after I set the contract in geth console as well as connecting with web3.js, it ultimately get fail.

  • Did you set the Gas and GasPrice when calling the smart contract method? – Ha ĐANG Sep 27 '18 at 4:25
  • I use "Mycontract.methods.mymethod(parms).estimateGas({from:account}).then()" to set up my gas value. On the other hand, I set my gasPrice as 0 (I use geth to set up -gasPrice 0 when activating the console) – Hermes Keng Sep 27 '18 at 4:35
  • I still dont know what is the reason of the error; but your estimate gas call like this estimateGas({from:account}) is not sufficient because it lacked much of information to estimate gas. You should provide enough information as below – Ha ĐANG Sep 27 '18 at 4:44
  • ``` // CallMsg contains parameters for contract calls. type CallMsg struct { From common.Address // the sender of the 'transaction' To *common.Address // the destination contract (nil for contract creation) Gas uint64 // if 0, the call executes with near-infinite gas GasPrice *big.Int // wei <-> gas exchange ratio Value *big.Int // amount of wei sent along with the call Data []byte // input data, usually an ABI-encoded contract method invocation } ``` – Ha ĐANG Sep 27 '18 at 4:44
0

It is possible to use dynamic arrays as a function argument using ABIEncoderV2 to a solidity function.

Refer the following Github issue and blog for more details -

https://github.com/ethereum/solidity/issues/2708

https://blog.ricmoo.com/solidity-abiv2-a-foray-into-the-experimental-a6afd3d47185

However, using multiple dynamic arrays as an argument might be another issue because in Java a variable length argument must be the last argument of a function and using multiple variable length arguments in the same function is not allowed.

Hope it helps.

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.