Executing the Truffle console script:no such file or directory

Hi,
I am trying to execute the following script:

module.exports = (callback)=> {
  Message.setProvider(web3.currentProvider);
const MyContract = require("~/Truffle programs/script_transfer_Eth_thr_Truffle/contracts/MyContract");
const MyContractTester = artifacts.require("~/Truffle programs/script_transfer_Eth_thr_Truffle/contracts/MyContractTester");
var acc1 = accounts[1]
var acc2 = accounts[2]
const myC = await MyContract.deployed()
const myCT = await MyContractTester.deployed()
web3.eth.sendTransaction({to:myC.address, from:acc2, value: web3.utils.toWei('11')})
myC.sendTo(myCT.address, web3.utils.toWei('3',"ether"), {from:accounts[0]})
myCbal = await web3.eth.getBalance(myC.address)
web3.utils.fromWei(myCbal, "ether")

My script is located at:

zulfi@lc2530hz:~/Truffle programs/script_transfer_Eth_thr_Truffle$ pwd
/home/zulfi/Truffle programs/script_transfer_Eth_thr_Truffle
zulfi@lc2530hz:~/Truffle programs/script_transfer_Eth_thr_Truffle$ ls my*
myscript.js

When I am executing the script on the truffle console, I am getting the following error:

truffle(development)> truffle exec myscipt.js
Using network 'development'.

Error: ENOENT: no such file or directory, open '/home/zulfi/Truffle programs/script_transfer_Eth_thr_Truffle/myscipt.js'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:343:35)
    at Object.file (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/require/require.js:28:1)
    at Object.exec (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/require/require.js:121:1)
    at Promise (internal/util.js:274:30)
    at new Promise (<anonymous>)
    at bound exec (internal/util.js:273:12)
    at Object.run (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/exec.js:80:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)

truffle(development)> 

Somebody please guide me.

Zulfi.

I think it’s just a typo … Your script is called myscript.js , and you’re trying to run:
truffle(development)> truffle exec myscipt.js

I hope I helped you :slight_smile:

1 Like