Here’s the contract: @dan-i
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;
}
}
And here’s the deployment file:
const HelloWorld = artifacts.require("HelloWorld");
module.exports = function(deployer, network, accounts) { //First parameter is the deployer - used to deploy contract, second is network parameter - which network are we on, third is Ganache accounts array
deployer.deploy(HelloWorld).then(function(instance){ // instance here is the contract returned by deployer.deploy(HelloWorld) after it has deployed.
instance.setMessage("Hello Again!", {value: 1000000, from: accounts[0]}).then(function(){ // here we want to call getMessage only ofter setMessage changed the message.
instance.getMessage().then(function(message){ // Getmessage returns the message, so we can pass that to console.log
console.log("Current message: " + message)
});
});
});
};
Both are copied from filip’s code, so it’s strange that I’m getting an error where he wasn’t.
EDIT - I got something working by building on the code you posted and browsing Truffle documentation some more. This is what I have now:
const HelloWorld = artifacts.require("HelloWorld"); // This method returns a contract abstraction we can use in the rest of out script.
module.exports = async function (deployer, network, accounts) { //Can get access to accounts = await web3.eth.getAccounts() by specifying accounts parameter here
await deployer.deploy(HelloWorld)
const instance = await HelloWorld.deployed();
await instance.setMessage('YOYO222', {gas: 1000000, from: accounts[0]}); //Using "gas" here instead of "value", it fixed the problem!"
const result = await instance.getMessage();
console.log(result)
};
Using {gas: 1000000, from: accounts[0]} instead of {value: 1000000, from: accounts[0]} works, so I assume that the error has something to do with specifying the transaction value, but I’m not sure what exactly the problem is. Any ideas @dan-i?