I want to exec a script in the truffle console.
script
const artifacts = require('./build/contracts/Message.json')
const contract = require('truffle-contract')
const Message = contract(artifacts);
Message.setProvider(web3.currentProvider);
module.exports = ()=> {
creator = web3.eth.accounts[0];
purchaser = web3.eth.accounts[1];
web3.personal.unlockAccount(creator);
var messageInstance = null;
Message.deployed().then(inst => { return messageInstance = inst}).then( () =>{ console.log("Creating Message"); return messageInstance.createMessage(creator, "message.newMessage") }).catch((error)=> { console.error("error", error) }).then( ()=> { return console.log("End");} )
}
Manually
When I manually insert the script (just the part inside module.exports), line by line it works and I get the last console.log
.
With exec
When I run exec ./run.js
: the script gets stuck at the second Promise without any error.
web3.eth.defaultAccount = web3.eth.accounts[0]
intruffle develop
beforehand? – Paul Razvan Berg Sep 8 '18 at 14:34module.exports
, and it should be used when you want a function to be used from a another file. If you just want to execute the body of the function then you do not need a function or assigning it tomodule.exports
, type the instruction directly in your file. – Ismael Sep 8 '18 at 19:33module.exports
is fine: truffleframework.com/docs/truffle/getting-started/… – Andi Giga Sep 10 '18 at 8:16Error: invalid address
error when calling the promise chain with exec. Which is usally the error for not having a default acount. Iconsole.log
the default account and it shows the right one on both solutions (beforehand & in the script). – Andi Giga Sep 10 '18 at 8:18