3

I have deployed a contract with following push function to my local privatechain via remix.

struct TestComplex{
    address testValue;
    address delegate;
    uint testInt;
}
TestComplex[] testArray;
function setTestArrayByPush( address _delegate, address _testAddr, uint _testInt) public {
    testArray.push(TestComplex( {
       testValue:_testAddr,
       delegate: _delegate,
       testInt: _testInt
    } ));
}

If I call it via web3Provider@remix, it works fine, but when I call it via geth console or via JS script contractInstance.setTestArrayByPush(<Add1>, <Add2>,<Int>), it will not push any thing into the array. When I remove one attribute from TestComplex structure and the function changed as following. It works for both geth and remix.

function setTestArrayByPush(address _testAddr, uint _testInt) public {
    testArray.push(TestComplex( {
       testValue:_testAddr,
       testInt: _testInt
       }));
    {
}

So I'm wondering that what is the difference between remix function call and geth console? And how could I pass more then two parameters into stuct array in my Dapp?

Don
  • 3,876
  • 10
  • 47
  • 76
Yudao Yan
  • 95
  • 1
  • 7
  • 1
    Include the transaction object in your JS: `contractInstance.setTestArrayByPush(, ,,{from: , gas: })`. If that doesn't solve it, post the code that shows you creating `contractInstance` along with the `struct` and `testArray` portion of your contract. – Adam Kipnis Jan 15 '18 at 20:10
  • @AdamKipnis Thank you for the information! the submitting works fine after pass the additional json with gas cost, Thank you very much! – Yudao Yan Jan 16 '18 at 07:11
  • @AdamKipnis One question here: how to put {from: , gas:} in python code? – Yudao Yan Feb 24 '18 at 09:21
  • @AdamKipnis I tried web3.py and it works same as web3 did – Yudao Yan Mar 07 '18 at 15:19

1 Answers1

0

This works fine:

pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;


contract Test  {

struct TestComplex{
address testValue;
address delegate;
uint testInt;
}

TestComplex[] public  testArray;


 function setTestArrayByPush( address _testValue, address _delegate, uint _testInt) public {
testArray.push(TestComplex(
   _testValue,
   _delegate,
   _testInt
) );
}

function getTestComplex () public view returns ( TestComplex[] memory)  {
return testArray ;
}