简体   繁体   English

Solidity 应该处理 Dapp 中的分页吗?

[英]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()方法与标有viewpure 状态可变性修饰符的 Solidity 函数结合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该使用 Pallet_membership 来处理 dapp 用户成员资格吗? (智能合约和区块链运行时的区别) - Should I use the pallet_membership to handle dapp user membership? (Differences between smart contracts and blockchain runtime) 我该怎么办 DApp? - What should I do about DApp? TypeError:在 Solidity 合约中(“应该标记为抽象”) - TypeError: in Solidity Contract ("should be marked as abstract") 我应该怎么做才能解决这个错误? - what should i do to solve this error in solidity? 在Ride4dApps中,充提dApp(Waves IDE中的例子)是如何处理延迟问题的? - In Ride4dApps, how does the deposit and withdraw dApp(the example in Waves IDE) handle the delay issue? 我应该使用以太坊区块链还是为我的 Dapp 创建自己的网络更好? - Should i use the Ethereum Blockchain or is it better to create my own network for my Dapp? 如何在 Ethereum 平台上的 Solidity 中处理 REST API 响应? - How to handle REST API response in Solidity on Ethereum platform? 我应该如何向具有部分 arguments 的结构添加值 - how should I add values to structures with partial arguments in solidity 在Solidity中使用索引时是否需要特定条件? - Should I require a specific condition when working with indexes in Solidity? (dApp) 我的 dapp 不与 MetaMask 交互 - (dApp) My dapp doesn't interact with the MetaMask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM