zksync-sdk / zksync2-go

zksync2-go is a geth library adapted to work with the zkSync Era.
Apache License 2.0
87 stars 36 forks source link

Provided example is not working any more #3

Closed elek closed 1 year ago

elek commented 1 year ago
       pkBytes, err := hex.DecodeString("REDACTED")
    if err != nil {
        panic(err)
    }

    // or from raw PrivateKey bytes
    ethereumSigner, err := zksync2.NewEthSignerFromRawPrivateKey(pkBytes, 280)
    if err != nil {
        panic(err)
    }
    fmt.Println(ethereumSigner.GetAddress().String())

    // also, init ZkSync Provider, specify ZkSync2 RPC URL (e.g. testnet)
    zkSyncProvider, err := zksync2.NewDefaultProvider("https://zksync2-testnet.zksync.dev")
    if err != nil {
        panic(err)
    }

    // then init Wallet, passing just created Ethereum Signer and ZkSync Provider
    wallet, err := zksync2.NewWallet(ethereumSigner, zkSyncProvider)
    if err != nil {
        panic(err)
    }

    b, err := wallet.GetBalance()
    if err != nil {
        panic(err)
    }

    fmt.Println(b)

    hash, err := wallet.Transfer(
        common.HexToAddress("4C466C61cf8cEEa6c7365f6F6490fcF765deC6cD"),
        big.NewInt(1),
        nil,
        nil,
    )
    if err != nil {
        panic(err)
    }
    fmt.Println("Tx hash", hash)

Prints out:

0xAfD2d8d18B2B7D1C1f35869Df4ab66BAeFc9A912
22000000000000000
panic: failed to call eth_sendRawTransaction: Failed to submit transaction: failed to validate the transaction. reason: Validation revert: Account validation error: Account validation returned invalid magic value. Most often this means that the signature is incorrect

As far as I remember it worked before an updated ~ near end of January / beginning of February...

VickMellon commented 1 year ago

Yes, there was general update of zkSync ecosystem, a few weeks ago, and we got many breaking changes. For now, we still working on updating all SDKs, to catch up current state and functionality, so it will take some more time. Sorry for inconvenience, you can try to use dev branch temporarily, but for your own risk.

elek commented 1 year ago

Thanks the answer.

I can wait, just tried to be sure that it's not my fault ;-)

Happy to help with testing dev branch...

egeaybars123 commented 1 year ago

Same happened to me. I guess we are going to wait for the updates.

elek commented 1 year ago

I started to use the dev branch and worked well (it can submit transaction)

But when I tried to call eth_getTransactionByHash I got transaction type not supported error. I think it's not zksync2-go specific as it seems to be a standard response for a good JSON-RPC call....

VickMellon commented 1 year ago

But when I tried to call eth_getTransactionByHash I got transaction type not supported error. I think it's not zksync2-go specific as it seems to be a standard response for a good JSON-RPC call....

You can't get some of Txs (and many other calls) on L2 (ZkSync network) using common go-ethereum library due to custom TxType of their EIP712 transactions. And go-ethereum library has strict validations on server replies.

Use zksync2.Provider implementation, like DefaultProvider and its method GetTransaction(txHash common.Hash) (*TransactionResponse, error) in this case.