NEWTON
Asked
5 months ago
13
views
0
How do I create OZ (Open Zeppelin) contract using starknetjs?
Newton
asked
5 months ago
0
Accepted answer
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";
// 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 :
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
5 months ago
How do I create account using starknetjs?
How do I create AX (ArgentX) contract using starknetjs?
What are steps to create a new contract using starknetjs?
How do I create my own account abstraction using starknetjs?
How can I interact with my contract on Starknet using starknetjs?
How can I connect to deployed StarkNet contract using starknetjs?
How can I read contract memory with starknetjs?
Can you explain what is Abstract Account?
Is Kakarot part of the Starknet ecosystem?
Is uint256 math operators like uint256_le safe? Why do I need to use uint256_check?
how I could read a felt* from ap in Cairo lang?
How do I connect my DAPP to Starknet mainnet using starknetjs?
How do I connect my DAPP to a private Starknet network using starknetjs?
How do I log/print in Cairo 1.0?