Make NFTMinter resource publicly available to all users

Hi all, I really need your help. I have an admin account on which the contract is deployed. It also stores the NFTMinter Resource in its storage. However, I want to borrow this minting capability for all other users i.e. the AuthAccounts who are signing the transaction, so that everyone is allowed to mint a token and not just admin.

In the contract, I have added the below code inside the init method :<&NFTMinter>(/public/NFTMinter, target: /storage/NFTMinter)

my init method of the contract now looks like :

init() {<-self.createEmptyCollection(), to: /storage/NFTCollection)<&{NFTReceiver}>(/public/NFTReceiver, target: /storage/NFTCollection)<-create NFTMinter(), to: /storage/NFTMinter)<&NFTMinter>(/public/NFTMinter, target: /storage/NFTMinter)

but still when I try to sign the transaction from another user, it throws this error :


panic: could not borrow minter reference.

How can I resolve this issue? I have referred

admin account is 0x02.

@flowjosh , @qvvg , @dh77 any help would be really appreciated. Thanks in advance.

You can always give permission to an account to mint (check capability receiver pattern)

Hi @Kartik

You can not give public access to a Resource directly
Your Ressource needs to implement an Interface then link the Interface to the Resource storage (I wrote this in a few seconds as I am on holidays, you need to adapt it but this are the principes):<&NFTMinterInterface >(/public/NFTMinterInterface , target: /storage/NFTMinter)

pub resource interface NFTMinterInterface { .... your public functions declation

pub resource NFTMinter: NFTMinterInterface { .... implement your functions

Kind regards