NEWTON
Asked
3 months ago
2
views
0
How do I create AX (ArgentX) contract using starknetjs?
Newton
asked
3 months ago
0
Accepted answer
Here, we will create a wallet with the ArgentX smart-contract v0.2.3. This case is more complicated because we will have the wallet behind a proxy contract (in this way, the wallet contract can be updated). The contract classes of both contracts are already implemented in both Testnet 1 & 2.
If necessary OZ contracts can also be created with a proxy.
import { Account, ec, json, stark, Provider, hash } from "starknet";
// connect provider const provider = new Provider({ sequencer: { network: "goerli-alpha" } }); //new Argent X account v0.2.3 : const argentXproxyClassHash = "0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918"; const argentXaccountClassHash = "0x033434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2"; // Generate public and private key pair. const privateKeyAX = stark.randomAddress(); console.log('AX_ACCOUNT_PRIVATE_KEY=', privateKeyAX); const starkKeyPairAX = ec.getKeyPair(privateKeyAX); const starkKeyPubAX = ec.getStarkKey(starkKeyPairAX); console.log('AX_ACCOUNT_PUBLIC_KEY=', starkKeyPubAX); // Calculate the future address of the ArgentX account const AXproxyConstructorCallData = stark.compileCalldata({ implementation: argentXaccountClassHash, selector: hash.getSelectorFromName("initialize"), calldata: stark.compileCalldata({ signer: starkKeyPubAX, guardian: "0" }), }); const AXcontractAddress = hash.calculateContractAddressFromHash( starkKeyPubAX, argentXproxyClassHash, AXproxyConstructorCallData, 0 ); console.log('Precalculated account address=', AXcontractAddress);
If you want a specific private key, replace stark.randomAddress()
by your choice.Then you have to fund this address.
If you have sent enough funds to this new address, you can go forward to the final step :
const accountAX = new Account(provider, AXcontractAddress, starkKeyPairAX); const deployAccountPayload = { classHash: argentXproxyClassHash, constructorCalldata: AXproxyConstructorCallData, contractAddress: AXcontractAddress, addressSalt: starkKeyPubAX }; const { transaction_hash: AXdAth, contract_address: AXcontractFinalAdress } = await accountAX.deployAccount(deployAccountPayload); console.log('✅ ArgentX wallet deployed at :',AXcontractFinalAdress);
Newton
answered
3 months ago
How do I create account using starknetjs?
What are steps to create a new contract using starknetjs?
How do I create my own account abstraction using starknetjs?
How do I create OZ (Open Zeppelin) contract using starknetjs?
How can I interact with my contract on Starknet using starknetjs?
How can I connect to deployed StarkNet contract using starknetjs?
What is ArgentX?
How do I connect my DAPP to a Starknet node using starknetjs?
What are multi-calls in Account Abstraction? What will it bring to the UX?
Have there been any security issues reported on the Cairo code generated from warp so far?
How to use Argent (or any from the main providers) account in the StarkNet.py?
Why abi of warp compiled contract does not match original solidity abi?
How do I create my own account abstraction using starknetjs?
Can I transpile any solidity version?