1

Let's say i want to make gaming NFT with variable Level.

i have game which using that NFT, when we play the game the NFT will level up.

i want the NFT only can be leveling up from the game.

as i know if we create public function that can changing the level variable, it can be accessed with the owner of the NFT (people who bought the NFT).

i want the function only can be accessed by the application, so account who have the NFT can't edit the level themself on explorer.

how to create function with access like that, or did my logic is wrong?

7
  • You can create such a function and attached a modifier to it, so the edit function can only be called by the address that you set the modifier to.
    – Prosperity
    Feb 13, 2022 at 0:25
  • @Prosperity can only be called by the address that you set the modifier to <- is this address the game contract address? what if the app and leveling logic in offchain server, so it doesn't have blockchain address. cause i want the user play the game without interacting with blockchain but then the user can do a sync to sync level NFT on the blockchain. Feb 13, 2022 at 0:34
  • then you can set an address to a modifier then use the address offcahin to call the function, this means you have to store the private key in offchain then set an instance offchain that can trigger the function for the address to perform the transaction (to call the function anytime you want to leve up).
    – Prosperity
    Feb 13, 2022 at 0:43
  • does it answer your question ?
    – Prosperity
    Feb 13, 2022 at 0:55
  • to clarify, so i create another smart contract (let's call game contract) that have function that can edit level the NFT contract, put private key in game contract, and trigger the function in game contract within the application with send the private key also. and function in game contract will validate the private key. is it like that? Feb 13, 2022 at 0:57

1 Answer 1

0

in other to perform such operation there is need to use web3JS or etherJS

your smart contract function will look like:

function setEdit( /* pass in params to edit */) public {
   require(msg.sender == owner);
   /* perform operation  */
}

then you can store the private key of the owner somewhere and use https://web3js.readthedocs.io/en/v1.2.0/web3-eth.html#sendsignedtransaction to sign and send transactions anytime you want to level up. some other help here on how to use a private key to send tx: How to make transactions using private key in web3?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.