Reputation: 1888
I would like to let my users reserve my NFT with cash (through things like PayPal or Stripe). 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.
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?
Upvotes: 0
Views: 382
Reputation: 1326
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.
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.
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.
And from the frontend, you can simply send the request using fetch
once the payment through stripe has been confirmed for example.
Upvotes: 1