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){
ballots.push(Ballot({
name: ballotName,
chainperson: msg.sender,
blind: blindParam
}));
ballotsNum++;
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:
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.
UPDATE
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("http://127.0.0.1:8545"));
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);
contract.ballots(0,function(e,d){console.log(d);});
contract.proposals(0,0,function(e,d){console.log(d);});
var filter = web3.eth.filter('latest');
filter.watch(function(error, result) {
var block = web3.eth.getBlock(result, true);
console.log('block #' + block.number);
console.dir(block.transactions);
});
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);
};
(function(){
$('#add-option').click(function(){
$('.options-wrapper').append(
'<div class=option>' +
'<input type="text" placeholder="Type option here (max 32)" maxlength="32" class="option-value"></br>' +
'</div>'
);
return false;
});
$('#create').click(function(){
var options = [];
var name = fromAscii($('#new-ballot-name').val(),32);
$(document).find('.option-value').each(function(){
val = $(this).val();
opt = fromAscii(val,32);
options.push(opt);
});
contract.startNewBallot(name, false, options, function(e,d){
console.log(e+' '+d);
});
console.log(options);
console.log(name);
return false;
});
}())
});
estimateGas
. And adjust the gas sent to the Dapp.