标签: solidity

不支持文件导入回调?

尝试运行:

\n

1.) Dappuniversity 项目 (dappuniversity/dbank)\n2.) pet-shop-tutorial

\n

Truffle v5.3.3(核心:5.3.3)\nNode v14.15.5

\n

当 Truffle 要求 it\xe2\x80\x99s 编译器/solc 匹配 5.3.3 时,ser 如何在 0.8.4 编译代码以导入 OpenZeppelin\xe2\x80\x99s ERC20.sol 模板?

\n
// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.4;\n\nimport "@openzeppelin/contracts/token/ERC20/ERC20.sol";\n\ncontract Token is ERC20 {\n\n  //add minter variable\n\n  //add minter changed event\n\n  constructor() public payable ERC20("Name", "Symbol") {\n\n    //assign initial minter\n\n  }\n\n  //Add pass minter role function\n\n  function mint(address account, uint256 amount) public {\n\n    //check if msg.sender has a minter role\n\n    _mint(account, amount);\n\n  }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n

未找到源 \xe2\x80\x9c@openzeppelin/contracts/token/ERC20/ERC20.sol\xe2\x80\x9d:不支持文件导入回调

\n

solidity erc20 openzeppelin

33
推荐指数
6
解决办法
4万
查看次数

当我尝试使用 Ganache 运行 Web3py 时,为什么会收到错误“不支持方法 eth_maxPriorityFeePerGas”?

使用 Ganache-cli 运行 Web3.py 会返回以下错误:

不支持方法 eth_maxPriorityFeePerGas。

然而,当直接使用像 Ropsten 这样的测试网络而不需要 Ganache-cli 时,这确实有效。

按照教程运行此代码:

from solcx import compile_standard, install_solc
import json
from web3 import Web3
import os
from dotenv import load_dotenv

load_dotenv()

with open("./SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()

install_solc("0.6.0")

compiled_sol = compile_standard(
    {
        "language": "Solidity",
        "sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
        "settings": {
            "outputSelection": {
                "*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
            }
        },
    },
    solc_version="0.6.0",
)

with open("compiled_code.json", "w") as file:
    json.dump(compiled_sol, file)

bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
    "bytecode"
]["object"]

abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"] …
Run Code Online (Sandbox Code Playgroud)

python solidity ganache web3py

32
推荐指数
2
解决办法
7982
查看次数

如何在solidity中生成随机数?

我有几个 keccak,如果我能找到一种便宜的方法来获取所创建的 uint 的一部分,那么它们可以减少到一个。

pragma solidity ^0.4.19;

contract test {
  function test() {

  }

function sup() returns (uint test) {
    uint _test = uint(keccak256("wow"));
    return _test;
  }
}
Run Code Online (Sandbox Code Playgroud)

这会返回一个甜蜜的随机数:13483274892375982735325

现在的计划是,我不用用不同的“种子”调用 keccak 5 次,而是可以将该数字分开并得到类似:1348、3274、8923 等的内容,然后将其用作我的随机数,例如:1348 % 10

但坚固性并不能仅仅做到这一点。有什么便宜又好用的东西吗?

string blockchain ethereum solidity smartcontracts

28
推荐指数
3
解决办法
6万
查看次数

ethers.js 合约实例中没有 safeTransferFrom 函数?

我在安全帽控制台中创建了一个合约实例,如下所示:

\n
const contract_fac = await ethers.getContractFactory("ContractName");\nconst contract = await contract_fac.attach("CONTRACTADDR...");\n
Run Code Online (Sandbox Code Playgroud)\n

合约对象具有除 之外的所有公共/外部函数safeTransferFrom。为什么?

\n

当我用它调用它时,它contract.safeTransferFrom(\xe2\x80\xa6)会抛出 JavaScript 错误 \xe2\x80\x9csafeTransferFrom 不是函数\xe2\x80\x9d。这是一个错误还是我不明白什么?safeTransferFrom函数在 ABI 中列出。

\n

我使用未做任何更改的 OpenZeppelin (v. 4.2) 721 令牌模板、Ethers.js (v. 5.4.1) 和 Hardhat (v. 2.4.1)。

\n

更新: \n问题已解决。safeTransferFrom 是一个重载函数。在 ethers 中,调用重载合约函数的语法与非重载函数不同。\n Ethers.js doc

\n

错误的:

\n
contract.safeTransferFrom(addr1, addr2, 1);\n
Run Code Online (Sandbox Code Playgroud)\n

正确的:

\n
contract["safeTransferFrom(address,address,uint256)"](addr1, addr2, 1);\n
Run Code Online (Sandbox Code Playgroud)\n

ethereum solidity openzeppelin ethers.js hardhat

28
推荐指数
1
解决办法
5233
查看次数

什么是Solidity中的地址(0)

任何人都可以向我解释什么address(0)是Solidity?我在文档中发现了以下内容,但它对我来说并不合理:

如果目标帐户是零帐户(地址为0的帐户),则该事务会创建新合同.如前所述,该合同的地址不是零地址,而是从发送方及其发送的交易数量("nonce")得出的地址.这种合同创建事务的有效负载被认为是EVM字节码并被执行.此执行的输出将永久存储为合同代码.这意味着,为了创建合同,您不发送合同的实际代码,而是实际返回该代码的代码.

http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html?highlight=address(0)#index-8

ethereum solidity ether

27
推荐指数
2
解决办法
9338
查看次数

我如何将 eth 值发送到 ethers.js 中支付的特定智能合约函数?

我正在尝试调用智能合约上的应付函数,该函数只接受一个参数。

如何将 eth 值与函数调用一起发送到 ethers.js 中的该函数?这些文档似乎没有给出太多关于执行此操作的最佳方法的示例。

我的函数调用

const reciept = await contract.buyPunk(1001);
Run Code Online (Sandbox Code Playgroud)

所有其他读写函数调用都按预期工作,但它调用了我尚未解决的付费函数。

node.js ethereum solidity ethers.js

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

如何使用 web3.js 注销 MetaMask 帐户

我正在使用 MetaMask 将交易发送到我的 DApp 中的合约。我需要有关如何在用户单击注销按钮时断开 MetaMask 帐户与我的 DApp 的帮助。

前端:ReactJS

后端:Web3js、Solidity(以太坊)

reactjs ethereum solidity web3js metamask

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

如何找出以太坊地址是否合同?

Solidity中的地址可以是帐户或合同(或其他事物,例如交易).当我有一个变量x,持有一个地址时,我该如何测试它是否是合同?

(是的,我已经阅读了关于 doc中类型章节)

ethereum solidity smartcontracts

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

Warning: Function state mutability can be restricted to pure function

I am new to solidity and I have been trying to print out simple messages using functions in solidity, but I have failed to deploy successfully, and there is an error that I can not figure out what's wrong.

This is what I have tried so far:

 pragma solidity ^0.6.0;
    
    contract test {
        
        string public _feedback;
        
        function reply(string memory feedback) public
        {
           feedback = "Well done!";
        }
    }
Run Code Online (Sandbox Code Playgroud)

The error I am receiving is "Warning: Function state mutability can be …

ethereum solidity

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

是否有类似于坚固的东西

    struct buyer{
       uint amount;
       Status status;
    }

    mapping(address=>buyer) public buyers;
    mapping(uint=>address) buyerIndex;
    uint public buyerNum;
    //Order a product.
    function(){
      uint doubleValue=value*2;
      uint amount=msg.value/doubleValue; 
      if(buyers[msg.sender]==null){ //Error in this line
      buyer abuyer=buyer({amount:amount,status:Status.Created}); //Error in this line
      buyerNum++;
      buyerIndex[buyerNum]=msg.sender;
      buyers[msg.sender]=abuyer;
    }else{
      buyers[msg.sender].amount+=amount;
    }
      Order(msg.sender,amount*doubleValue,amount);

 }
Run Code Online (Sandbox Code Playgroud)

如果买方没有记录在买方映射中,那么buyerNum ++; 但我不知道如何判断买家是否在映射中

contract ethereum solidity

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