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?

satrio galih
  • 39
  • 1
  • 1
  • 5
  • 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 '22 at 00: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.

    – satrio galih Feb 13 '22 at 00: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 '22 at 00:43
  • does it answer your question ? – Prosperity Feb 13 '22 at 00: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? – satrio galih Feb 13 '22 at 00:57
  • if yes, is it safe to put private key in smart contract? cause if the code published, anyone can see the private key, or we don't need to publish the code? – satrio galih Feb 13 '22 at 00:58
  • you aren't getting it yet. – Prosperity Feb 13 '22 at 01:01

1 Answers1

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?

Prosperity
  • 195
  • 7