我遇到此错误:
.../node_modules/truffle-expect/index.js:3
expected_keys.forEach(function(key) {
^
Error: Expected parameter 'solc' not passed to function.
当我尝试通过webpack使用松露固体装载机时。知道如何解决吗?谢谢。
更新:
智能合约:
pragma solidity ^0.5.0;
contract ToDo {
struct Task {
uint id;
uint date;
string content;
string author;
bool done;
}
uint lastTaskId;
mapping(uint => Task) tasks;
uint[] taskIds;
constructor () public{
lastTaskId = 0;
}
event TaskCreated(uint id, uint date, string content, string author, bool done);
function createTask(string memory _content, string memory _author) public {
lastTaskId++;
tasks[lastTaskId] = Task(lastTaskId, now, _content, _author, false);
taskIds.push(lastTaskId);
emit TaskCreated(lastTaskId, now, _content, _author, false);
}
function getTask(uint id) taskExists(id) public view returns (uint, uint, string memory, string memory, bool) {
return(
id,
tasks[id].date,
tasks[id].content,
tasks[id].author,
tasks[id].done
);
}
function getTaskIds() view public returns (uint[] memory) {
return taskIds;
}
// function getTaskFixtures(uint _id) public view returns(uint,uint,string,string,bool) {
// return (0, now, "Create more tutorials for ETB", "Julien", false);
// }
modifier taskExists(uint id){
if(tasks[id].id == 0){
revert();
}
_;
}
}
index.js:
import artifact from '../../contracts/ToDo.sol';
import Web3 from 'web3';
import TruffleContract from 'truffle-contract';
// import config from './config.js';
console.log('loaded');
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));
const abstraction = new TruffleContract(artifact);
abstraction.setProvider(web3.currentProvider);
const network = Object.keys(artifact.networks)[0];
const address = artifact.networks[network].address;
abstraction.at(address)
.then((todo) => {
todo.getTaskIds()
.then((taskIds) => {
console.log(taskIds);
});
});
web3.eth.getAccounts(console.log);
服务器:
const express = require('express');
const app = express();
const PORT = 3000;
//Serve static assets (js, css, ...)
app.use(express.static('app'));
//Serve contract artifact files (ex: ToDo.json)
app.use(express.static('build/contracts'));
//Serve index.html
app.get('/', (req, res) => {
res.sendFile(`${__dirname}/app/index.html`);
});
//If anything else is requested that's an error
app.get('*', (req, res) => {
res.status(404);
res.send('Oops... this URL does not exist');
});
//Start the server
app.listen(PORT, () => {
console.log(`ETB Ethereum ToDo List App running on port ${PORT}...`);
});
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...