0

trying to implement like this

uint[2] memory royalty = royaltyInfo(_tokenId, price);

payable(royalty[0]).transfer(royalty[1]);

but getting error

TypeError: Different number of components on the left hand side (1) than on the right hand side (2).
  --> contracts/NFTMarketplace.sol:98:9:
   |
98 |         uint[2] memory royalty = royaltyInfo(_tokenId, price);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


TypeError: Type address is not implicitly convertible to expected type uint256[2] memory.
  --> contracts/NFTMarketplace.sol:98:9:
   |
98 |         uint[2] memory royalty = royaltyInfo(_tokenId, price);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


TypeError: Explicit type conversion not allowed from "uint256" to "address payable".
   --> contracts/NFTMarketplace.sol:105:9:
    |
105 |         payable(royalty[0]).transfer(royalty[1]);

1 Answer 1

0

You're trying to transfer funds to royalty[0] which should be a valid address rather than a uint256, as the third errors says.

From what I can tell, the royaltyInfo function should return the address to which the funds must be sent and the amount. If so, you need to update the return type of the royaltyInfo as following:

function royaltyInfo(
    uint256 _tokenId,
    uint256 price
) public returns (address recipient, uint256 amount) {
    address _recipient;
    uint256 _amount;
    
    // INSERT YOUR LOGIC HERE

    return (_recipient, _amount);
}

and get the address and amount like this:

(address recipient, uint256 amount) = royaltyInfo(tokenId, price);

then you can send the funds using the returned values:

payable(recipient).transfer(amount);

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.