I have a question on setting prices for the cards in the card game I'm working on.

Right now, I have 2 cards available but there will be more (maybe a couple dozen).

I store each card as a struct with its attributes and when a person "collects" it a function makes a copy of it in a new array, mints it to the person collecting it and sets the tokenURI.

My question is how could I set the prices for the cards, being that some will be more rare/collectible than others? Maybe set a cardPrice as part of the struct for each card, then have the payable function check to make sure the value being sent by msg.sender matches the cardPrice for that card?

If something like that would work, I'd also want to add a function to update the cardPrice if needed.

Would that approach work or have any of you done anything like that where you have a single payable function that would need to be paid different fees depending on a given situation?

Here are the two structs & arrays. Card is the master version and Warrior is the one collected by the person.

struct Card {
string cardName;
uint16 cardImage;
uint256 cardAttributes;
uint16 cardIssued;
uint16 cardMax;
Card[] public cards;

struct Warrior {
string warName;
uint16 warImage;
uint16 warNumber;
uint256 warAttributes;
uint16 warIssued;
uint16 warMax;
Warrior[] public warriors;

Here's the bit that copies a Card into a Warrior:

function dupCard(uint256 id, string memory _tokenURI, address _to) public 
returns (
string memory _warName,
uint16 _warImage,
uint16 _warNumber,
uint256 _warAttributes,
uint16 _warIssued,
uint16 _warMax
) {
Card storage Crd = cards[id];
_warName = string(Crd.cardName);
_warImage = uint16(Crd.cardImage);
_warNumber = uint16(id);
_warAttributes = uint256(Crd.cardAttributes);
_warIssued = uint16(Crd.cardIssued);
_warMax = uint16(Crd.cardMax);

createWarrior(_warName, _warImage, _warNumber, _warAttributes, _warIssued, _warMax, _tokenURI, _to);

function createWarrior(string memory _warName, uint16 _warImage, uint16 _warNumber, uint256 _warAttributes, uint16 _warIssued, uint16 _warMax, string memory _tokenURI, address _to) public {
uint256 id = warriors.length;
warriors.push(Warrior(_warName, _warImage, _warNumber, _warAttributes, _warIssued, _warMax));
_mint(_to, id);
_setTokenURI(id, _tokenURI);
warriorToOwner[id] = _to;

function incrementIssued(uint256 id) internal {


Your Answer

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

Browse other questions tagged or ask your own question.