I'm trying to create a function that inserts an item and returns the resulting ID through web3 to my frontend. It looks like this:
function newTranslation(string str, uint lang1, uint lang2) payable returns (uint translationID) {
if (msg.value > 0) {
translationID = translations.length;
Translation memory t;
t.originAddress = msg.sender;
t.originStr = str;
t.originLanguage = lang1;
t.destLanguage = lang2;
t.bounty = msg.value; // use the amount in txn
t.time = now;
t.completed = false;
translations.push(t);
numTranslations++;
}
}
Problem is, when I try to call instance.newTranslation()
through web3, I get the transaction object rather than the actual uint id
. However, if I do instance.newTranslation.call()
, I get the uint id
, but the function doesn't actually change the state of the contract.
I also found another SO post about this issue and it recommended using events to do this. However, I found this to be a little too hacky and wondered if there was a preferred method of accomplishing the same thing? Or if there isn't, am I architecting my code in a non-standard way?
Much thanks for any help.