My goal is to send a signed transaction to create a smart contract, however, I am facing an issue I have not been able to solve for few days:

When I send the transaction (on a private chain), there are two different ending:

- 1 Web3js tells me it worked, I can see the transaction on the block. However, when trying to contact the contract, I have the following output:

Error: Couldn't decode uint256 from ABI: 0x

When I try to run eth.getCode(contractAddress) in Geth, it returns 0x

- 2 Web3js tells me that the transaction has not been mined for 50 blocks (the node did not have time to mine 50 blocks). But I can see the transaction in the block (in geth).

Here is the code I use:

web3g = result;
getContractInstance(function (error, instance) {
    if (error) {
    } else {
        let newContract = instance;
        let deploy = newContract.deploy({
            data: bytecode,
            arguments: [MY ARGS]
        let gas = web3g.utils.toHex(3000000);
        let gasPrice = web3g.utils.toHex(21000000000);
        let gasLimit = web3g.utils.toHex(4000000);
        let nonce;
            .then(function (result) {
                nonce = result;
                nonce = web3g.utils.toHex(nonce);
                let transactionObject = {
                    gas: gas,
                    gasPrice: gasPrice,
                    gasLimit: gasLimit,
                    data: deploy,
                    from: req.body.sender_address,
                    nonce: nonce

                web3g.eth.accounts.signTransaction(transactionObject, req.body.private_key, function (error, signedTx) {
                    if (error) {
                    } else {
                            .on('confirmation', function (number, receipt) {
                                if (number == 1) {
                                        // do stuff

Can someone point me out what I am doing wrong?

Note: I am able to send signed transaction using the method above to transfer ether between addresses.

Edit: Estimating gas returns the following: error: Returned error: gas required exceeds allowance or always failing transaction

1 Answer 1


I faced similar trouble in creating signed transactions and end up developing this package. https://www.npmjs.com/package/web3js-raw. Should solve your problem.

  • Thank you for your answer. however, using an non official library is not an option for me, as this is for professionnal purpose and you migth not keep updating your library. But could you explain what is the problem? Jan 15, 2018 at 10:12
  • You do not have to use the library, because the source code is available in public in git repo (github.com/fidenz-chim/web3js-raw). There are so many moving parts when you try to sign a transaction. All I have done is package web3.js functions in an easy to use manner to use in sendRawTransaction. If you are happy to share contract, I could deploy it and see what happens.
    – Chim
    Jan 15, 2018 at 10:16
  • I'll check it when I'll be able to. Will come back to you asap! Jan 15, 2018 at 10:18
  • Well, your solution seems to be quite good. Will try to implement it on my side. If too much difficulties, will fork it. Thank you! Jan 16, 2018 at 2:35
  • Using web3js ^0.17.0 does not allow me to connect to the node: ONNECTION ERROR: Couldn't connect to node. But it works fine with web3js ^1.0.0-beta.26. Sam =e on my own implementation or with yours Jan 16, 2018 at 6:23

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.