简体   繁体   English

是否可以从特定帐户在我的前端运行我的 Solidity 智能合约 function

[英]Is it possible to run my Solidity Smart Contract function on my frontend from a specific account

I'm currently working on creating a web3 browser game and I ran into an issue.我目前正在创建一个 web3 浏览器游戏,但遇到了一个问题。 I have a method in my SmartContract for giving players tokens and its onlyOwner .我的 SmartContract 中有一个方法可以给玩家代币及其onlyOwner I want to be able to let my Frontend run it but not users .我希望能够让我的Frontend运行它而不是 users Since Users could easily just give themselves free coins if they did that.因为如果他们这样做,用户可以很容易地给自己免费的硬币。 Im Using Web3Js and i'm not the most familiar with it yet.我正在使用Web3Js ,但我还不是最熟悉它。 Is there a way that i can run my function from MY address in my frontend, instead of it running from the connected users?有没有一种方法可以让我从前端的我的地址运行我的 function,而不是从连接的用户运行? All Feedback is welcome, thanks for your time.欢迎所有反馈,感谢您的时间。

Your user controls the frontend, so if you allow it to call a function you are also allowing the user to do so.您的用户控制前端,因此如果您允许它调用 function,您也允许用户这样做。

there a way that i can run my function from MY address in my frontend, instead of it running from the connected users?有没有一种方法可以让我从前端的我的地址运行我的 function,而不是从连接的用户运行?

You check in the smart contract Solidity code that the transaction comes from your address using msg.sender .您使用msg.sender在智能合约 Solidity 代码中检查交易来自您的地址。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM