Hello,
I am new to smart contracts and I am learning to develop DApps using truffle and web3 client from my web app.
.
I have already deployed a contract. And I want to extend it with some view functions that the web app will be using.
I was thinking about a solution, but I am not sure if which would be good practice in a real-world project:
I am thinking about deploying another contract that has view/pure functions that query the data from the first one.
But would not deploying such contracts be expensive as it cost ethers in real-world scenarios?
Or should I just use web3 and manipulate the data on the client-side?
Does these approaches sounds reasonable, or do you have a better ones?
If your existing contract has public state variables, then you could create a wrapper contract to combine/manipulate that data and expose as view/pure functions.
The cost would be the expense of deploying the wrapper contract but this could make your interaction much easier. Gas prices are more reasonable so this could be worth it: https://www.ethgasstation.info/
Note, even read functions have a gas limit, so there will be some restrictions on what you can do.
Another approach, (less decentralized) would be to look at a service like The Graph to read data from your smart contracts.