0

I've seen this in Solidity several times, but I can't find it in the documentation nor do I know how to describe it in a search engine. Say you have a function:

 function buyItem(uint256 _upc)
    public
    payable
    // Call modifier to check if upc has passed previous supply chain stage
    forSale(_upc)
    // Call modifer to check if buyer has paid enough
    paidEnough(items[_upc].productPrice)
    // Call modifer to send any excess ether back to buyer
    checkValue(_upc)
{
    // Update the appropriate fields - ownerID, distributorID, itemState
    items[_upc].ownerID = msg.sender;
    items[_upc].distributorID = msg.sender;
    items[_upc].itemState = State.Sold;

    // Transfer money to farmer
    items[_upc].distributorID.transfer(items[_upc].productPrice);
    // emit the appropriate event
    emit Sold(_upc);
}

When you call the function in the test, you pass it an object with a from and value property. How do I know when I need to use these properties and where is this described in the documentation?

// Mark an item as Sold by calling function buyItem()
    await supplyChain.buyItem(upc, {
        from: distributorID,
        value: productPrice,
    });

1 Answer 1

0

They're called payable functions because they have the payable modifier.

In the extra parameters from is the address signing the transaction, and value is the amount of ethers sent to the transaction.

Your Answer

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

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