标签: ether

什么是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
查看次数

在 ethers.js 中设置合约方法的 Gas 限制

问题

我试图在测试网络(ropsten)上使用合约的方法,但由于以下错误而失败:

原因:'无法估计气体;交易可能失败或可能需要手动气体限制',代码:'UNPREDICTABLE_GAS_LIMIT'

代码

我创建了一个智能合约的实例,并想调用它的注册方法:

const registrationContract = new ethers.Contract(ADDRESS, abi, signer);
const hashedDomain = utils.keccak256(utils.toUtf8Bytes(domain));

const register = await registrationContract.register(hashedDomain, walletAddress);
Run Code Online (Sandbox Code Playgroud)

ethers.js是否提供了对合约设置限制的功能?或者可以用其他方式做到这一点吗?我在文档中没有找到。

javascript ethereum ether ethers.js

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

如何使用 Hardhat 将以太币添加到我的本地主机 Metamask 钱包?

我已将元掩码连接到使用安全帽创建的节点http://localhost:8545设置链 id 以匹配安全帽网络链 id 后,我可以在元掩码中连接到网络上的此节点(31337)

如何将以太币发送到本地主机网络上的帐户/地址,以便这些帐户有足够的以太币来部署合约?

localhost metamask ether hardhat

12
推荐指数
1
解决办法
9091
查看次数

错误:在调用多重调用合约以太坊的聚合函数时发送交易需要签名者

\n

index.js:1 无法获取多重调用块 [{\xe2\x80\xa6}] 1 错误:发送交易需要签名者(操作=“sendTransaction”,代码=UNSUPPORTED_OPERATION,版本=contracts/5.0.2)

\n
\n

多重调用合约地址 - https://etherscan.io/address/0xeefba1e63905ef1d7acba5a8513c70307c1ce441#writeContract

\n

在 Uniswap 界面中工作,但在我的代码中抛出错误,我不知道出了什么问题

\n

javascript reactjs ethereum ether etherscan

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

即使所有者也无法调用实现“public onlyOwner”的 Solidity 函数

我正在按照此处的文档进行操作:https://docs.alchemyapi.io/alchemy/tutorials/how-to-create-an-nft/how-to-mint-a-nft。并拥有以下形式的智能合约:

pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

  contract NFTA is ERC721, Ownable {

     using Counters for Counters.Counter;
     Counters.Counter public _tokenIds;
     mapping (uint256 => string) public _tokenURIs;
     mapping(string => uint8) public hashes;

     constructor() public ERC721("NFTA", "NFT") {}

     function mintNFT(address recipient, string memory tokenURI)
          public onlyOwner
          returns (uint256)
      {
          _tokenIds.increment();

          uint256 newItemId = _tokenIds.current();
          _mint(recipient, newItemId);
          _setTokenURI(newItemId, tokenURI);

          return newItemId;
     }

     /**
      * @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
      *
      * Requirements:
      *
      * - …
Run Code Online (Sandbox Code Playgroud)

ethereum solidity ether

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

bigNumber 无法正确解析以太币

我有以下内容:

import { BigNumber } from "@ethersproject/bignumber";
import { parseUnits } from "@ethersproject/units";

const decimals = 18;

export const add = (a: string, b: string): string => {
  const _a = parseUnits(a, decimals);
  console.log(_a.toString(), a);
  const _b = BigNumber.from(b);
  const res = _a.add(_b).toString();
  return res;
};

// a = 123456789123456789.123456789123456789
// b = 1
// _a.toString() = 123456789123456789123456789123456789
// res = 123456789123456789123456789123456790
Run Code Online (Sandbox Code Playgroud)

我是否遗漏了一些明显的东西,为什么res不能计算为“123456789123456790.123456789123456789”?

即使我不传入decimals,结果也是一样的。(理想情况下我不想指定实际的小数值)

javascript numbers typescript ethereum ether

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

为什么我们不能通过智能合约将以太网发送到以太坊地址0x1

有了下面的可靠性代码,我试图通过智能合约将以太网发送到以太坊钱包地址0x1,它就会失败.但是,当我尝试直接从我的钱包发送以太网到地址0x1时,它就会成功.

pragma solidity ^0.4.24;

contract Transfer {

    constructor () public payable {
        // Deploy contract with 1000 wei for testing purpose
        require(msg.value == 1000);
    }

    function done() public {
        address(0).transfer(1); // Transaction success
    }

    function fail() public {
        address(1).transfer(1); // Transaction failed
    }

    function send(address account) public {
        account.transfer(1); // Transaction success (except 0x1)
    }

}
Run Code Online (Sandbox Code Playgroud)

为什么我们不能通过合约将以太网发送到地址0x1

参考:

  1. 直接从我的钱包发送以太币是成功的 https://ropsten.etherscan.io/tx/0x1fdc3a9d03e23b0838c23b00ff99739b775bf4dd7b5b7f2fa38043056f731cdc

  2. done()函数成功 https://ropsten.etherscan.io/tx/0xd319c40fcf50bd8188ae039ce9d41830ab795e0f92d611b16efde0bfa1ee82cd

  3. fail()函数失败 https://ropsten.etherscan.io/tx/0x0c98eafa0e608cfa66777f1c77267ce9bdf81c6476bdefe2a7615158d17b59ad

blockchain ethereum solidity smartcontracts ether

6
推荐指数
1
解决办法
440
查看次数

“错误:无法检查交易收据:” Web3.js[1.0.0] 与 Node ,使用 sendSignedTransaction 收到此错误

这是我尝试运行的代码:

w3.eth.sendSignedTransaction( data ).once( 'transactionHash', (hash) => {
    console.log('hash')
  }).once('receipt', (receipt) => {
    console.log('receipt');
  }).on('confirmation', (confirmationNumber, receipt) => {
    console.log('confirmation');
  }).on('error', (err) => {
    console.log(err);
  }).then( (receipt) => {
    console.log('finally got the receipt!');
  })
Run Code Online (Sandbox Code Playgroud)

我在执行时遇到的错误如下:

Error: Failed to check for transaction receipt:
{}
    at Object._fireError (/..../node_modules/web3-utils/src/index.js:56:17)
    at /..../node_modules/web3-core-method/src/index.js:260:23
    at <anonymous>
Run Code Online (Sandbox Code Playgroud)

任何解决此问题的帮助将不胜感激。

node.js blockchain ethereum web3js ether

5
推荐指数
0
解决办法
3343
查看次数

以太坊 Nonce 管理。错误随机数太低

我使用 web3 和供应商主网。我按合同进行了 2 笔交易。首先是批准方法,另一笔交易是多次转账。我将第二个签名存储在数据库中。如果第一笔交易成功,我发送第二笔交易/。第二个事务几乎总是错误 nonce 太低`。我该如何解决这个问题

bitcoin ethereum ether cryptocurrency

5
推荐指数
2
解决办法
7678
查看次数

如何在 Remix IDE 中设置 msg.value

这可能是我错过的一个简单错误,但我一生都无法弄清楚如何在这个合同中设置 msg.value 变量。我在网上读到这个值是与交易相关的 wei 数量,但是作为合约的调用者,我如何具体设置该值。这是我正在努力处理的合同。

杂注坚固性 0.8.7;

合同自动售货机 {

// Declare state variables of the contract
address public owner;
mapping (address => uint) public cupcakeBalances;

// When 'VendingMachine' contract is deployed:
// 1. set the deploying address as the owner of the contract
// 2. set the deployed smart contract's cupcake balance to 100
constructor() {
    owner = msg.sender;
    cupcakeBalances[address(this)] = 100;
}

// Allow the owner to increase the smart contract's cupcake balance
function refill(uint amount) public {
    require(msg.sender …
Run Code Online (Sandbox Code Playgroud)

solidity ether remix

5
推荐指数
1
解决办法
5595
查看次数