我正在尝试调用智能合约上的应付函数,该函数只接受一个参数。
如何将 eth 值与函数调用一起发送到 ethers.js 中的该函数?这些文档似乎没有给出太多关于执行此操作的最佳方法的示例。
我的函数调用
const reciept = await contract.buyPunk(1001);
Run Code Online (Sandbox Code Playgroud)
所有其他读写函数调用都按预期工作,但它调用了我尚未解决的付费函数。
我正在使用 MetaMask 将交易发送到我的 DApp 中的合约。我需要有关如何在用户单击注销按钮时断开 MetaMask 帐户与我的 DApp 的帮助。
前端:ReactJS
后端:Web3js、Solidity(以太坊)
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 …
我正在得到
类型“Window & typeof globalThis”上不存在属性“ethereum”
反应中的错误。这是产生问题的行:
import { ethers } from 'ethers'
const provider = new ethers.providers.Web3Provider(window.ethereum);
Run Code Online (Sandbox Code Playgroud)
知道会发生什么吗?
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 ++; 但我不知道如何判断买家是否在映射中
运行测试和脚本时,所有函数均由 Hardhat 提供的第一个地址调用。
我想知道是否有办法在同一测试或脚本中更改调用地址。
提前致谢!
我如何连接字符串的可靠性?
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)
也没为我工作..:/
我正在尝试提取钱包地址持有的代币合约列表,类似于 bscscan 的做法,但以编程方式除外。bscscan.com/apis 没有端点,web3js 似乎只报告 ETH 余额。
这是可以实现的,因为 bscscan 报告列表并且许多令牌跟踪器(例如 farmfol.io )似乎也提取该信息。我只是没有找到正确的方法
ethereum ×10
solidity ×7
ethers.js ×3
web3js ×3
javascript ×2
metamask ×2
node.js ×2
reactjs ×2
binance ×1
blockchain ×1
contract ×1
hardhat ×1
typescript ×1