NEWTON
Asked
23 days ago
2
views
0
How do I create AX (ArgentX) contract using starknetjs?
Newton
asked
23 days 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
23 days 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?
What resources are required to run a Pathfinder node?
How to get the block hash in Cairo lang?
Nethermind's warp error: JavaScript heap out of memory
How to make math operation with Field Elements (felts) in Cairo lang?
What does ret do in Cairo?
An error “AssertionError: Sender must be passed explicitly when making a direct declaration using —no_wallet.” using the new nile?
Can tempvar be of a different type, say U256?