我可以在服务器上生成交易并将其发送给客户端以付款

发布于 2025-02-05 19:28:17 字数 1003 浏览 1 评论 0原文

我已经建立了一种智能合同方法,该方法通过了一些敏感数据,这些数据需要存储在区块链上并改变合同状态。我,合同的创建者不想成为该交易费用的人。我希望浏览器上的用户批准并为其付费。

但是,我不想在浏览器上生成事务对象,因为我希望将某些将传递给合同的数据从客户端隐藏。如果我正确理解Web3语法,在下面的代码中,我就是这样做的,

web3.eth.sendTransaction({
   from: walletAddressOfTheUserThatWillPayForTheTransaction,
   data: myContract.methods.changeState(..sensitive data...).encodeABI()
})

但是我不希望以上内容发生在浏览器上。在我的脑海中,事件的顺序应该像这样( pseudocode ):

// server
let transactionObject = {
   from: walletAddressOfTheUserThatWillPayForTheTransaction,
   data: myContract.methods.changeState(..sensitive data...).encodeABI()
}

sendToClient(encrypt(transactionObject)) 


// client
let encryptedTransactionObject = await fetchEncryptedTransactionObjectFromServer()

// this should open up Metamask for the user so that they may approve and finalise the transaction on the browser
web3.eth.sendTransaction(encryptedTransactionObject)

这可能吗?还有其他实现这一目标的方法吗?您能为我提供有关要使用的实际语法的一些提示吗?

I have built a smart contract method to which I pass some sensitive data that needs to be stored on the blockchain and alter the state of the contract. I, the creator of the contract don't want to be the one paying for the fees of that transaction. I want the user on the browser to approve and pay for it.

However, I do not want to generate the transaction object on the browser as I want some of the data that will be passed to the contract to be hidden from the client. If I understand the web3 syntax correctly, in the code below, I'm doing just that

web3.eth.sendTransaction({
   from: walletAddressOfTheUserThatWillPayForTheTransaction,
   data: myContract.methods.changeState(..sensitive data...).encodeABI()
})

However I do not want the above to happen on the browser. In my head, the sequence of events should look like this (pseudocode):

// server
let transactionObject = {
   from: walletAddressOfTheUserThatWillPayForTheTransaction,
   data: myContract.methods.changeState(..sensitive data...).encodeABI()
}

sendToClient(encrypt(transactionObject)) 


// client
let encryptedTransactionObject = await fetchEncryptedTransactionObjectFromServer()

// this should open up Metamask for the user so that they may approve and finalise the transaction on the browser
web3.eth.sendTransaction(encryptedTransactionObject)

Is this possible ? Is there some other way of achieving this? Could you provide me with some hints about the actual syntax to be used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一世旳自豪 2025-02-12 19:28:17

但是,我不想在浏览器上生成事务对象,因为我希望将某些将传递给合同的数据从客户端隐藏。

那么,您不应首先使用公共区块链,因为关于公共区块链的所有数据均为公开。任何人都可以阅读。

However, I do not want to generate the transaction object on the browser as I want some of the data that will be passed to the contract to be hidden from the client.

Then you should not be using public blockchains in the first place, as all data on public blockchains, by definition, is public. Anyone can read it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文