任何人都可以向我解释什么address(0)是Solidity?我在文档中发现了以下内容,但它对我来说并不合理:
如果目标帐户是零帐户(地址为0的帐户),则该事务会创建新合同.如前所述,该合同的地址不是零地址,而是从发送方及其发送的交易数量("nonce")得出的地址.这种合同创建事务的有效负载被认为是EVM字节码并被执行.此执行的输出将永久存储为合同代码.这意味着,为了创建合同,您不发送合同的实际代码,而是实际返回该代码的代码.
我试图在测试网络(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是否提供了对合约设置限制的功能?或者可以用其他方式做到这一点吗?我在文档中没有找到。
我已将元掩码连接到使用安全帽创建的节点。http://localhost:8545设置链 id 以匹配安全帽网络链 id 后,我可以在元掩码中连接到网络上的此节点(31337)
如何将以太币发送到本地主机网络上的帐户/地址,以便这些帐户有足够的以太币来部署合约?
\n\nindex.js:1 无法获取多重调用块 [{\xe2\x80\xa6}] 1 错误:发送交易需要签名者(操作=“sendTransaction”,代码=UNSUPPORTED_OPERATION,版本=contracts/5.0.2)
\n
多重调用合约地址 - https://etherscan.io/address/0xeefba1e63905ef1d7acba5a8513c70307c1ce441#writeContract
\n在 Uniswap 界面中工作,但在我的代码中抛出错误,我不知道出了什么问题
\n我正在按照此处的文档进行操作: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) 我有以下内容:
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,结果也是一样的。(理想情况下我不想指定实际的小数值)
有了下面的可靠性代码,我试图通过智能合约将以太网发送到以太坊钱包地址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?
参考:
直接从我的钱包发送以太币是成功的 https://ropsten.etherscan.io/tx/0x1fdc3a9d03e23b0838c23b00ff99739b775bf4dd7b5b7f2fa38043056f731cdc
done()函数成功 https://ropsten.etherscan.io/tx/0xd319c40fcf50bd8188ae039ce9d41830ab795e0f92d611b16efde0bfa1ee82cd
fail()函数失败 https://ropsten.etherscan.io/tx/0x0c98eafa0e608cfa66777f1c77267ce9bdf81c6476bdefe2a7615158d17b59ad
这是我尝试运行的代码:
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)
任何解决此问题的帮助将不胜感激。
我使用 web3 和供应商主网。我按合同进行了 2 笔交易。首先是批准方法,另一笔交易是多次转账。我将第二个签名存储在数据库中。如果第一笔交易成功,我发送第二笔交易/。第二个事务几乎总是错误 nonce 太低`。我该如何解决这个问题
这可能是我错过的一个简单错误,但我一生都无法弄清楚如何在这个合同中设置 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)