通过智能合约将ETH转移到其他帐户?

发布于 2025-02-13 22:48:31 字数 145 浏览 0 评论 0原文

在以下代码中,将以WEI的形式转移eTH,但我希望金额以醚的形式转移,我该怎么做?

function (uint amount) public payable {
someaddress.transfer(amount);
}

In the below code eth will be transferred in the form of Wei by default, but I want the amount will transfer in the form of Ether, how can I do that?

function (uint amount) public payable {
someaddress.transfer(amount);
}

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

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

发布评论

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

评论(1

微凉徒眸意 2025-02-20 22:48:31

WEI是以太的最小单位,特别是1 eth == 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000亿。

Transfer()函数始终接受WEI中的金额。因此,如果您只想将1作为输入参数,这意味着要发送1个完整的ETH,则可以将值乘以1E18有效地将ETH转换为WEI。

function (uint ethAmount) public payable {
    uint weiAmount = ethAmount * 1e18;
    someaddress.transfer(weiAmount);
}

注意:还有全局单元,但在当前的固定版本(0.8)中,它只能与数字文字结合使用,而不是与变量一起使用。

uint weiAmount = 1 ether; // ok
uint weiAmount = ethAmount ether; // syntax error

Wei is the smallest unit of Ether, specifically 1 ETH == 1,000,000,000,000,000,000 (or 1e18) wei.

The transfer() function always accepts the amount in wei. So if you want to pass just 1 as the input param, meaning that you want to send 1 full ETH, you can multiply the value by 1e18 effectively converting ETH to wei.

function (uint ethAmount) public payable {
    uint weiAmount = ethAmount * 1e18;
    someaddress.transfer(weiAmount);
}

Note: There's also the ether global unit, but in the current Solidity version (0.8), this can be used only in combination with number literals - not with variables.

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