# ethereum-method **Repository Path**: SuHangWeb/ethereum-method ## Basic Information - **Project Name**: ethereum-method - **Description**: 以太坊使用方法 用于记录 无限迭代 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-14 - **Last Updated**: 2024-08-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 使用方法 ## 所需依赖 - web3 用来进行合约调用 - bignumber.js 用来进行数字运算 ## 调用方法 ### 请求以太坊账户 ```js const accounts = await EthRequestAccounts(); ``` ### 获取以太坊链 ID ```js const chainId = await EthChainId(Boolean); ``` | 参数 | 类型 | 必填 | 说明 | | :----- | :------ | :--- | :--------------- | | 参数 1 | Boolean | 否 | 是否进行轮询操作 | ### 获取以太坊 Gas 价格 ```js const gasPrice = await GetGasPrice(); ``` ### 获取 gas 限制 ```js const gasLimit = await GetGasLimit({ from, to, amount, pow, ...{}, }); ``` | 参数 | 类型 | 必填 | 说明 | | :----- | :----- | :--- | :------------------------ | | from | String | 是 | 当前地址 | | to | String | 是 | 合约地址 | | amount | String | 是 | 转账金额 | | pow | Number | 否 | 幂次 默认为 10 的 18 次方 | | ... | any | 否 | 更多 | ### 获取以太坊地址的余额 ```js const balance = await EthGetBalance(String, Number); ``` | 参数 | 类型 | 必填 | 说明 | | :----- | :----- | :--- | :------------------------ | | 参数 1 | String | 是 | 当前地址 | | 参数 2 | Number | 否 | 幂次 默认为 10 的 18 次方 | ### 获取以太坊代币余额 ```js const tokenBalance = await EthGetTokenBalance({ address, tokenAddress, pow, }); ``` | 参数 | 类型 | 必填 | 说明 | | :----------- | :----- | :--- | :------------------------ | | address | String | 是 | 当前地址 | | tokenAddress | String | 是 | 代币合约地址 | | pow | Number | 否 | 幂次 默认为 10 的 18 次方 | ### 根据交易哈希值获取交易信息 ```js const getTransactionByHash = await EthGetTransactionByHash(String, Boolean); ``` | 参数 | 类型 | 必填 | 说明 | | :----- | :------ | :--- | :----------------------------------------- | | 参数 1 | String | 是 | 交易哈希值 | | 参数 2 | Boolean | 否 | 是否使用轮询方式查询交易信息,默认为 false | ### 发送以太坊交易 ```js const sendTransaction = await EthSendTransaction({ from, to, amount, pow, gasLimit, gas, value, dataSuffix, type, ...{}, }); ``` | 参数 | 类型 | 必填 | 说明 | | :--------- | :----- | :--- | :---------------------------------------------------------------------------------- | | from | String | 是 | 当前地址 | | to | String | 是 | 交易接收者地址 | | amount | Number | 是 | 交易金额 | | pow | Number | 否 | 幂次 默认为 10 的 18 次方 | | gasLimit | Number | 否 | 交易 gas 限制,单位为 wei | | gas | Number | 否 | 交易 gas 价格,单位为 wei | | value | String | 否 | 交易的 value 字段,默认为 0x00 | | dataSuffix | String | 否 | 自定义的 data 后缀 如果配置后缀则代表 data 值拼接 type 后都需要手动通过当前字段传递 | | type | String | 否 | 交易类型,默认为"a9059cbb" | | ... | any | 否 | 更多 |