NEWTON
Asked
23 days ago
9
views
0
How do I create OZ (Open Zeppelin) contract using starknetjs?
Newton
asked
23 days 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
23 days 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?
Where can I find a list of decorators available in Cairo?
A plan to get better visibility when a transaction got received but not placed into a block?
Is there a way to search a block for events without using `get_transaction_receipt` for each transaction?
Any idea what this could be caused by?
What do I have as the result of a Cairo contract in JavaScript?
Cairo OR operator
What are events in Cairo Language?