I am unsure of what I am doing wrong, I followed the example on https://github.com/ethereum/wiki/wiki/JavaScript-API Trying to creat new contract.

I keep getting the error:web3j err: Error: unknown account

Here is the function I am trying to run:

var deployNewContract = function(contractName){
    fs.readFile(contractDefaultPath + contractName + '.sol', 'utf8', function(err, contractCode) {
        if(err) console.log("error: " + err);
        let compiledContract = solc.compile(contractCode, 1);
        for (var contractName in compiledContract.contracts) {
            let abi = compiledContract.contracts[contractName].interface;
            let bytecode = compiledContract.contracts[contractName].bytecode;
            let gasEstimate = web3.eth.estimateGas({data: "0x" + bytecode});
            let MyContract = web3.eth.contract(JSON.parse(abi));
            var myContractReturned = MyContract.new("0x0",{
                data:"0x" + bytecode,
                gas:gasEstimate}, function(err, myContract){
                if(!err) {
                    // NOTE: The callback will fire twice!
                    // Once the contract has the transactionHash property set and once its deployed on an address.

                    // e.g. check tx hash on the first call (transaction send)
                    if(!myContract.address) {
                        console.log(myContract.transactionHash) // The hash of the transaction, which deploys the contract
                        // check address on the second call (contract deployed)
                    } else {
                        console.log(myContract.address) // the contract address
                    // Note that the returned "myContractReturned" === "myContract",
                    // so the returned "myContractReturned" object will also get the address set.
                    console.log("web3j err: " + err);
module.exports.deployNewContract = deployNewContract;

I run on a private consortium on AZURE, I have double checked my wallet address, and it is correct, I can see the balance using metamask.

  • Can you pass the address instead of variable and check if it is working.. instead of from:wallet change from:<address of account>. – Abhishek Aug 13 '17 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.