starknet-io / starknet.js

JavaScript library for StarkNet
https://www.starknetjs.com
MIT License
1.22k stars 746 forks source link

Deploy Account Paying Fee By STRK #1099

Closed karasbuilder closed 6 months ago

karasbuilder commented 6 months ago

I have a function for deploy a account pay fee by STRK I follow the way to create a new inistall account to send V3 transaction

const accountAX = new Account(provider, address, decodePrivateKey, undefined,
        constants.TRANSACTION_VERSION.V3);

    const starkKeyPubAX = ec.starkCurve.getStarkKey(decodePrivateKey);

    // Calculate future address of the ArgentX account
    const AXConstructorCallData = CallData.compile({
        owner: starkKeyPubAX,
        guardian: '0',
    });

    const deployAccountPayload = {
        classHash: ARGENTX_HASH,
        constructorCalldata: AXConstructorCallData,
        contractAddress: address,
        addressSalt: starkKeyPubAX,
    };

    const estimateAccountDeployFee = await
        accountAX.estimateAccountDeployFee({
            classHash: ARGENTX_HASH, constructorCalldata: AXConstructorCallData
        })
    console.log('Max-Fee', estimateAccountDeployFee.suggestedMaxFee)
    const { transaction_hash: AXdAth, contract_address: AXcontractFinalAddress } =
        await accountAX.deployAccount(deployAccountPayload
            ,
            {
                version: 3,
                maxFee: estimateAccountDeployFee.suggestedMaxFee,
                resourceBounds: {
                    l1_gas: {
                        max_amount: num.toHex(estimateAccountDeployFee.suggestedMaxFee,),  // max quantity of gas authorized
                        max_price_per_unit: num.toHex(estimateAccountDeployFee.suggestedMaxFee,)
                    },
                    l2_gas: {
                        max_amount: num.toHex(0),
                        max_price_per_unit: num.toHex(0),
                    },
                },
            }
        );

    await provider.waitForTransaction(AXdAth);

So What I I'm Try to Do Right ? Here is My test account : https://sepolia.starkscan.co/contract/0x03cf04fac1f8f73c9eef908b50b93bff18e04e2bfb9576be76e763adf686656c#portfolio And It Return the error :

Screenshot 2024-04-24 at 16 18 07

--Setting Enviroment-- Starknet : V.6.7.0 Node: 18 RPC Testnet: https://starknet-sepolia.public.blastapi.io/rpc/v0_7

PhilippeR26 commented 6 months ago

Hello, Have you pre-funded with some STRK the future address of the account? You can take example of this code in my tuto : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/b943f985779d169fef1db517e2fbd5ff665fa451/src/scripts/Starknet13/Starknet13-devnet/1a.transactionV3.ts#L125-L173

karasbuilder commented 6 months ago

Hello, Have you pre-funded with some STRK the future address of the account? You can take example of this code in my tuto : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/b943f985779d169fef1db517e2fbd5ff665fa451/src/scripts/Starknet13/Starknet13-devnet/1a.transactionV3.ts#L125-L173

Thanks , but if i try to create argentX wallet or braavos .Can I code in different way ?

PhilippeR26 commented 6 months ago

Not sure to understand your question. To deploy a Braavos account is complicated. Reserved for experimented users. You can find in my tuto many account deployments (with V2 transaction). You have here an ArgentX deployment with tx V2 : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/3.createNewArgentXaccount.ts Just add constants.TRANSACTION_VERSION.V3 in the account instantiation.

karasbuilder commented 6 months ago

Not sure to understand your question. To deploy a Braavos account is complicated. Reserved for experimented users. You can find in my tuto many account deployments (with V2 transaction). You have here an ArgentX deployment with tx V2 : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/3.createNewArgentXaccount.ts Just add constants.TRANSACTION_VERSION.V3 in the account instantiation.

I mean .I'm build the follow to create a argentX wallet and deploy it in TestNest. It work well when I use the eth . All the information about it above , and then I change to pay fee by STRK . I also using declare account V3 like you before , but it alway Return the error Like This:

Screenshot 2024-04-24 at 20 38 38

I don't know , it look like I can not have enough strk but I have already funded that account :

Screenshot 2024-04-24 at 20 40 22
PhilippeR26 commented 6 months ago

I just added this example in my tuto : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/Starknet131/Starknet131-devnet/7.deployAXaccountV3.ts I run it with a devnet-rs fork, of my local Sepolia testnet node. Should work in Sepolia. If not, you will have probably to increase manually the fees. The result is :

Reduction of ETH balance = 0.0
Reduction of STRK balance = 0.0000241
ivpavici commented 6 months ago

Thanks @PhilippeR26 ! @karasbuilder please try and reopen if you have any additional questions!