是否可以仅使用以太js模拟帐户?我不想用安全帽。虽然我用铸造厂分叉主干网。现在想转移eth的让我们假设vitalik到我自己的帐户本地。不可能只使用以太js吗?
发布于 2023-05-01 19:05:50
import { ethers } from "ethers";
let url = "http://localhost:8545";
const provider = new ethers.providers.JsonRpcProvider(url);
async function impersonateAccount(address, targetAddress, amount) {
// Impersonate the account
await provider.send("anvil_impersonateAccount", [address]);
// Create a signer for the impersonated account
const signer = provider.getSigner(address);
// Send a transaction from the impersonated account
const tx = await signer.sendTransaction({
to: targetAddress,
value: ethers.utils.parseEther(amount),
});
await tx.wait();
console.log(`Sent ${amount} ETH from ${address} to ${targetAddress}`);
}
const addressToImpersonate = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
const targetAddress = "0x840E0f2e07A52F335e956947fd2AC0f60496f891";
const amount = "1000";
// impersonateAccount(addressToImpersonate, targetAddress, amount);
console.log(
ethers.utils.formatEther(
await provider.getBalance("0xd8da6bf26964af9d7eed9e03e53415d37aa96045")
)
);这是密码。甚至我也把eth从Vitalik账户转到了我的账户上。但他想弄明白什么是"anvil_impersonateAccount“。
https://ethereum.stackexchange.com/questions/149705
复制相似问题