[英]Should Solidity handle the Paging in a Dapp?
I'm using a smart contract to store a dynamic array that can grow in length.我正在使用智能合约来存储可以增加长度的动态数组。 I want to render this list in the browser and would normally do that using web3 and sending a call() to get the list from the blockchain.
我想在浏览器中呈现这个列表,通常会使用 web3 并发送 call() 来从区块链中获取列表。 But, since the array could potentially contain thousands of elements I wouldn't want to do this due to high gas price.
但是,由于数组可能包含数千个元素,因此由于 gas 价格高,我不想这样做。
Is it appropriate to implement paging of data within the Solidity contract?在 Solidity 合约中实现数据分页是否合适? If not, what other options are there?
如果没有,还有哪些其他选择?
since the array could potentially contain thousands of elements I wouldn't want to do this due to high gas price
由于数组可能包含数千个元素,因此由于gas价格高,我不想这样做
The .call() web3 method invokes the eth_call RPC method, which is gas free. .call () web3 方法调用eth_call RPC 方法,该方法是无气体的。
It can't change the contract state (update storage, emit events, ...) but it shouldn't matter in your use case, if you're only reading the data.它无法更改合约状态(更新存储、发出事件,...)但在您的用例中应该无关紧要,如果您只是读取数据。 It's recommended to use the
call()
method only in combination with Solidity functions that are marked with the view
or pure
state mutability modifiers.建议仅将
call()
方法与标有view
或pure
状态可变性修饰符的 Solidity 函数结合使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.