Code Monkey home page Code Monkey logo

Comments (7)

vgjtsy avatar vgjtsy commented on July 28, 2024 2

Here is the software-solution of the problem
The software realized: Paymaster approve and swaps to Syncswap, Mute.io, Velocore.

https://github.com/Elez-dev/ZksyncPaymaster

from zksync2-python.

Elez-dev avatar Elez-dev commented on July 28, 2024 1

I am trying to approve the USDC token(0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4) on syncswap but I encounter an error when calculating gas:
raise ContractLogicError(message, data=data)
web3.exceptions.ContractLogicError: failed pre-paymaster preparation. error message: Unsupported paymaster flow

what is the problem?

   account = Account.from_key(self.private_key)
    zk_web3 = ZkSyncBuilder.build('https://rpc.ankr.com/zksync_era')

    paymaster_params = PaymasterParams(**{
        "paymaster": Web3.to_checksum_address(hex(1385176238538084405112226988227972482942345053927)),
        "paymaster_input": b'0x949431dc0000000000000000000000003355df6d4c9c3035724fd0e3914de96a5a83aaf4ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001'
    })

    tx_func_call = TxFunctionCall(
        chain_id=zk_web3.zksync.chain_id,
        nonce=zk_web3.zksync.get_transaction_count(self.address_wallet),
        from_=account.address,
        to=Web3.to_checksum_address('0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4'),
        data=HexStr("0x095ea7b30000000000000000000000009b5def958d0f3b6955cbea4d5b7809b2fb26b059ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
        gas_limit=0,  # Unknown at this state, estimation is done in next step
        gas_price=self.web3.eth.gas_price,
        max_priority_fee_per_gas=100_000_000,
        paymaster_params=paymaster_params
    )

    estimate_gas = zk_web3.zksync.eth_estimate_gas(tx_func_call.tx)

    tx_712 = tx_func_call.tx712(estimate_gas)
    signer = PrivateKeyEthSigner(account, 324)
    signed_message = signer.sign_typed_data(tx_712.to_eip712_struct())
    msg = tx_712.encode(signed_message)
    tx_hash = zk_web3.zksync.send_raw_transaction(msg)

image

"to": "293073555886263999399931999154716245840435063540",
"gasLimit": "2500000",
"gasPerPubdataByteLimit": "50000",
"maxFeePerGas": "100000000",
"maxPriorityFeePerGas": "100000000",
"paymaster": "1385176238538084405112226988227972482942345053927",
"nonce": "93",
"value": "0",
"data": "0x095ea7b30000000000000000000000009b5def958d0f3b6955cbea4d5b7809b2fb26b059ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"factoryDeps": [],
"paymasterInput": "0x949431dc0000000000000000000000003355df6d4c9c3035724fd0e3914de96a5a83aaf4ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001"
}

from zksync2-python.

petarTxFusion avatar petarTxFusion commented on July 28, 2024

You could use Transaction712 class to create your transaction or you could use for example TxFunctionCall to generate object of type Transaction712 using method tx712(). Method to_eip712_struct() in class Transaction712 will return Transaction with 113 type. Using sign_typed_data and encoding signed message you can send your transaction using send_raw_transaction. Here is the example:

        provider_l2 = ZkSyncBuilder.build("http://127.0.0.1:3050")
        account :LocalAccount = Account.from_key(HexStr("0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"))
        transaction = TxFunctionCall(
            from_=account.address,
            to=HexStr("0xa61464658AfeAf65CccaaFD3a512b69A83B77618"),
            value=1,
            chain_id=provider_l2.zksync.chain_id,
            nonce=provider_l2.zksync.get_transaction_count(account.address),
            gas_price=provider_l2.zksync.gas_price
        )
        tx_712 = transaction.tx712(
            provider_l2.zksync.zks_estimate_gas_transfer(transaction.tx)
        )
        signer = PrivateKeyEthSigner(account, provider_l2.zksync.chain_id)
        signed_message = signer.sign_typed_data(tx_712.to_eip712_struct())

        msg = tx_712.encode(signed_message)
        tx_hash = provider_l2.zksync.send_raw_transaction(msg)
        transaction_receipt = provider_l2.zksync.wait_for_transaction_receipt(
            tx_hash, timeout=240, poll_latency=0.5
        )
        print(transaction_receipt)

If you need any additional help just let us know.

from zksync2-python.

petarTxFusion avatar petarTxFusion commented on July 28, 2024

Sorry for delayed response. Could you also share how you encode data for the transaction and paymaster params?

from zksync2-python.

petarTxFusion avatar petarTxFusion commented on July 28, 2024

We have a similar topic opened and answered on our discussions. Could you check this out link

from zksync2-python.

Toby1nik avatar Toby1nik commented on July 28, 2024

"Failed to serialize transaction: transaction type is not supported" maybe some one know problem need a special rpc if i wand send_raw_transacrion or i must do it only with zksync-sdk?

from zksync2-python.

petarTxFusion avatar petarTxFusion commented on July 28, 2024

"Failed to serialize transaction: transaction type is not supported" maybe some one know problem need a special rpc if i wand send_raw_transacrion or i must do it only with zksync-sdk?

If you could share a bit more information which type of transaction are you trying to send or if you can share your code that would be even better. If you want you can open separate issue. Also here are some python examples, in the paymaster example you can see how can you build transaction manually and send it as raw

from zksync2-python.

Related Issues (20)

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.