我想在服务器上部署智能合约并使用移动客户端与其进行交互。我不知道它是如何工作的,但是经过一番研究,我发现了以下内容:
如果我们比较移动客户端中通过Web服务进行的通信,那么智能合约中的所有预期几乎都是相同的,不是由于系统分散性而产生的数据库或部署服务。那正确吗?我们可以使用诸如web3之类的库将移动客户端连接到智能合约,该库实际上可以与Json RPC或websockets一起使用。
但是,如果我不想使用像web3这样的库将每个移动客户端连接到智能合约怎么办?相反,如果我想拥有一个HTTP服务器,然后它将连接到如下所示的智能合约,该怎么办?
有可能吗?如果是,那我该怎么办?
我的第二个问题是关于部署。在集中式服务器方案中,我会将数据库部署在某些服务(例如AWS等)上。我可以估算部署成本。我了解到,我们必须在以太坊主网上部署智能合约,这将花费以太坊的数量。但是后来我发现我的用户将不得不为每次计算付费。如果我想承担所有费用怎么办?我们如何估算这种费用?
请在上述问题上为我提供指导。谢谢。
答案 0 :(得分:1)
Instead, what if I want to have a HTTP server and then it would connect to smart contract like below?
You certainly can do this, some might argue a layer of centralization is added by placing a web server between the DApp and blockchain, but I would disagree. If you want to do this, your DApp would simply call a REST API on your web server which in return would utilize web3.js (node.js), web3j (Java), Nethereum (C#/.NET) or any other flavor of Web3 to interact directly with the blockchain.
What if I want to bear all the costs?
You will only be able to bear the costs of deploying smart contracts which are deployed on your behalf and not on behalf of any potential end-users.
How can we estimate such costs?
You can estimate the gas cost of a contract deployment or contract interaction via web3's estimateGas
method. Understand, this cost can be largely effected by how well structured your Solidity smart contract code is written. Note, this is of course also only an estimate as users could always expend more Ether to have their transaction confirmed quicker or the state of the data within the smart contract could change over time requiring higher gas costs (i.e. iterating a growing array). For more information on gas costs within the Ethereum mainnet, you can take a look at ETH Gas Station.
As a side note, since I do not know your particular use case for blockchain technology, it could be helpful to weigh out whether or not it makes sense to utilize the Ethereum mainnet or to spin up your own private Ethereum blockchain. With the latter you would completely avoid having to spend any Ether to interact with blockchain network, but you would likely have additional overhead.