标签: ethereum

我如何将 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万
查看次数

如何在 MetaMask 上触发更改区块链网络请求

我正在使用 web3 进行第一次 dapp 测试,如果尚未选择,MetaMask 会提示用户将网络更改为 Binance (BSC) 网络,如下所示:

元掩码请求更改网络

如何触发这样的请求?

javascript ethereum web3js metamask

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

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万
查看次数

React 中的“Window & typeof globalThis”类型上不存在属性“ethereum”错误

我正在得到

类型“Window & typeof globalThis”上不存在属性“ethereum”

反应中的错误。这是产生问题的行:

import { ethers } from 'ethers'

const provider = new ethers.providers.Web3Provider(window.ethereum);
Run Code Online (Sandbox Code Playgroud)

知道会发生什么吗?

typescript reactjs blockchain ethereum ethers.js

19
推荐指数
3
解决办法
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万
查看次数

如何使用不同的地址来调用 Hardhat 测试和脚本中的函数?

运行测试和脚本时,所有函数均由 Hardhat 提供的第一个地址调用。

我想知道是否有办法在同一测试或脚本中更改调用地址。

提前致谢!

ethereum solidity smartcontracts ethers.js hardhat

18
推荐指数
1
解决办法
6039
查看次数

字符串连接是否可靠?

我如何连接字符串的可靠性?

var str = 'asdf'
var b = str + 'sdf'
Run Code Online (Sandbox Code Playgroud)

似乎不起作用..

我查阅了文档(https://github.com/ethereum/wiki/wiki/Solidity-Tutorial#elementary-types-value-types),并没有提到有关字符串连接的内容.但据说它适用于点('.')?

"[...] a mapping key k is located at sha3(k . p) where . is concatenation."
Run Code Online (Sandbox Code Playgroud)

也没为我工作..:/

ethereum solidity

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

如何通过钱包地址获取所有代币

我正在尝试提取钱包地址持有的代币合约列表,类似于 bscscan 的做法,但以编程方式除外。bscscan.com/apis 没有端点,web3js 似乎只报告 ETH 余额。

这是可以实现的,因为 bscscan 报告列表并且许多令牌跟踪器(例如 farmfol.io )似乎也提取该信息。我只是没有找到正确的方法

javascript node.js ethereum web3js binance

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