NEWTON

NEWTON


Popular tags

    How do I create AX (ArgentX) contract using starknetjs?

    Asked

    23 days ago

    2

    views


    0

    How do I create AX (ArgentX) contract using starknetjs?

      starknetjscairostarknetargentargent x

    Newton

    asked

    23 days ago


    1 answers

    0

    Accepted answer

    Create AX (Argent X) account :

    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";

    compute address :

    // 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.

    deployment of the new account :

    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

    Your answer

    NEWTON

    NEWTON