我是区块链技术的新手。我正在尝试部署智能合约。但我在编译 sol 文件时总是遇到以下错误。它正在工作,但突然停止工作。我没有做任何改变。
这是我收到的错误
Traceback (most recent call last):
File ".\main.py", line 68, in <module>
main()
File ".\main.py", line 57, in main
compiled_sol = compile_source_file('contract.sol')
File ".\main.py", line 20, in compile_source_file
return solcx.compile_source(source)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\solcx\main.py", line 130, in compile_source
allow_empty=allow_empty,
File "C:\Program Files (x86)\Python37-32\lib\site-packages\solcx\main.py", line 277, in _compile_combined_json
combined_json = _get_combined_json_outputs(solc_binary)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\solcx\main.py", line 242, in _get_combined_json_outputs
help_str = wrapper.solc_wrapper(solc_binary=solc_binary, help=True)[0].split("\n")
File "C:\Program Files (x86)\Python37-32\lib\site-packages\solcx\wrapper.py", line 163, in solc_wrapper
stderr_data=stderrdata,
solcx.exceptions.SolcError: An error occurred during execution …Run Code Online (Sandbox Code Playgroud) 我是 Solidity 的初学者,我一直在玩松露,当我发送交易时,我得到一个交易日志,其中一个值是“tx”,其他标签非常不言自明,但我不太明白什么这个代表?
那么它代表什么/你可以用这些信息做什么?
谢谢
这是我的hardhat.config.js -
module.exports = {
solidity: "0.8.4",
networks: {
hardhat: {
chainId: 1337
},
mumbai: {
url: "https://rpc-mumbai.matic.today",
accounts: [process.env.pk]
},
// polygon: {
// url: "https://polygon-rpc.com/",
// accounts: [process.env.pk]
// }
}
};
Run Code Online (Sandbox Code Playgroud)
运行 npx Hardhat 测试时出现以下错误:
**Error HH8: There's one or more errors in your config file:
Invalid account: #0 for network: mumbai - Expected string, received undefined**`
Run Code Online (Sandbox Code Playgroud)
我的 Hardhat.config.js 文件似乎有一些错误,但无法找到。我正在使用 Nader Dabit 的 full-stack-web3 教程进行全栈 web3 开发。
我在 Ropsten 以太坊测试网络上部署了以下智能合约,之后我尝试使用 @alch/alchemy-web3 npm 包进行交易(是的,我正在使用 Alchemy API),但正如你所看到的,我在交易中收取了费用。这是为什么?公共视图函数调用不应该花费 0 Gas 吗?
\n部署的智能合约
\n// SPDX-Lincense-Identifier: MIT\npragma solidity ^0.8.11;\n\ncontract VendingMachine {\n address public owner;\n mapping(address => uint256) public donutBalances;\n\n constructor() {\n owner = msg.sender;\n donutBalances[address(this)] = 100;\n }\n\n function getVendingMachineBalance() public view returns (uint256) {\n return donutBalances[address(this)];\n }\n\n function restock(uint amount) public {\n require(msg.sender == owner, "Only the owner can restock this machine.");\n donutBalances[address(this)] += amount;\n }\n\n function purchase(uint amount) public payable {\n require(msg.sender == owner, "Only the owner can …Run Code Online (Sandbox Code Playgroud) 如何覆盖 Opezeppelin 默认小数点 18。文档说 _setupDecimals() 应该从构造函数调用;我究竟做错了什么。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
uint8 _decimals;
constructor() ERC20("MyToken", "MTK") {
_decimals = 3;
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
_mint(msg.sender, 5000 * 10 ** decimals());
}
}
Run Code Online (Sandbox Code Playgroud) solidity ×5
ethereum ×2
javascript ×2
blockchain ×1
config ×1
hardhat ×1
python ×1
python-3.x ×1
truffle ×1
web3js ×1
web3py ×1