I'm trying to implement a contract which will store bytes blob, a dynamic bytes array.
For example I have following struct:
Sign {
address signer;
bytes16 signType;
bytes sign;
}
plus an event:
event Signed(
bytes16 signType,
bytes sign
);
and trying to set it:
function addSignature(byte16 signType, bytes sign) {
// ... store data
... = Sign(msg.sender, signType, sign)
// raise event
Sign(signType, sign);
}
The problem that I can't find a way to pass bytes to the function from Javascript.
I'm using Truffle, and tried following Javascript code:
var type = web3.fromAscii('test', 16);
var sign = [0x12, 0x34]; //also tried web3.toBigNumber('0x1234');
contract.addSignature(type, sign, {from: myAccount, gas: 2000000});
it makes a transaction, but I don't see correct value stored into my contact. For example by listening to Signed event I see that there're an empty array. If I try to read data, I got zeros (actually it's more weird, I get signType padded with long array of zeroes).
What is a proper way to use arbitrary bytes array? hot to send to contract, how to read?
PS I'm using Truffle with TestRPC.
var sign = '0x1234';? IIRC it worked for me, but I didn't use Truffle or TestRPC. – eth Apr 03 '16 at 18:25byte16but to isolate your issues, try with say auintsignType first: it's getting padded with zeros sincetestis only 4 bytes, and you're usingbyte16. – eth Apr 03 '16 at 18:34