0

Struggling with how to adjust the following function in my app.js file send ether. I've made the target function in my solidity code payable and it tested out successfully in Remix. But, I'm struggling with how to set up the function in my dapp.

Here's the function in app.js:

function dupCard(id, tokenURI, to) {
  App.contracts.WarriorFactory.deployed().then(function(instance){
   return instance.dupCard(id, tokenURI, to);
 });
}

I got a variable userAccount that is set to the user's address so I assume that's my "from" and I'll need to set a "value" for the amount I want to send, but I just can't seem to formulate how to structure the send part of this thing.

For reference, here's the solidity side of it:

function dupCard(uint256 id, string memory _tokenURI, address _to) public 
payable returns (
string memory _warName,
uint16 _warImage,
uint256 _warAttributes,
uint16 _warIssued,
uint16 _warMax,
uint256 _cardPrice
) {
Card storage Crd = cards[id];
_warName = string(Crd.cardName);
_warImage = uint16(Crd.cardImage);
_warAttributes = uint256(Crd.cardAttributes);
_warIssued = uint16(Crd.cardIssued);
_warMax = uint16(Crd.cardMax);
_cardPrice = uint256(Crd.cardPrice);
require(msg.value == basePrice*_cardPrice);
createWarrior(_warName, _warImage, _warAttributes, _warIssued, _warMax, _tokenURI, _to);
incrementIssued(id);
}

This all worked in my dapp prior to any attempt to make the function payable.

Thanks in advance. Kevin

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.