Skip to content

Instantly share code, notes, and snippets.

@mmagician
Created March 11, 2021 18:06
Show Gist options
  • Save mmagician/c0347c370a9adbf323c0248b0feb93e3 to your computer and use it in GitHub Desktop.
Save mmagician/c0347c370a9adbf323c0248b0feb93e3 to your computer and use it in GitHub Desktop.
zkSync tutorial
from web3 import Web3, HTTPProvider, Account
from zksync_sdk import ZkSyncProviderV01, HttpJsonRPCTransport, network, ZkSync, EthereumProvider, Wallet, ZkSyncSigner, EthereumSignerWeb3, ZkSyncLibrary
import asyncio
from zksync_sdk.types import ChainId
from dataclasses import dataclass
@dataclass
class Network:
zksync_url: str
chain_id: ChainId
async def main():
# Load crypto library
library = ZkSyncLibrary()
# Create Zksync Provider
# Had to change to http, see the PR: https://github.com/zksync-sdk/zksync-python/pull/7
my_network = Network(zksync_url="http://localhost:3030/jsrpc", chain_id=ChainId.LOCALHOST)
provider = ZkSyncProviderV01(provider=HttpJsonRPCTransport(network=my_network))
# Setup web3 account
account = Account.from_key("my key here")
# Create EthereumSigner
ethereum_signer = EthereumSignerWeb3(account=account)
# Load contract addresses from server
contracts = await provider.get_contract_address()
# # Setup web3
w3 = Web3(HTTPProvider(endpoint_uri="http://localhost:30303"))
# # # Setup zksync contract interactor
zksync = ZkSync(account=account, web3=w3,
zksync_contract_address=contracts.main_contract)
# # Create ethereum provider for interacting with ethereum node
ethereum_provider = EthereumProvider(w3, zksync)
# Initialize zksync signer, all creating options were described earlier
signer = ZkSyncSigner.from_account(account, library, my_network.chain_id)
# Initialize Wallet
wallet = Wallet(ethereum_provider=ethereum_provider, zk_signer=signer,
eth_signer=ethereum_signer, provider=provider)
if __name__ == "__main__":
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment