如何使用 ethers.js 在 Rinkeby 上转移 ETH

发布于 2025-01-12 06:25:56 字数 293 浏览 3 评论 0原文

有没有人可以帮助我使用 ethers.js 以编程方式转移 ETH?

我在 Rinkeby 上有一些 ETH,想以编程方式将其转移到任何地址。

平衡开启Rinkeby

请告诉我ETH合约的地址以及如何使用ethers.js进行转账。

Is there anybody who can help me with transfer ETH programmatically using ethers.js?

I have some ETH on Rinkeby and want to transfer it to any address programmatically.

Balance on Rinkeby

Please let me know the address of ETH contract and how to transfer using ethers.js.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

牵你手 2025-01-19 06:25:56

首先,我建议阅读 ethers.js 库。这是一个用于使用 evm 网络的出色库。

然后我们考虑两种选择:

  1. 使用钱包(例如 Metamask)发送;
  2. 使用私钥发送钱包。

让我们从钱包选项开始。这个例子可以在 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")
})

First, I suggest reading about the ethers.js library. This is a great library for working with evm networks.

Then let's consider two options:

  1. sending with wallet like Metamask;
  2. sending without wallet using private key.

Let's start with the wallet option. This example can be found on the ethers.js documentation site:

// 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")
});

Now an option if we don't have a wallet like Metamask, but we have a private key:

// 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")
})
怂人 2025-01-19 06:25:56

快速的 Google 搜索就可以完成这项工作,但请检查 这个出来

A quick Google search would've done the job, but check this out

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文