Writing some contracts on the Ethereum mainnet which will probably use WETH to handle Ξ to avoid writing the logic twice. An important integration would be to let users interact with DAI, but xDai has been on our radar lately.
If we deploy the contracts on xDai, do we have to rewrite them to use the idiomatic functions to manage value? That is,
address.balance. Asking because
WDAI sounds like overkill haha.
xDai chain is fully EVM 1.0 compatible. The smart-contracts written for Mainnet will work the same way in xDai chain. You shouldn’t rewrite them.
Hi @viktorbaranov, thank for getting back. Sorry for not being clear enough, I was specifically referring to the issue that the contracts handle ERC20 tokens and, if we were to move them over on xDai and use DAI (a.k.a. the main currency of the blockchain), we’d have to rewrite them to use the canonical functions. But I’m not totally sure that’s a fact, hence why I asked what are the best practices.
I was specifically referring to the issue that the contracts handle ERC20 tokens
I see. There is no problem here. You can still handle ERC-20 tokens in xDAI chain.
if we were to move them over on xDai and use DAI (a.k.a. the main currency of the blockchain)
Maybe, there is a misunderstanding here, that confuses you:
DAI is an ERC-20 token in the Mainnet. 1 DAI = 1 USD
The native currency of xDai chain is xDai coin, that also 1 xDAI = 1 USD (but it is not an ERC-20 token).
address(this).balance will return a balance of a smart-contract in xDai wei (xDai has the same amount of wei, that Ether has).
Thus, from Solidity part, everything works the same way. Just balances are not in Ether wei, but in xDai wei.
Exactly, Solidity works the same way and that’s a problem in our case - we’d have to rewrite the code to use the native functions, a.k.a.
address(this).balance instead of querying the DAI ERC20 contract. Thank you for your help.
Could you please describe your use case? I’m not sure you would need to do any code rewrite. At a high level, what is your goal?
Here’s a snippet from the source code:
IERC20 tokenContract = IERC20(_tokenAddress);
uint256 allowance = tokenContract.allowance(msg.sender, address(this));
allowance >= deposit,
"contract not allowed to transfer enough tokens"
Normally, this would use the canonical DAI contract. If we move to xDai, this code would need to be revamped to use properties and methods like
msg.sender.transfer because DAI is the native currency of xDai.
And this is exactly the reason why people created WETH on the mainnet: to avoid writing logic twice.
To summarise: there’s no WETH equivalent on xDai, is there?