starknet-io / starknet.js

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

deployAccount Function Failure #1050

Closed TiyoSheng closed 3 months ago

TiyoSheng commented 3 months ago

1047

starknet.js version 6.1.5

My network uses --disable-fee, and it works successfully on starknet.js v5.23.

ivpavici commented 3 months ago

what network supports --disable-fee , where is this from?

TiyoSheng commented 3 months ago

katana --disable-fee (Disable charging fee for transactions.

847850277 commented 3 months ago

I also encountered the same problem。

The following code is set according to creating a document account.


const { RpcProvider, Account,ec,stark,CallData, hash} = require("starknet");

async function main() {
    //const provider = new RpcProvider({ nodeUrl: "http://127.0.0.1:5050/rpc" }); // only for starknet-devnet-rs
    const provider = new RpcProvider({ nodeUrl: "http://127.0.0.1:5050/rpc" });

    console.log("Provider connected to Starknet-devnet-rs");
    //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 starkKeyPubAX = ec.starkCurve.getStarkKey(privateKeyAX);
    console.log('AX_ACCOUNT_PUBLIC_KEY=', starkKeyPubAX);

// Calculate future address of the ArgentX account
    const AXproxyConstructorCallData = CallData.compile({
        implementation: argentXaccountClassHash,
        selector: hash.getSelectorFromName('initialize'),
        calldata: CallData.compile({ signer: starkKeyPubAX, guardian: '0' }),
    });
    const AXcontractAddress = hash.calculateContractAddressFromHash(
        starkKeyPubAX,
        argentXproxyClassHash,
        AXproxyConstructorCallData,
        0
    );
    console.log('Precalculated account address=', AXcontractAddress);

    const body = {
        address: AXcontractAddress.toString(),
        amount: 10_000_000_000_000_000_000,
        unit: "WEI"
    };

    // Send the request
    fetch('http://127.0.0.1:5050/mint', {
        method: 'POST',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(body)
    }).then(response => response.json())
        .then(data => console.log(data))
        .catch((error) => {
            console.error('Error:', error);
        });

    const accountAX = new Account(provider, AXcontractAddress.toString(), privateKeyAX,'1');

    const deployAccountPayload = {
        classHash: argentXproxyClassHash,
        constructorCalldata: AXproxyConstructorCallData,
        contractAddress: AXcontractAddress,
        addressSalt: starkKeyPubAX,
    };

    const { transaction_hash: AXdAth, contract_address: AXcontractFinalAddress } =
        await accountAX.deployAccount(deployAccountPayload);
    console.log('✅ ArgentX wallet deployed at:', AXcontractFinalAddress);
    await provider.waitForTransaction(AXdAth);

}

main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error);
        process.exit(1);
    });

but However, executing this method will return the following error message


LibraryError: RPC: starknet_estimateFee with params {"request":[{"type":"DEPLOY_ACCOUNT","constructor_calldata":["0x33434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2","0x79dc0da7c54b95f10aa182ad0a46400db63156920adb65eca2654c0945a463","0x2","0x14cf7b6c50ae6aaa00a1df516f2c2a7b7ee576e7acc2b3f86f9bb1e367c4be1","0x0"],"class_hash":"0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918","contract_address_salt":"0x14cf7b6c50ae6aaa00a1df516f2c2a7b7ee576e7acc2b3f86f9bb1e367c4be1","version":"0x100000000000000000000000000000001","signature":["0x6903ba3fa270cbba097b09fb963ad867631fed671c3c55b2c4d7de5ce547758","0x1d07092aeeab7ce865c0e4510959dfeb5691ff7c0631b967e732a46596127c9"],"nonce":"0x0","max_fee":"0x0"}],"block_id":"pending"}
 -32602: missing field `simulation_flags`: undefined

In fact, if I use the test case of Java starknet-jvm, it can be executed normally. It will bring the following parameter information over.

image

image
PhilippeR26 commented 3 months ago

Sounds like an error due to the rpc spec of your node. Which rpc spec is using your Katana? Then Select the right version of Starknet.js, following this table : https://www.starknetjs.com/docs/next/guides/connect_network

847850277 commented 3 months ago

Sounds like an error due to the rpc spec of your node. Which rpc spec is using your Katana? Then Select the right version of Starknet.js, following this table : https://www.starknetjs.com/docs/next/guides/connect_network

Starknet.js version is 5.24.3, testnet is latest starknet-devnet-rs

When I use Argent X to deploy accounts on the local network, the same error occurs

image

Do I have to use Katana for testing the network?

The above error is based on my judgment that the deployAccount method did not carry the simulation_flags parameter when calling the startnet_estimateFee of the rpc node. I think it is possible to extend the startnet_estimateFee setting to add a default value to be compatible with it.

PhilippeR26 commented 3 months ago

Well, this issue has been created about Katana? What are you doing here? Don't you think that you should open your own issue, using the mandatory template to expose your case? Or requests assistance in the Starknet Discord : https://discord.com/channels/793094838509764618/927918707613786162 ?

ivpavici commented 3 months ago

Starknet.js version 5.24.3 does not work with the latest starknet-devnet-rs. Please switch to the latest develop branch from starknet.js

Anyway, I will close this since it is incoherent between 2 users and not easy to understand who is using what and which version... Also in the future please do not remove the bug template, I will start automatically closing all issues that do not fill in the template properly!