2

I have a contract, for simplicity sake, which has an array; I want to enter values into this array with the content of a text file in my local machine.
How can I access this data?
I was thinking that going through the CLI with loadscript(...) but I'm having issues accessing anything... The console is not very cooperative :)

Thanks.

  • from which context (browser, cli/node, geth) you want to do this? – radmen Mar 14 '17 at 12:47
  • I would like to do it from the geth console if possible. But I'm also interested in other contexts, even as a brief outline of the 'working principle'. The more methods to get data the better. :) – mik Mar 14 '17 at 13:10
  • 1
    For a second I've thought that geth runs basically nodejs instance. Looks like no. In this case I'd write a Nodejs script which connects to geth/parity instance using web3. You can read files in Nodejs by using fs module. – radmen Mar 14 '17 at 13:15
2

You make a function in the contract that can accept row-wise inputs. It can be secured with onlyOwner() or similar, as appropriate. The function is indifferent to the original source of the values.

Something like

uint[] public  myArray';

function appendArray(uint value) public returns(bool success) {
  myArray.push(value);
  return true;
}

Then you write a migration in JavaScript, NodeJS, Truffle, or ... preference.

The migration iterates over the rows in the input file and bangs away on the input function in the contract. Unless something really rare is planned, I would expect to send one transaction per array row.

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.