我看到了一个类似的问题,但没有解决我的问题。这是我基于研究的合同代码。
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <=0.8.4;
contract Lottery {
// address payable is the same as address, but have transfer and send members.
address payable public manager;
address payable[] public players;
constructor (){
// msg.sender is an address where the current function call came from
manager = payable(msg.sender);
}
function enter() public payable {
// msg.value is the amount of wei sent with the message to the contract
require(msg.value > .01 ether);
players.push(payable(msg.sender));
}
function random() private view returns (uint) {
return uint(keccak256(abi.encodePacked(block.difficulty,block.timestamp)));
}
function pickWinner() public restricted {
uint index = random() % players.length;
// transfer reverts on failure
players[index].transfer(address(this).balance);
// resets the array
players = new address payable[](0);
}
modifier restricted() {
require(msg.sender == manager);
_;
}
function getPlayers() public view returns (address payable[] memory ) {
return players;
}
}
这是一个错误:
RuntimeError: abort([object Object]). Build with -s ASSERTIONS=1 for more info.
at process.abort (/home/projects/ethereum/lottery/node_modules/solc/soljson.js:1:13012)
我检查了"solc/soljson“第一个字母为"null”。
我检查了solc,有一个类似的问题,但仍然是开放的:https://github.com/ethereum/solc-js/issues/493
编译和测试这项工作是有效的。但问题在于部署。这是deploy.js
const HDWalletProvider = require("@truffle/hdwallet-provider");
const Web3 = require("web3");
const { abi, evm } = require("./compile");
const config = require("./config");
const bytecode = evm.bytecode.object;
const abi_string = JSON.stringify(abi);
const metamask_mnemonic = config.metamask_mnemonic;
const ropsten_network = config.ropsten_network;
const provider = new HDWalletProvider({
mnemonic: {
phrase: metamask_mnemonic,
},
providerOrUrl: ropsten_network,
});
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log("Attempting to deploy from account", accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(abi_string))
.deploy({ data: "0x" + bytecode })
.send({ gas: "1000000", from: accounts[0] });
// this address is used in etherscan to find the account
console.log("Contract deployed to" + result.options.address);
// console.log("ABI:" + abi_string);
};
deploy();
这是abi_string:
abi_String [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"enter","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getPlayers","outputs":[{"internalType":"address payable[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pickWinner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"players","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
此帐户为0:
Attempting to deploy from account 0x3FB83280e44B4c1b77E8fb3ce6e0E1C271BE1659
发布于 2021-06-11 01:38:12
我在try/catch块中编写了部署():
const deploy = async () => {
try {
const accounts = await web3.eth.getAccounts();
console.log("Attempting to deploy from account", accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(abi_string))
.deploy({ data: "0x" + bytecode })
.send({ from: accounts[0], gas: "1000000" });
// this address is used in etherscan to find the account
console.log("Contract deployed to", result.options.address);
console.log("ABI:" + abi_string);
} catch (error) {
console.log(error);
}
};
catch()阻止记录此错误:
{ code: -32000, message: 'insufficient funds for gas * price + value' }
所以我访问这个水龙头,把一些乙醚转移到accounts[0]
。
成功部署
https://ethereum.stackexchange.com/questions/101518
复制相似问题