Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Wallet receive eth & token but can't send #189

Open
Kotomanga opened this issue Feb 28, 2018 · 2 comments
Open

New Wallet receive eth & token but can't send #189

Kotomanga opened this issue Feb 28, 2018 · 2 comments

Comments

@Kotomanga
Copy link

Hello,

i made some experimentations with ethereum & smart contract on Ganache(testRpc). Every thing works corectly, i can create token, send ether ... now i want to create a wallet (on demand) to work with my contract. the wallet can receive ether & token, when a call the balance of thisnew wallet it's return sorme value.

But wen i try to send ether or token from my new generated wallet, i had a json RPC error

{ "error": "Invalid JSON RPC response: {\"id\":3,\"jsonrpc\":\"2.0\"}" }

this my code for sending transaction, i use ethereumjs-tx

        const privateKeyBuff = Buffer.from(privateKey, 'hex');
        const rawTx = {
          nonce: web3.toHex(web3.eth.getTransactionCount(web3.eth.coinbase)),
          from: callerAddress,
          to: contractAddress,
          gasPrice: gasPrice.toString(10),
          gasLimit: gasLimit, // default gas limit to send ether
          chainId: config.eth.chain_id,
          data: methodRef,
        };


        const tx = new Tx(rawTx);
      
        if (gasLimit === 'auto') {
          console.log('Auto calculating gas limit...');
          gasLimit = web3.eth.estimateGas(rawTx);
          console.log('Estimated gas: ' + gasLimit);
          tx.gasLimit = gasLimit;
        }

        tx.sign(privateKeyBuff);

        const serializedTx = tx.serialize();

        web3.eth.sendRawTransaction(
          '0x' + serializedTx.toString('hex'),
          (error, txHash) => {
            if (error) return reject(error);

            result.tx_hash = txHash;

            return resolve(result);
          }
        );
@Grashias
Copy link

Hi convert each parameters to hex in the const rawTx and then try signing the eaw transaction, it will work.

@barrard
Copy link

barrard commented May 25, 2018

web3.toHex() < version 1.0

web3.utils.toHex() >= version 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants