简体   繁体   English

我可以使用智能合约在没有确认的情况下铸造我的 NFT 吗?

[英]Can I use smart contract to mint my NFT without confirmation?

I would like to let my users reserve my NFT with cash (through things like PayPal or Stripe).我想让我的用户用现金(通过 PayPal 或 Stripe 之类的东西)保留我的 NFT。 When the reservation happens, the NFT should be minted by my wallet and they can contact me once they have set up their own wallet, so I can transfer the NFT to their wallet.当预订发生时,NFT 应该由我的钱包铸造,一旦他们建立了自己的钱包,他们可以联系我,这样我就可以将 NFT 转移到他们的钱包中。

But it seems each minting (which would create a transaction) will need the confirmation of the owner of the wallet.但似乎每次铸币(会创建交易)都需要钱包所有者的确认。 Is there a way to skip it, or do I have to do it manually?有没有办法跳过它,还是我必须手动完成?

If by "automatically" you mean by doing it without using a wallet like Metamask, then yes, you can automate the transaction, but you'll need to specify your private key and an RPC URL to a node when calling the contract's mint method.如果“自动”是指不使用 Metamask 之类的钱包,那么是的,您可以自动执行交易,但在调用合约的 mint 方法时,您需要指定您的私钥和节点的 RPC URL。

For that, you'll need to securely manage that transaction in a different place besides your frontend, since if you type your private key on your frontend app ( website ), anyone can access it and access your wallet.为此,您需要在前端以外的其他地方安全地管理该交易,因为如果您在前端应用程序(网站)上输入您的私钥,任何人都可以访问它并访问您的钱包。

You'll need an external service ( node app for example running an ethers script ) on a server where you can securely manage that data, and execute the transaction, and have the frontend call this service.您需要在服务器上提供外部服务(例如运行 ethers 脚本的节点应用程序),您可以在其中安全地管理该数据,执行事务,并让前端调用此服务。

This script can, for example, listen for HTTP requests from the frontend ( using expressjs ), once received the request, get a provider from the RPC URL, a signer using the private key ( using the method new ethers.Wallet( privateKey [ , provider ] ) and then, get a contract instance like usual. After that, just call the method, await for the transaction's promise, and then return a response to the frontend.例如,此脚本可以监听来自前端的 HTTP 请求(使用 expressjs),一旦收到请求,从 RPC URL 获取提供者,使用私钥的签名者(使用方法new ethers.Wallet( privateKey [ , provider ] )然后,像往常一样获取一个合约实例。之后,只需调用该方法,等待交易的承诺,然后向前端返回响应。

And from the frontend, you can simply send the request using fetch once the payment through stripe has been confirmed for example.例如,一旦通过条带付款得到确认,您就可以从前端简单地使用fetch发送请求。

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

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