3

I have a ERC721 contract and I have one problem, I'm trying to set the price in another currency like UNI or SUSHI but the problem is that I don't know how to change it, I don't know a lot about contracts, here is the code.

I was wondering if it is possible to make the following UNI work:

uint256 public constant NFT_PRICE = 1 ether;

I try to do something like this

uint256 public constant NFT_PRICE = 1 UNI;

But this doesn't work

MaartenDev
  • 5,631
  • 5
  • 21
  • 33
Nayra1316
  • 31
  • 4

2 Answers2

2

Ethereum natively knows only about Ether payments.

For a token payment, you need to study ERC-20 standard and its transferFrom() functionality to support ERC-20 token payments in your Solidity smart contracts.

For ERC-777 tokens you can have an incoming payment handler.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
0

Well, maybe this answer is a bit late, if you want to set a price in anything that is not ether you will need to use an erc20, the uniswap token is an erc20, now if you want to have a fixed amount of that token (remember that contracts are not upgradable) you probably do something like this uniToken.transferFrom(msg.sender,to,amount); remember that tokens can also have decimals and could be different from the ether decimals, if you want to use a non fixed amount you will need a chainlink oracle to provide you the price, as an example if you want to set an amount of 10 dollars in Uni you will need an oracle that returns you that value and then you can do the calculations and other things, other thing you need to know, in solidity the expression x ether is just sugar syntax, what it does is return an uint 256 of x * 10^18, because that's how decimals are handled in tokens and ether, so if you want 0.5 ethers you can do this 0.5 ether or this 5 * 10^17 or this 500000000000000000 and all represent the exact same number, that's a way to dont't loose presition with decimals, most tokens and ether use 18 decimals but there are some that doesn't, so is important to check that

jhonny
  • 805
  • 4
  • 10