I have the contract
pragma solidity ^0.4.11;
contract UserBasic {
struct Record {
bytes32 _id;
address _addedBy;
uint _dateAdded;
bytes32 _transactionHash;
bytes32 _type;
bytes32 _hash;
bytes32 _signature;
}
// Type to records array
mapping(bytes32 => bytes32[]) typeRecords;
// Record ID to record
mapping(bytes32 => Record) idRecord;
// Search for record
function searchRecord(bytes32 _id) constant returns (bytes32, address, uint, bytes32, bytes32, bytes32, bytes32) {
Record storage temp = idRecord[_id];
return (temp._id, temp._addedBy, temp._dateAdded, temp._transactionHash, temp._type, temp._hash, temp._signature);
}
// Add a record
function addRecord(bytes32 _type, bytes32 _id) {
typeRecords[_type].push(_id);
var _new = Record(_id, tx.origin, now, "", _type, "", "");
idRecord[_id] = _new;
}
// Get all records of a given type
function getRecordsByType(bytes32 _type) constant returns(bytes32[]) {
return typeRecords[_type];
}
}
My addRecord
method isn't working (I figure because of gas costs). I wanted to estimate how much gas that method costs but not sure how. This answer explains a way for a function with one parameter but it seems too complex of a process, I was wondering if there is a simpler way.
I'm calling it from node with
function addRecord(publicAddress, contractAddress, _type, _id) {
const contract = contractInstance("UserBasic", contractAddress);
// Interaction with the contract
contract.addRecord(_type, _id, {from: publicAddress}, (err, res) => {
// Log transaction to explore
if (err) {
console.log(err);
} else {
console.log('tx: ' + res);
helpers.addTransaction(publicAddress, res);
}
});
}
I read the docs but the only part I don't know is how to convert multiple parameters to data
.