Я учусь писать умные контракты, используя основательность. При запуске этих кодов используется трюфель (ганаш):
Helloworld.sol
pragma solidity 0.5.12;
contract Helloworld {
string message = "Hello World";
function getMessage() public view returns (string memory) {
return message;
}
function setMessage(string memory newMessage) public payable {
message = newMessage;
}
}
Helloworld_migration. js
const Helloworld = artifacts.require("Helloworld");
module.exports = function(deployer, network, accounts){
deployer.deploy(Helloworld).then(function(instance){
instance.setMessage("Hello Again!", {value: 1000000, from: accounts[0]}).then(function(){
console.log("Success");
}).catch(function(err){
console.log("error: " + err);
});
}).catch(function(err){
console.log("Deploy failed " + err);
});
};
Helloworldtest. js
const Helloworld = artifacts().require("Helloworld");
contract("Helloworld", async function(){
it("should initialize correctly", async function(){
let instance = await Helloworld.deployed();
let message = await instance.getMessage();
assert(message === "Hello Again!");
});
});
Я получил эту ошибку msg:
TypeError: artifacts is not a function
at Object.<anonymous> (/Users/cherrybluemoon/projects/test/Helloworldtest.js:1:20)
at Module._compile (internal/modules/cjs/loader.js:1123:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:972:32)
at Function.Module._load (internal/modules/cjs/loader.js:872:14)
at Module.require (internal/modules/cjs/loader.js:1012:19)
at require (internal/modules/cjs/helpers.js:72:18)
at /usr/local/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:231:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles
(/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:228:14)
at Mocha.run
(/usr/local/lib/node_modules/truffle/node_modules/mocha/lib/mocha.js:536:10)
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-
core/lib/test.js:135:1
at processTicksAndRejections (internal/process/task_queues.js:97:5)