以太坊中以太币及代币计量单位

访客 阅读:17 2024-06-21 13:18:19 评论:0
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

无论是构建交易进行以太币的转账或是调用智能合约进行代币的发放,单位都是不可或缺的。今天就带大家详细了解一下以太坊中以太币和代币的单位,以及如何通过web3的方式进行操作。

The units are essential, whether to build a transaction for money transfers or to call smart contracts for the issuance of tokens. Today, you will be given a detailed idea of how to operate in Tai Ying's currency and in its currency units, and how to do so through web3.

首先我们来看一下以太币单位之间的转换,以太币的最小单位为wei,1个eth相当于10的8次方wei。通常,大家也使用Gwei作为展示单位。比较常用的就是eth,Gwei和wei。

First of all, let's take a look at the conversion between the tusk units, with the smallest unit of the tusk being wei, and one eth being equivalent to the eight sides of ten wei. Usually, Gwei is also used as a display unit. The more common ones are eth, Gwei and wei.

单位

Units

wei值

wi value

Wei

wei

1

1 wei

Kwei (babbage)

1e3 wei

1,000

Mwei (lovelace)

1e6 wei

1,000,000

Gwei (shannon)

1e9 wei

1,000,000,000

microether (szabo)

1e12 wei

1,000,000,000,000

milliether (finney)

1e15 wei

1,000,000,000,000,000

ether

1e18 wei

1,000,000,000,000,000,000

为了使用和验证web3的操作命令,我们先进入geth的console控制台,在这里对具体的单位或进制转换进行详细的实例演示。

In order to use and validate the web3 operational command, we first enter the console console of the geth, where a detailed demonstration of the specific unit or evolution is made.

启动geth,进入控制台命令:

Activate geth. Enter Console command:

代码语言:javascript
复制

可根据自己的具体情况调整geth路径和ipc路径。

The geth and ipc paths can be adjusted according to their specific circumstances.

十六进制转十进制

此转换方法为web3.toDecimal(hexString)。直接在控制台输入一下命令进行使用此函数进行转换。

This conversion method is web3.toDecimal (hexString). Enter the command directly on the control table to use this function for conversion.

代码语言:javascript
复制

通过此函数将十六进制的0x16转换为十进制的22。

Converts a hexadecimal 0x16 to a decimal 22.

十进制转十六进制

转换函数:web3.fromDecimal(number)。

Conversion function: web3.fromDecimal (number).

控制台命令及结果如下:

The Console command and the results are as follows:

代码语言:javascript
复制

转换为BigNumber类型

把给定数字或十六进制字符串转为 BigNumber 类型的实例。

An example of converting a given number or hexadecimal string to the BigUMer type.

代码语言:javascript
复制

此处转换需要注意的是BigNumber只会保留小数点后20位,超过20位的部分将会被截取掉。

What needs to be noted here is that Bignummer will only keep 20 decimal places and that more than 20 places will be intercepted.

以太币单位转换

上面表格中列出了以太币之间的单位进制,同样可以使用web3进行相应的转换,基本函数为web3.fromWei和web3.toWei(number, unit)。

The above table lists the units of evolution between tusks, which can be converted accordingly using Web3 with the basic functions of web3.fromwei and web3.towei (number, unit).

具体实例如下:

Specific examples are as follows:

代码语言:javascript
复制

其他的相关转换大家可自行尝试,下面列出相应的转换种类: - kwei/ada - mwei/babbage - gwei/shannon - szabo - finney - ether - kether/grand/einstein - mether - gether - tether

Other related conversions can be tried on their own and the corresponding conversion types are listed below: -kwei/ada - mwei/babbage - gwei/channon - szabo - finney - other - keep/grand/einstein - either - get her - other

通过上面的函数,在交易的过程中我们就可以随意的单位进行发送交易,而不必使用最小单位wei。

Through the function above, we can send the transaction at random during the transaction without using the smallest unit.

代码语言:javascript
复制

通过查询余额的方法,我们也可以看出区块链中存储这些数据的单位为wei。

By searching the balance, we can also see that the unit in which the data are stored in the block chain is wei.

代码语言:javascript
复制

在编写ERC-20的代币合约时我们可以指定代币的单位,比如:

In preparing the currency contract for the ERC-20, we can specify units of the currency, such as:

代码语言:javascript
复制

这里就指定了代币单位精确到小数点后几位。比如精确到小数点后3位,那么1个代币存储时就是1000个最小单位的值。

Here you specify the number of decimal units that are accurate to the number of decimal places. For example, when you are accurate to the number of decimal places, a coin is stored with a value of 1,000 minimum units.

文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明 网址:https://netpsp.com/?id=68695

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
关注我们

若遇到问题,加微信客服---清歌

搜索
排行榜
扫一扫,加我为微信好友加我为微信好友