pchain-org / pchain

Pchain client-in-Go
https://plian.org
GNU General Public License v3.0
24 stars 12 forks source link

Cannot send tx: "Status: Pending" #35

Closed galbraithd closed 5 years ago

galbraithd commented 5 years ago

Code:

var Web3 = require("pweb3");
var web3 = new Web3();
web3 = new Web3(new Web3.providers.HttpProvider("http://54.68.240.52:6969/pchain"));

const PchainTx = require('pchainjs-tx');
const privateKey = Buffer.from('f0bedd21a93d5f7a97407c187c684d338e8c4c00cccf5e8fafa94d920454e4b1', 'hex');

const txParams = {
  nonce: '0x35',
  gasPrice: '0x2540BE400', 
  gasLimit: '0x61A8',
  to: '0xe2f396e3485df644626174ea31ab0cbc54335e6d',
  value: '0x38D7EA4C68000', 
  data: '0x11',
  // mainChain :"pchain",childChain 1 :"child_0"
  chainId: "pchain"
};

const tx = new PchainTx(txParams);
tx.sign(privateKey);
console.log( tx.sign(privateKey) );
const serializedTx = tx.serialize();

//console.log(serializedTx.toString('hex'));
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
 if (!err);
  console.log(hash); 
 else
   console.log(err);
});

Get hash, as a result: https://testnet.pchain.org/index.html?key=0x03bc400085c49e068e1226def1e183c01d5c447ee0363f82b5f4fd478ac2a3ba&chain=0

But tx status Pending. permanently

Similar tx with the same inputs made through the website https://testnet.pchain.org/index.html?key=0x5401309730dfc7aba3450e297adca8c11dee4851d60bc2522eee10a694ed8750&chain=0

galbraithd commented 5 years ago

image

galbraithd commented 5 years ago

I've launched own node, tried again and got same result:

> web3.eth.getBalance("0xf55a3614609d0197ded83378ed5ccc6a181bb8af")
60000000000000000
> web3.personal.unlockAccount("0xf55a3614609d0197ded83378ed5ccc6a181bb8af")
Unlock account 0xf55a3614609d0197ded83378ed5ccc6a181bb8af
Passphrase:
true
> web3.eth.sendTransaction({nonce: '0x68',   gasPrice: web3.toWei(5, "gwei"),   gas: '0x61A8',   from: '0xf55a3614609d0197ded83378ed5ccc6a181bb8af',   to: '0xe90ec675dad07929232740b74391e3021562910c',   value: web3.toWei(0.001, "ether"),   data: '0x',   chainId: 'pchain'})
"0xe6e2fb55a94081f960741bf244f627d578d4e6e4180a2d96d1ccbf05fea1113e"
> web3.eth.getTransaction("0xe6e2fb55a94081f960741bf244f627d578d4e6e4180a2d96d1ccbf05fea1113e")
{
  blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  blockNumber: null,
  from: "0xf55a3614609d0197ded83378ed5ccc6a181bb8af",
  gas: 25000,
  gasPrice: 5000000000,
  hash: "0xe6e2fb55a94081f960741bf244f627d578d4e6e4180a2d96d1ccbf05fea1113e",
  input: "0x",
  nonce: 104,
  r: "0xe85b3cd19871754746f39d80234b0b528bde15fcf9ed7eafac2d3a8b664e6e17",
  s: "0x214e742563ff7e27646ff42898263fd5b31aafb1f15f9f2cfa9598d9eddef308",
  to: "0xe90ec675dad07929232740b74391e3021562910c",
  transactionIndex: 0,
  v: "0x6ad51b06ee7e3e3cd86ef37774b179dbd37ceecd6e38400fa884d8260c5d9c46",
  value: 1000000000000000
}
skykingit commented 5 years ago

you should check your latest nonce in the transaction. use the API as below: https://github.com/pchain-org/pweb3/wiki/JavaScript-API#web3ethgettransactioncount. The transaction was executed in the nonce's sequence.

galbraithd commented 5 years ago

Thanks a lot. Solved.

I had to use getNonce or import private key to web wallet and get nonce from there. In my case address was new, so i've used nonce: 0