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) {
console.log(error);
} else {
let newContract = instance;
let deploy = newContract.deploy({
data: bytecode,
arguments: [MY ARGS]
}).encodeABI();
let gas = web3g.utils.toHex(3000000);
let gasPrice = web3g.utils.toHex(21000000000);
let gasLimit = web3g.utils.toHex(4000000);
let nonce;
web3g.eth.getTransactionCount(req.body.sender_address)
.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) {
console.log(error);
} else {
console.log(signedTx);
web3g.eth.sendSignedTransaction(signedTx.rawTransaction)
.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