英文:
Wrapping ETH into WETH via ethers -- WETH coins on my balance won't appear
问题
我正试图通过调用 deposit
函数将 Goerli 上的 ETH 包装成 WETH。尽管已经有几个交易被确认并成功挖矿,但在 goerli.etherscan.io
的下拉菜单 Token Holdings
中我的 WETH 余额不会显示任何内容,也没有 WETH,而其他代币则有。
let wallet = new ethers.Wallet(prKey, provider);
const contract = new ethers.Contract(WETH_CONTRACT_ADDRESS, WETH_ABI, wallet);
const txSigner = contract.connect(wallet);
const balance = await provider.getBalance(wallet.address);
const gasPrice = await provider.getGasPrice();
const balanceMinusGas = balance.sub(gasPrice.mul(ETH_GAS_LIMIT));
let tx = txSigner.deposit({value: balanceMinusGas});
return tx;
}```
发生了什么事情?
此外,在 https://goerli.etherscan.io/address/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 上可以看到我的交易。
**更新1**
另外,我尝试调用
```let amount = ethers.utils.parseEther(<sum of all previous ETH-s transfers>);
contract.transfer(wallet.address, amount);```
然而,没有成功。
**更新2**
我已经切换到 Goerli 上的 `0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6`。然而,调用 `contract.deposit()` 仍然无法将任何 `WETH` 存入我的钱包。
<details>
<summary>英文:</summary>
I'm attempting to wrap ETH on Goerli into WETH by calling `deposit` function using ethers. Even though several TX already have **been confirmed and successfully mined**, nothing will appear on my WETH balance at `goerli.etherscan.io` in the dropdown `Token Holdings`. No is there `WETH` there at all, whereas there're other tokens
async function myWrap(prKey) {
let wallet = new ethers.Wallet(prKey, provider);
const contract = new ethers.Contract(WETH_CONTRACT_ADDRESS, WETH_ABI, wallet);
const txSigner = contract.connect(wallet);
const balance = await provider.getBalance(wallet.address);
const gasPrice = await provider.getGasPrice();
const balanceMinusGas = balance.sub(gasPrice.mul(ETH_GAS_LIMIT));
let tx = txSigner.deposit({value: balanceMinusGas});
return tx;
}
What's the matter?
Moreover, at https://goerli.etherscan.io/address/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 my TX-s are present.
**update1**
Additionally, I then have tried to call
let amount = ethers.utils.parseEther(<sum of all previous ETH-s transfers>);
contract.transfer(wallet.address, amount);
yet, to no avail
**update 2**
I've switched to `0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6` on Goerli. However, calling `contract.deposit()` still won't deposit any `WETH` to my wallet.
</details>
# 答案1
**得分**: 3
[WETH地址][1] 在您的评论中提到的在Goerli测试网上没有任何智能合约代码。它只是这个网络上的一个普通的EOA地址。
因此,当您向Goerli测试网上的这个地址发送交易时,它只是转移了ETH的`value` - 但仅此而已。因为没有智能合约会对交易做出反应,所以没有其他互动发生。
话虽如此,Uniswap的[文档页面][2]提到了Goerli上不同的WETH合约地址,具体为[0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6][3]。
**解决方案**:在Goerli网络上使用已更正的WETH合约地址。
[1]: https://goerli.etherscan.io/address/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
[2]: https://docs.uniswap.org/contracts/v3/reference/deployments
[3]: https://goerli.etherscan.io/address/0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6
<details>
<summary>英文:</summary>
The [WETH address][1] mentioned in your comment doesn't hold any any smart contract code on the Goerli testnet. It's "just" a regular EOA address on this network.
So when you send a transaction to this address on the Goerli testnet, it simply transfers the ETH `value` - but that's it. No other interaction happens because there's no smart contract that would react to the transaction.
Having said that, the Uniswap [2] mentions a different WETH contract address on Goerli, specifically [0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6][3].
**Solution**: Use the corrected WETH contract address on Goerli network.
[1]: https://goerli.etherscan.io/address/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
[2]: https://docs.uniswap.org/contracts/v3/reference/deployments
[3]: https://goerli.etherscan.io/address/0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论