NEWTON

NEWTON


Popular tags

    How do I create my own account abstraction using starknetjs?

    Asked

    23 days ago

    3

    views


    0

    How do I create my own account abstraction using starknetjs?

      starknetjscairostarknetaccount abstraction

    Newton

    asked

    23 days ago


    1 answers

    0

    Accepted answer

    Create your account abstraction :

    You are not limited to OZ or AX contracts; you can create your own contract for your wallet. It's the concept of Account Abstraction. You can customize entirely the wallet; for example :

    • use a different concept of keys.
    • Add a guardian to save your account.
    • have the possibility to transfer ownership of the wallet.
    • Add some administrators or a super-administrator.
    • Whitelist of address for transfer.
    • Multisig

    The only limitation is your imagination...Here is an example of a customized wallet, including super administrator management, on a local starknet-devnet (launch starknet-devnet --seed 0 before using this script) :

    import { Account, ec, json, stark, Provider, hash } from "starknet"; import axios from "axios";

    and:

    // connect provider const provider = new Provider({ sequencer: { network: "http://127.0.0.1:5050" } }); // initialize existing predeployed account 0 of Devnet const privateKey0 = "0xe3e70682c2094cac629f6fbed82c07cd"; const starkKeyPair0 = ec.getKeyPair(privateKey0); const accountAddress0 = "0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a"; const account0 = new Account(provider, accountAddress0, starkKeyPair0); // new account abstraction : // Generate public and private key pair. const AAprivateKey = stark.randomAddress(); console.log('New account :\nprivateKey=', AAprivateKey); const AAstarkKeyPair = ec.getKeyPair(AAprivateKey); const AAstarkKeyPub = ec.getStarkKey(AAstarkKeyPair); console.log('publicKey=', AAstarkKeyPub); // declare the contract const compiledAAaccount = json.parse(fs.readFileSync("./compiled_contracts/myAccountAbstraction.json").toString("ascii") const AAaccountClashHass = "0x5139780c7ec8246e21a22e49f4fa0ce430237df4a4b241214a3a5a5c120120d"; const { transaction_hash: declTH, class_hash: decCH } = await account0.declare({ classHash: AAaccountClashHass, contract: compiledAAaccount }); console.log('Customized account class hash =', decCH); await provider.waitForTransaction(declTH); // Calculate future address of the account const AAaccountConstructorCallData = stark.compileCalldata({ super_admin_address: account0.address, publicKey: AAstarkKeyPub }); const AAcontractAddress = hash.calculateContractAddressFromHash( AAstarkKeyPub, AAaccountClashHass, AAaccountConstructorCallData, 0 ); console.log('Precalculated account address=', AAcontractAddress); // fund account address before account creation const { data: answer } = await axios.post('http://127.0.0.1:5050/mint', { "address": AAcontractAddress, "amount": 50_000_000_000_000_000_000, "lite": true }, { headers: { "Content-Type": "application/json" } }); console.log('Answer mint =', answer); // deploy account const AAaccount = new Account(provider, AAcontractAddress, AAstarkKeyPair); const { transaction_hash, contract_address } = await AAaccount.deployAccount({ classHash: AAaccountClashHass, constructorCalldata: AAaccountConstructorCallData, addressSalt: AAstarkKeyPub }); await provider.waitForTransaction(transaction_hash); console.log('✅ New customized account created.\n address =', contract_address);

    Newton

    answered

    23 days ago

    Your answer

    NEWTON

    NEWTON