Consider the following function from a solidity Contract:
function createProduct(uint _price, string memory _desc) public payable{
emit UserLedgerUpdated(_desc, -1*int(msg.value));
}
I want my Dapp to show a simple ledger like the following:
Created Shoes priced at 100 Wei for a Total Cost of 2345 Wei
I have two choices here:
Catch the
UserLedgerUpdated
Event in the DappUse the etherscan API to obtain the txn details
My questions are:
a) If I go for choice 2 (ie, reading txn details), then I can avoid emitting events. Since Events get logged and occupy space, they'd cost gas, and hence will be more expensive than reading txn details for free. Is my understanding correct?
b) While reading the ethscan API, I get the input to the function as hex. I can use web3.toAscii
to convert it to string, but notice that the first argument to the function is actually a number. Hence, when I convert
Input Data in Sample Transaction, I get {@Shoes
instead of 123Shoes
. Is there a way to properly cast the hex data we are getting from ethrscan API?