I want to build an application and send my users a custom token or nft. I can easily generate a solana address, but none of my users will have solana coins to pay for fees to send it back out or redeem it back with me. How can one tackle this common problem when you need the native parent token to pay for fees?
2 Answers
The user running the application must connect their wallet to open the new account and fund it with some lamports. They will sign the tx to do so. In a wallet like Phantom this is why you will see a small Sol fee to interact with some Dapps for the first time, this is the fee to open the necessary accounts. This is a pretty universal approach because other accounts such as token accounts need to be funded with the rent exemption. It sounds like you want to create an Associated Token Account for your users and mint them custom tokens.
You can also fund the creation of the accounts out of your account, so the caller of the program (maybe you) is opening an account for another user, but you will pay the rent exemption. This approach is not very common.
-
Let me get this straight. So i need to initiate each and every user account with a small fraction of SOL before my users can use their account? What if I have 100K user accounts and I want to generate a SOL address for each and send each one a free NFT. Commented Aug 9, 2022 at 13:01
-
That's right: any account you make on Solana requires rent. Usually you will fund the account with 2 years worth of rent, which actually allows it to be exempt from paying rent. The rent fee for something like a token account is very small (generally around .000001 Sol), and this cost is typically paid by the user when they claim the token/NFT/etc. Commented Aug 9, 2022 at 20:20
The key here is to specify a fee_payer
under your control to also sign users' transactions.
Users would first sign and send you (not the blockchain yet) a transaction that is configured with one of your accounts as fee_payer
. Then you just have your fee_payer
sign and send.
-
so i have to sign a transaction every time a user sends the free NFT that i sent them? Commented Aug 9, 2022 at 13:00
-
Yes, the user would sign for the NFT transfer, and you'd sign for the fee-payer designation, then you'd send the transaction to the cluster. And to be clear, you wouldn't sign manually, of course. You'd use a server. Commented Aug 9, 2022 at 14:23