0

This is my Javascript code. I keep getting an error that states

Error: No privateKey given to the TransactionSigner. at TransactionSigner._callee$ (/Users/payton/WebstormProjects/Esgro_DAPP/node_modules/web3-eth/dist/web3-eth.cjs.js:53:23) at tryCatch (/Users/payton/WebstormProjects/Esgro_DAPP/node_modules/regenerator-runtime/runtime.js:45:40) at Generator.invoke [as _invoke] (/Users/payton/WebstormProjects/Esgro_DAPP/node_modules/regenerator-runtime/runtime.js:271:22) at Generator.prototype. [as next] (/Users/payton/WebstormProjects/Esgro_DAPP/node_modules/regenerator-runtime/runtime.js:97:21)

I am using node 12.1.0 & web3^1.0.0-beta.55

 const contract = new web3.eth.Contract(_ABI);

   web3.eth.accounts.wallet.add({
        address:_publicKey,
        privateKey: _privateKey.toString()
    });
    const contract_Instance = await contract.deploy({
        data: _bytecode,
        arguments: _constructor_args})
        .send({
        from: _adminAddress,
        gas: 1500000,
        gasPrice: '20000000000'
    });

What am I doing wrong here?

  • Same question as this one, which you posted earlier. Please don't spam this facility with multiple questions that look the same. – goodvibration May 24 at 16:30
  • The one I posted earlier had the wrong title & I was worried that it would not be addressed. Thank you for being diligent. – pjonson2 May 24 at 16:39
0

With web3 v1.0.0-beta.34, you can use this:

async function deploy(contractName, contractArgs) {
    const abi = fs.readFileSync(YOUR_ARTIFACTS_PATH + contractName + ".abi");
    const bin = fs.readFileSync(YOUR_ARTIFACTS_PATH + contractName + ".bin");
    const contract = new web3.eth.Contract(JSON.parse(abi));
    const options = {data: "0x" + bin, arguments: contractArgs};
    const transaction = contract.deploy(options);
    const handle = await send(transaction);
    const args = transaction.encodeABI().slice(options.data.length);
    return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
}

async function send(transaction) {
    const options = {
        to   : transaction._parent._address,
        data : transaction.encodeABI(),
        gas  : (await util.web3.eth.getBlock("latest")).gasLimit
    };
    const signedTransaction  = await web3.eth.accounts.signTransaction(options, YOUR_PRIVATE_KEY);
    const transactionReceipt = await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
    return transactionReceipt;
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.