我的 dApp 必须连接到 MetaMask。文档中有两种粗鲁的解决方案:让用户每次手动单击连接 btn 或在页面加载后弹出连接确认。我想实现唯一方便的解决方案:第一次用户通过单击连接 btn 并与 MetaMask 弹出窗口交互来手动连接,然后我的 dApp 检测到连接仍然建立并使用此连接。我找不到解决方案,但我在其他 dApp 中看到了这个(例如捕获以太)我使用:
import detectEthereumProvider from '@metamask/detect-provider';
const provider = await detectEthereumProvider();
if (provider) {
connect(provider)
} else {
// kind of "Install the MetaMask please!"
}
function connect(provider) {
// How to check if the connection is here
if (//connection established) {
// Show the user connected account address
} else {
// Connect
provider.request({ method: "eth_requestAccounts" })
.then // some logic
}
}
Run Code Online (Sandbox Code Playgroud) 我在文档中找不到有关此表达式的任何信息。关于Ehternaut重入任务有以下代码。
function withdraw(uint _amount) public {
if(balances[msg.sender] >= _amount) {
(bool result,) = msg.sender.call{value:_amount}("");
if(result) {
_amount;
}
balances[msg.sender] -= _amount;
}
}
Run Code Online (Sandbox Code Playgroud)
这是什么_amount;意思?