Skip to main content

Wallet

https://docs.metamask.io/wallet/

https://docs.metamask.io/wallet/reference/provider-api/#properties

0x01 quick start

钱包 ->-> 账户

事件监听: 账户改变事件监听&销毁、 chainChanged 事件监听&销毁

合约 (部署 )交易

window.ethereum;

https://hardhat.org/hardhat-network/docs/reference#chainid

https://docs.metamask.io/guide/ethereum-provider.html#properties

window.ethereum.networkVersion;
const [selectedAddress] = await window.ethereum.request({ method: 'eth_requestAccounts' });
this._provider = new ethers.BrowserProvider(window.ethereum);
this._simpleToken = new ethers.Contract(
simpleTokenContractAddress,
simpleTokenArtifact.abi,
await this._provider.getSigner(0)
);
this.setState({ decimals: await this._simpleToken.decimals() });
const name = await this._simpleToken.name();
const symbol = await this._simpleToken.symbol();
const balance = await this._simpleToken.balanceOf(this.state.selectedAddress);