Here is my full contract's code. The reason I ask here is the function startNewBallot(). As you can see, it accepts bytes32[] dynamical array

pragma solidity ^0.4.8;
contract ibaVoter {

struct Proposal{
    bytes32 name;
    uint16 voteCount;

struct Ballot{
    bytes32 name;
    address chainperson;
    bool blind;

Ballot[] public ballots;
uint256 public ballotsNum;
mapping (uint256 => Proposal[]) public proposals;

function startNewBallot(bytes32 ballotName, bool blindParam, bytes32[] proposalNames) external returns (bool success){

        name: ballotName, 
        chainperson: msg.sender, 
        blind: blindParam


    for (uint8 i=0;i<proposalNames.length;i++){
        proposals[ballots.length-1].push(Proposal({name:proposalNames[i], voteCount: 0}));

    return true;

What I try to do in Remix:

enter image description here

I just pass such arguments: "0x7465737473746500000000000000000000000000000000000000000000000000", false, ["0x6164616461646100000000000000000000000000000000000000000000000000", "0x6461646164616461640000000000000000000000000000000000000000000000"]

And it works perfectly. After transaction is executed I try to call public ballots(0) or proposals(0,0) and it returns me values I passed before.

The problem is that I can not do same thing from my dapp-web interface. I create contract with correct ABI (checked it several times), pass the same arguments to it's function contracts.startNewBallot(). Transaction becomes mined but gas and used gas are always the same and new data never been recorded. Spent already two days trying to guess what's wrong.


I'm using private testnet with Geth's following command: "geth --dev --rpc --rpccorsdomain="*" --rpcapi "eth,net,web3,personal" --datadir "C:\testnet" --networkid 8"

Javascript code I'm using

window.addEventListener('load', function() {
window.web3 = new Web3(new Web3.providers.HttpProvider(""));
web3.eth.defaultAccount = '0x5908e7068cbf2de89fcb2ea998235fb0e743b846';
var addressc = '0xa736b0794339593f702622de998bff54f8fc9444';
var contract = web3.eth.contract([{"constant":true,"inputs":[],"name":"ballotsNum","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"ballots","outputs":[{"name":"name","type":"bytes32"},{"name":"chainperson","type":"address"},{"name":"blind","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"name":"proposals","outputs":[{"name":"name","type":"bytes32"},{"name":"voteCount","type":"uint16"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"ballotName","type":"bytes32"},{"name":"blindParam","type":"bool"},{"name":"proposalNames","type":"bytes32[]"}],"name":"startNewBallot","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]).at(addressc);


var filter = web3.eth.filter('latest');
filter.watch(function(error, result) {
    var block = web3.eth.getBlock(result, true);
    console.log('block #' + block.number);

var fromAscii = function(str, padding) {
    var hex = '0x';
    for (var i = 0; i < str.length; i++) {
        var code = str.charCodeAt(i);
        var n = code.toString(16);
        hex += n.length < 2 ? '0' + n : n;
    return hex + '0'.repeat(padding*2 - hex.length + 2);

            '<div class=option>' +
            '<input type="text" placeholder="Type option here (max 32)" maxlength="32" class="option-value"></br>' +
        return false;

        var options = [];
        var name = fromAscii($('#new-ballot-name').val(),32);
            val = $(this).val();
            opt = fromAscii(val,32);
        contract.startNewBallot(name, false, options, function(e,d){
            console.log(e+' '+d);
        return false;
  • 1
    Where's your dapp source code?
    – user19510
    Oct 26 '17 at 15:25
  • How much gas do you pass? Are you testing against a testnet or testrpc? Perhaps your gas it is too low, try increasing it.
    – Ismael
    Oct 26 '17 at 16:18
  • Maybe you are running out of gas, check how much gas the function is consuming by call the web3 function estimateGas. And adjust the gas sent to the Dapp. Oct 26 '17 at 20:08
  • Updated with dapp code Oct 27 '17 at 6:26
  • Eduardo's comment was a right answer. Formalize it as an answer and I'll accept, thanks for you help. I needed to send it as web3.eth.sendTransaction() since contract object doesn't allow us to set up the gas amount. Oct 27 '17 at 11:24

I can successfully return those values out of your contract using a basic test. Your solidity works so look in your test code or share it here so we can try and help.

  • updated question with dapp code Oct 27 '17 at 6:27
  • Try using a method call for reading, i.e. contract.ballots.call(0,function(e,d){console.log(d);}); contract.proposals.call(0,0,function(e,d){console.log(d);}); web3js.readthedocs.io/en/1.0/… Oct 27 '17 at 6:54
  • Without "call" it works fine if there is a data, so I guess problem is not there. The problem is my transaction with calling function startNewBallot() doesn't pass through from js, get mined but fails on execution. Oct 27 '17 at 7:01
  • Ok, I am actually testing using truffle and not the web3.eth.contract interface but I'd bet the problem is in the dApp code not Solidity. Have you tried passing in the hardcoded values directly in contract.startNewBallot(name, false, options) call? Oct 27 '17 at 7:10
  • Yep. I've tried it with hardcoded values and what transaction looks like after it's mined: blockNumber: 3317 contractAddress: null cumulativeGasUsed: 90000 gasUsed: 90000 I've checked input filed of transaction to be sure same method is called and it's the same with remix's transaction. Oct 27 '17 at 8:11

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.