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

web3.eth.signTransactions has different result to eth.account.signTransaction #1125

Closed
naddison36 opened this issue Oct 19, 2017 · 2 comments

Comments

@naddison36
Copy link
Contributor

naddison36 commented Oct 19, 2017

I can't get web3.eth.sendSignedTransaction to send locally signed transactions. I can successfully send transactions using web3.eth.sendTransaction, which signs the transaction on the remote node.

The first test in the below works which is using a connected geth 1.7.2 node to sign the transaction.
The second test fails which is signing the transaction locally using web3.eth.account.

describe("signed transaction from web3 1.0 documentation", ()=>
    {
        const web3: Web3 = new Web3("ws://localhost:8647");

        const tx = {
            from: '0x2c7536E3605D9C16a7a3D7b1898e529396a65c23',
            to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
            value: '1000000000',
            gas: 2000000,
            gasPrice: '234567897654321',
            nonce: 0,
            chainId: 1
        };

        const expectedRawTx = '0xf86a8086d55698372431831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca00801ca003e69c73809f9f72a3ce22d65d0d8a1e42df244da0ae23a921bb6758fac70e83a043518de58905fe940965ba9bfd305c0c29c00f44d2115e8baba3a5796403391a',
            expectedTxHash = '0xb11c3d4f1405df1e6cf14e091c533af12d397c062b9f25cc8827a2406f5b1a03';

        test("using web3.eth.signTransaction", async ()=>
        {
            expect.assertions(2);

            const result = await web3.eth.signTransaction(tx);

            expect(result.tx.hash).toEqual(expectedTxHash);
            expect(result.raw).toEqual(expectedRawTx);
        });

        test("using web3.eth.accounts.signTransaction", ()=>
        {
            const account = web3.eth.accounts.privateKeyToAccount('0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318');

            expect(account.address).toEqual('0x2c7536E3605D9C16a7a3D7b1898e529396a65c23');

            const result = account.signTransaction(tx);

            expect(result.messageHash).toEqual(expectedTxHash);
            expect(result.rawTransaction).toEqual(expectedRawTx);
        });
    });

The above tests are based off the example in the web3 1.0 documentation
http://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#id6

I was hoping the following PR in 1.0.0-beta.24 would fix the problem but it hasn't
#1111

@frozeman
Copy link
Contributor

Hm. i just send yesterday a transaction which i locally signed, which used sendSignedTransaction under the hood and it went through. Can you do some more tests manually?

The result could be different as the signing changed, it might be that signTx on the geth node still returns the old signature type. If you test using the node and the tx goes through the signature is correct.

@naddison36
Copy link
Contributor Author

You are right, Geth will send the transaction. I used the following test against a new dev instance of Geth so the nonce of 0x2c7536E3605D9C16a7a3D7b1898e529396a65c23 was 0.

describe("signed transaction from web3 1.0 documentation", ()=>
    {
        const web3: Web3 = new Web3("ws://localhost:8647");

        const tx = {
            from: '0x2c7536E3605D9C16a7a3D7b1898e529396a65c23',
            to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
            value: '1000000000',
            gas: 2000000,
            gasPrice: '234567897654321',
            nonce: 0,
            chainId: 1
        };

        const expectedRawTx = '0xf86a8086d55698372431831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca00801ca003e69c73809f9f72a3ce22d65d0d8a1e42df244da0ae23a921bb6758fac70e83a043518de58905fe940965ba9bfd305c0c29c00f44d2115e8baba3a5796403391a',
            expectedTxHash = '0xb11c3d4f1405df1e6cf14e091c533af12d397c062b9f25cc8827a2406f5b1a03';

        test("send web3.eth.sendSignedTransaction", async ()=>
        {
            expect.assertions(3);

            await web3.eth.sendSignedTransaction(expectedRawTx)
            .on('receipt', (receipt: object) =>
            {
                console.log(JSON.stringify(receipt));
                expect(isObject(receipt)).toBeTruthy();
                expect(receipt.transactionHash).toEqual(expectedTxHash);
                expect(receipt.blockNumber).toBeGreaterThanOrEqual(0);
            });
        }, 30000);
    });

I'm closing as I only care that Geth will send transactions signed by web3.eth.account.signTransaction. I don't care that the hashes don't match.

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

2 participants