标签: ethereum

Solidity - 类型错误:覆盖函数缺少“覆盖”说明符

我正在基于 BEP20Token 模板(https://github.com/binance-chain/bsc-genesis-contract/blob/master/contracts/bep20_template/BEP20Token.template )创建智能合约(BEP20 代币)。公共构造函数被修改以添加一些令牌详细信息。然而,所有标准函数都会出现编译时问题,例如缺少覆盖函数。

**这是源代码**

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.2;

interface IBEP20 {
  /**
   * @dev Returns the amount of tokens in existence.
   */
  function totalSupply() external view returns (uint256);

  /**
   * @dev Returns the token decimals.
   */
  function decimals() external view returns (uint8);

  /**
   * @dev Returns the token symbol.
   */
  function symbol() external view returns (string memory);

  /**
  * @dev Returns the token name.
  */
  function name() external view returns (string memory);

  /**
   * @dev …
Run Code Online (Sandbox Code Playgroud)

ethereum solidity binance-smart-chain

2
推荐指数
1
解决办法
1万
查看次数

智能合约可以访问其他区块链的数据吗?

假设我创建了一个 erc20 令牌。现在我想制定一个智能合约,如果用户在另一个区块链(如比特币)上有 X 个硬币,则向用户发送 1 个硬币。那行得通吗?我可以使用卡尔达诺/以太坊/任何其他智能合约从其他区块链读取数据吗?

blockchain ethereum smartcontracts cryptocurrency cardano

2
推荐指数
1
解决办法
666
查看次数

我们可以通过代币名称获取智能合约地址吗

我想像 Etherscan 那样通过代币名称获取智能合约信息,但需要使用我的专用网络。

根据 web3 文档,如果我需要获取与智能合约相关的任何信息,我首先需要有一个智能合约地址和 ABI。但是在编写智能合约时,我没有将其存储在数据库中的命令。

我的主要目标是我需要创建一个浏览器的精确副本,如 Etherscan 和 bscscan.com

blockchain ethereum go-ethereum erc20 ethereumclassic

2
推荐指数
1
解决办法
1767
查看次数

将 Secret 存储在 EVM 区块链中

我正在考虑将秘密存储在区块链中。虽然有一些特定的区块链在处理它,但我想看看以太坊的可行性。

这个想法是将秘密存储为加密格式的状态变量,并且该变量值的可访问性仅限于某人。我的问题是,由于区块链是开放的,每个人都可以,如果有人真的很熟练,那么他/她可以读取每个变量的值。您认为,或者需要进一步做什么,才能使状态变量的值足够安全?

security privacy blockchain ethereum solidity

2
推荐指数
1
解决办法
780
查看次数

为什么我收到以下 Chainlink 错误:无法估计 Gas

我正在尝试使用安全帽遵循此处找到的 Chainlink VRF 教程: https: //docs.chain.link/docs/intermediates-tutorial/,并在调用 rollDice 函数时遇到此问题:

Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"cannot estimate gas; transaction may fail or may require manual gas limit","code":"UNPREDICTABLE_GAS_LIMIT","method":"estimateGas","transaction":{"from":"0x014Da1D627E6ceB555975F09D26B048644382Ac6","maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x9502f900"},"maxFeePerGas":{"type":"BigNumber","hex":"0x9502f90e"},"to":"0x5887946875A01D1BB79d6Fb357BceeA5A0096D2e","data":"0xdd02d9e5000000000000000000000000014da1d627e6ceb555975f09d26b048644382ac6","type":2,"accessList":null}}, tx={"data":"0xdd02d9e5000000000000000000000000014da1d627e6ceb555975f09d26b048644382ac6","to":{},"from":"0x014Da1D627E6ceB555975F09D26B048644382Ac6","type":2,"maxFeePerGas":{"type":"BigNumber","hex":"0x9502f90e"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x9502f900"},"nonce":{},"gasLimit":{},"chainId":{}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.5.0)
    at Logger.makeError (/Users/matt/Desktop/hardhat/randomDay/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
    at Logger.throwError (/Users/matt/Desktop/hardhat/randomDay/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
    at /Users/matt/Desktop/hardhat/randomDay/node_modules/@ethersproject/abstract-signer/src.ts/index.ts:301:31
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 7)
Run Code Online (Sandbox Code Playgroud)

我能够部署到 Kovan 测试网,我能够验证合约,并且我已经发送了合约 LINK 代币,但仍然遇到了问题。合约可以在这里查看:https://kovan.etherscan.io/address/0x7b72d80670512c87605ab8ac7e6113fda9c57de4#code

我正在使用 Chainlink 合约 0.8 版本。

随机日.sol

pragma solidity ^0.8.9;

import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";

contract RandomDay is VRFConsumerBase {
    
    uint256 private constant ROLL_IN_PROGRESS = …
Run Code Online (Sandbox Code Playgroud)

blockchain ethereum solidity chainlink

2
推荐指数
1
解决办法
2309
查看次数

在 NextJS 应用程序中导入 web3 时出现 Netlify 构建错误 - “错误:无法解析...中的‘电子’”

我正在构建一个使用 web3 与以太坊智能合约交互的网页。每当我将 web3 导入页面时,我都会在 Netlify 构建中遇到错误:

9:54:39 PM: ModuleNotFoundError: Module not found: Error: Can't resolve 'electron' in '/opt/build/repo/node_modules/swarm-js/node_modules/got'
9:54:39 PM: > Build error occurred
9:54:39 PM: Error: > Build failed because of webpack errors
Run Code Online (Sandbox Code Playgroud)

我可以通过将 web3 导入添加到页面来重现出现此错误与未出现此错误的情况:

import web3 from '../ethereum/web3'
Run Code Online (Sandbox Code Playgroud)

上面的代码只是从另一个文件导出实例化的 web3 实例:

import Web3 from "web3";
 
let web3;
 
if (typeof window !== "undefined" && typeof window.ethereum !== "undefined") {
  // We are in the browser and metamask is running.
  window.ethereum.request({ method: "eth_requestAccounts" });
  web3 = new Web3(window.ethereum); …
Run Code Online (Sandbox Code Playgroud)

electron ethereum netlify next.js web3js

2
推荐指数
1
解决办法
819
查看次数

ETH 2.0 和 NEAR 有什么区别?

Etherium 2.0 和 NEAR 在很多方面似乎非常相似。有人可以详细说明两者之间有什么区别吗?

blockchain ethereum nearprotocol near

2
推荐指数
1
解决办法
114
查看次数

导入 web3 导致 React js 出现问题

Compiled with problems:
Run Code Online (Sandbox Code Playgroud)

./node_modules/cipher-base/index.js 中的错误 3:16-43

找不到模块:错误:无法解析“C:\Blockchain\lottery-React\node_modules\cipher-base”中的“流”

重大更改:webpack < 5 默认情况下包含 Node.js 核心模块的 Polyfill。这已不再是这种情况。验证您是否需要此模块并为其配置一个polyfill。

如果你想包含一个polyfill,你需要: - 添加一个后备 'resolve.fallback: { "stream": require.resolve("stream-browserify") }' - 安装 'stream-browserify' 如果你不这样做想要包含一个polyfill,你可以使用一个空模块,如下所示:resolve.fallback: { "stream": false }

./node_modules/eth-lib/lib/bytes.js 中的错误 9:193-227

找不到模块:错误:无法解析“C:\Blockchain\lottery-React\node_modules\eth-lib\lib”中的“加密”

重大更改:webpack < 5 默认情况下包含 Node.js 核心模块的 Polyfill。这已不再是这种情况。验证您是否需要此模块并为其配置一个polyfill。

如果你想包含一个polyfill,你需要: - 添加一个后备 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }' - 安装 'crypto-browserify' 如果你不这样做想要包含一个polyfill,你可以使用一个空模块,如下所示:resolve.fallback: { "crypto": false }

./node_modules/ethereumjs-util/dist.browser/account.js 71:31-48 中出现错误

找不到模块:错误:无法解析“C:\Blockchain\lottery-React\node_modules\ethereumjs-util\dist.browser”中的“assert”

重大更改:webpack < 5 默认情况下包含 Node.js 核心模块的 Polyfill。这已不再是这种情况。验证您是否需要此模块并为其配置一个polyfill。

如果你想包含一个polyfill,你需要: - 添加一个后备 'resolve.fallback: { "assert": require.resolve("assert/") }' - 安装 'assert' 如果你不想包含一个polyfill,你可以使用一个空模块,如下所示:resolve.fallback: …

javascript node.js reactjs ethereum web3js

2
推荐指数
1
解决办法
3767
查看次数

在以太坊中分配给 `uint` 如何节省“存储读取”成本?

我正在查看 uniswapv2 教程演练

以下内容参考了github 存储库中的此函数,并且教程说明如下:

    uint _kLast = kLast; // gas savings
Run Code Online (Sandbox Code Playgroud)

kLast 状态变量位于存储中,因此它在合约的不同调用之间会有一个值。访问存储比访问合约函数调用结束时释放的易失性内存要昂贵得多,因此我们使用内部变量来节省燃料。

因此,在传统编程中,_kLast将引用kLast. _kLast实例化后又被引用 3 次。

  • 如果它们只是用作kLast变量,而不是将其分配给,那么每次使用uint时是否都会花费一次存储读取?kLast
  • 如果不是这种情况,那么我真的不明白他们是如何节省汽油的,有人可以解释一下吗?

ethereum solidity

2
推荐指数
1
解决办法
744
查看次数

Metamask注入的window.ethereum和web3.js之间有什么关系吗?我们可以两者都使用吗?

我正在学习 DApp 编程,出现的一个问题是 Metamask 和 web3.js 注入的 API 之间的区别。据我了解,MetaMask 注入一个有自己的 API 的对象,与 web3.js 库无关。它是否正确?我仍然可以将 web3.js 库与 MetaMask 一起使用吗?在后一种情况下,我该怎么办?如果有人能进一步解释这种差异,我将不胜感激。谢谢!

blockchain ethereum smartcontracts web3js metamask

2
推荐指数
1
解决办法
2613
查看次数