NEWTON

NEWTON


Popular tags

    How do I create OZ (Open Zeppelin) contract using starknetjs?

    Asked

    23 days ago

    9

    views


    0

    How do I create OZ (Open Zeppelin) contract using starknetjs?

      starknetjscairoopen-zepplinstarknetdeployment

    Newton

    asked

    23 days ago


    1 answers

    0

    Accepted answer

    Create OZ (Open Zeppelin) account :

    Here, we will create a wallet with the Open Zeppelin smart-contract v0.5.1. The contract class is already implemented in both Testnet 1 & 2.

    import { Account, ec, json, stark, Provider, hash } from "starknet";

    compute address :

    // connect provider const provider = new Provider({ sequencer: { network: "goerli-alpha" } }); // new Open Zeppelin account v0.5.1 : // Generate public and private key pairs. const privateKey = stark.randomAddress(); console.log('New OZ account :\nprivateKey=', privateKey); const starkKeyPair = ec.getKeyPair(privateKey); const starkKeyPub = ec.getStarkKey(starkKeyPair); console.log('publicKey=', starkKeyPub); const OZaccountClashHass = "0x2794ce20e5f2ff0d40e632cb53845b9f4e526ebd8471983f7dbd355b721d5a"; // Calculate the future address of the account const OZaccountConstructorCallData = stark.compileCalldata({ publicKey: starkKeyPub }); const OZcontractAddress = hash.calculateContractAddressFromHash( starkKeyPub, OZaccountClashHass, OZaccountConstructorCallData, 0 ); console.log('Precalculated account address=', OZcontractAddress);

    If you want a specific private key, replace stark.randomAddress() by your choice.

    Then you have to fund this address. How to proceed is out of the scope of this guide, by you can for example :

    • transfert ETH from an other wallet.
    • Bridge ETH to this Starknet address.
    • Use a faucet.
    • Mint ETH on starknet-devnet.

    deployment of the new account :

    If you have sent enough funds to this new address, you can go forward to the final step :

    const OZaccount = new Account(provider, OZcontractAddress, starkKeyPair); const { transaction_hash, contract_address } = await OZaccount.deployAccount({ classHash: OZaccountClashHass, constructorCalldata: OZaccountConstructorCallData, addressSalt: starkKeyPub }); await provider.waitForTransaction(transaction_hash); console.log('✅ New OpenZeppelin account created.\n address =', contract_address);

    Newton

    answered

    23 days ago

    Your answer

    NEWTON

    NEWTON