有没有人能帮我用ethers.js编程传输ETH?
我在Rinkeby上有一些ETH,并希望以编程方式将其传输到任何地址。

请告诉我ETH合同的地址和如何使用ethers.js转帐。
发布于 2022-03-07 16:38:59
首先,我建议阅读有关ethers.js库的内容。这是一个用于使用evm网络的很好的库。
那么,让我们考虑两个选项:
我们从钱包开始吧。此示例可在ethers.js文档站点上找到:
// A Web3Provider wraps a standard Web3 provider, which is
// what MetaMask injects as window.ethereum into each page
const provider = new ethers.providers.Web3Provider(window.ethereum)
// MetaMask requires requesting permission to connect users accounts
Await provider.send("eth_requestAccounts", []);
// The MetaMask plugin also allows signing transactions to
// send ether and pay to change state within the blockchain.
// For this, you need the account signer...
const signer = provider.getSigner()
// Sending 1 ETH
const tx = signer.sendTransaction({
to: destAddress,
value: ethers.utils.parseEther("1.0")
});现在,如果我们没有像Metamask那样的钱包,但是我们有一个私钥,那么我们可以选择:
// The JsonRpcProvider is a popular method for interacting with Ethereum
const provider = new ethers.providers.JsonRpcProvider("ADDRESS OF RINKEBY RPC");
// Create a new Wallet instance for privateKey and connected to the provider.
const wallet = new Wallet("TOP SECRET PRIVATE KEY", provider);
// Sending 1 ETH
wallet.sendTransaction({
to: destAddress,
value: ethers.utils.parseEther("1.0")
})发布于 2022-03-07 12:02:49
快速搜索Google就可以完成这项工作,但是请查看这。
https://stackoverflow.com/questions/71375457
复制相似问题