I have the following code in a script name contract.js ( foo, pwd and id are replaced by their value in my actual script)
var web3=require('web3');
personal.unlockAccount('id', "pwd")
var aContract = web3.eth.contract([]);
var a = aContract.new(
{
from: web3.eth.accounts[1],
data: 'foo',
gas: 3000000
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
I wanted to execute this code in the geth console so I typed
loadScript("/usr/username/contract.js")
But all I have is the following error:
err: TypeError: Cannot access member 'contract' of undefined false
I know that I didn't define an ABI but when I type the code above directly in the geth console it just works and then I can mine this contract (in local).
So is it really possible to obtain the same result with loadscript ?