Giter Club home page Giter Club logo

Comments (10)

paulmillr avatar paulmillr commented on June 7, 2024

tx .raw.chainId = numberTo0xHex(1337); is incorrect/unsupported way of changing chainId. The correct way is specifying chainId when creating new Transaction. But since you are passing hex string, it's not an option I guess.

from micro-eth-signer.

siquylee avatar siquylee commented on June 7, 2024

Thank you very much for quick response. I tried the following code but the chainId is stil 0x01.

async function testHex() {
    let pk = "8c6b19592316688fd537f726db8f2c2237af5cd1a0eb634efdb4bc3c3677f693";
    const ethTx = new Transaction({
        chainId: 1337,
        to: "0x8bac311a9fb1fc90c4ab8cee1c8437087169849a",
        gasLimit: 21000,
        gasPrice: 21000,
        value: BigInt(6000000000000000000),
        nonce: 10
    });

    let signedTx = await ethTx.sign(pk, false);
    let hex = signedTx.hex;
    console.log(hex);
   // Restore the transaction from the hex value
    let restoredTx = new Transaction(hex);
    console.log(restoredTx.raw.chainId);
}

Did I set chainId correctly ?

from micro-eth-signer.

paulmillr avatar paulmillr commented on June 7, 2024

You are using gasPrice, I think that makes library think you are using legacy type transaction.

If you want to use gasPrice instead of new fields, maybe pass chain name through second argument (mainnet by default).

from micro-eth-signer.

siquylee avatar siquylee commented on June 7, 2024

Great, it works. Thank you very much for your hep.

from micro-eth-signer.

paulmillr avatar paulmillr commented on June 7, 2024

I recommend using new tx type with maxFeePerGas, and maxPriorityFeePerGas, but that may not be possible with your network?

So if you use maxFeePerGas, you can pass chainId. If you use gasPrice, you should pass network name as a second argument. We map network name to chainId through some process, so maybe take a look at the code - maybe you will need to modify micro eth code to add 1337

from micro-eth-signer.

siquylee avatar siquylee commented on June 7, 2024

Honestly I'm new to Ethereum & cryptography. I'm using your library to build an a blockchain education app. I start using new tx type with maxFeePerGas, and maxPriorityFeePerGas and it works fine. I have one more question. Could micro-eth-signer decode the legacy raw transaction to get the sender?

from micro-eth-signer.

paulmillr avatar paulmillr commented on June 7, 2024

Yes

from micro-eth-signer.

siquylee avatar siquylee commented on June 7, 2024

I appreciate your help much. Is this the correct way to get sender from a legacy ETH transaction.

let hex = "0xf86e8083023e3883023e38941b4e1bb8ef8c474f4d0006fb6b69e969f4042f3a890d8d726b7177a8000080820a96a0ece7c1db9395de2dab9b724809d5b1c7947c6630eee76e8c40a88eac5930d0c7a01804147852ec93bab9acb7de52c35e6e6a72052d7bc1319f7b8a37f078aa4c79";
let tx = new Transaction(hex);
console.log(tx.sender);

It's a transaction sent from Brave wallet. The correct sender/from field is 0xe3aced781d71a65226c4fbd6140a2b0253ce4e32. When I tried to decode the sender field with your library, it threw an error Cannot recover signature: invalid recovery bit

from micro-eth-signer.

paulmillr avatar paulmillr commented on June 7, 2024

You've forgot to pass chainId. It is used in recovering sender lubkey.

from micro-eth-signer.

siquylee avatar siquylee commented on June 7, 2024

I got it. Thank you so much

from micro-eth-signer.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.