0

I am working on making a game where users can collect items. I have chosen to store the ERC721 tokens that represent the items in this way:

Item struct: Image of item struct

User struct and map that maps account-addresses to user-structs: User Struct and map

I made some functions to test this out:

functions

As seen, getItem does in fact not get an item, but rather how many items a user has. This is done for testing, and will be changed back when it works.

I then created some tests to try this out: Test

This outputs as follows:

enter image description here

As you see, the createItem adds an item to the array, but when GetItem is called, it is no longer there. When I called createItem from within getItem, it worked as expected. But for some reason this is not working. Can anyone help?

  • Please share your actual code and output, not screenshots. Screenshots are not searchable (so not useful to future developers looking for help) and are inaccessible to people with visual impairments. – user19510 Mar 13 at 16:22
  • You're using call to invoke createItem. A call does not send a transaction and thus cannot change blockchain state. You need to send a transaction (probably via send instead, depending on what library you're using). – user19510 Mar 13 at 16:27
  • @smarx Oh okay yeah that makes sense. I'll give that a try. And I will upload actual code next time! My bad – user51347 Mar 13 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.