NEWTON
Asked
3 months ago
12
views
0
How do I create OZ (Open Zeppelin) contract using starknetjs?
Newton
asked
3 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
3 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?
How to deploy a contract through starknet.py?
Cairo error "Expected expression of type 'starkware.cairo.common.uint256.Uint256' to have an address."
Has anyone had `get_caller_address` problems in devnet ?
What is an abstract account? For example: StarkNet Account Abstraction
What do I have as the result of a Cairo contract in JavaScript?
What does this error means? (AssertionError: assert_not_zero failed: 0 = 0.)
how to send token