Call to sendSignedTransaction return a promise that is fulfilled as soon as the transaction is settled.
sendSignedTransaction hangs forever.
Also, it seems from the logs that I'm stuck in a loop.
eth_sendRawTransaction
Transaction: 0x33244e50ce07f80112de5cb56bc64616d85078350ba9c8df0f883182a9580470
Gas usage: 21000
Block Number: 5
Block Time: Sun Apr 28 2019 17:37:47 GMT-0300 (GMT-03:00)
eth_getTransactionReceipt
eth_getBlockByNumber
eth_getTransactionReceipt
eth_getBlockByNumber
eth_getTransactionReceipt
eth_getBlockByNumber
eth_getTransactionReceipt
eth_getBlockByNumber
eth_getTransactionReceipt
eth_getBlockByNumber
eth_getTransactionReceipt
...
const Web3 = require('web3')
const EthTxn = require('ethereumjs-tx')
const web3 = new Web3('http://localhost:8545')
const { getBalance, sendSignedTransaction } = web3.eth
const sender = {
address: '...',
privateKey: '...',
}
const receiver = {
address: '...',
privateKey: '...',
}
;(async () => {
const rawTxn = {
nonce: 5,
to: receiver.address,
gasPrice: 20000000,
gasLimit: 30000,
value: 100,
data: '',
}
const senderPrivateKeyHex = Buffer.from(sender.privateKey, 'hex')
const txn = new EthTxn(rawTxn)
txn.sign(senderPrivateKeyHex)
const serializedTxn = txn.serialize()
await sendSignedTransaction(serializedTxn)
console.log('here') // <--- never executed
})()
Same here.
pragma solidity >=0.5.0 <0.6.0;
contract DigitalRights {
string data = "0x123123123";
string copyright = "bogdan";
string[] producers = ["prod1","prod2"];
string[] productionAssistance = ["as1","as2"];
string[] guests = ["guest1","guest2"];
string[] sponsors = ["Sponsor1","Sponsor2"];
}
const contract = new this.web3.eth.Contract(abi)
.deploy({ data: '0x' + bytecode })
.send({ from: owner, gas: this.gas })
.on('error', error => {
log(`error: ${error}`);
reject(error);
})
.on('transactionHash', transactionHash => {
log(`transactionHash: ${transactionHash}`);
})
.on('receipt', receipt => {
log(`receipt: ${receipt}`);
})
.on('confirmation', (confirmationNumber, receipt) => {
log(`confirmation: ${confirmationNumber} ${JSON.stringify(receipt)}`);
//gets 1 configmation
})
.then((newContract: Contract) => {
// never fulfilled
log(`successfully deployed at ${newContract.options.address}`);
resolve({
contract: newContract,
owner,
accounts,
});
});
Try setting https://web3js.readthedocs.io/en/1.0/web3-shh.html#transactionconfirmationblocks
and/or set fixed blocktime using -b 1 for ganache.
I had the same problem !
The reason is that Web3 will by default wait for 24 confirmations before resolving, but ganache-cli will only give you one, causing it to hang indefinitely.
The easiest solution is to change options for web3 to only require one confirmation:
const Web3 = require('web3')
const ganache = require('ganache-cli')
const web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 /* This is the critical part */ })
// ... send your transaction using web3
Thanks @bergkvist! If time permits, I would definitely encourage you to open a PR! Or, let me know and I'll make sure this lands in our documentation! :+1: :+1:
@nicholasjpaterno I might look into it in the end of next week! I won't have time until then.
Documentation fixed by: https://github.com/trufflesuite/ganache-cli/pull/656 Thanks everyone!
Most helpful comment
The reason is that Web3 will by default wait for 24 confirmations before resolving, but ganache-cli will only give you one, causing it to hang indefinitely.
The easiest solution is to change options for web3 to only require one confirmation: