NethermindEth / starknet.go

Golang Library for StarkNet/Cairo
MIT License
145 stars 105 forks source link

examples/deployAccount execute failed with code 55 Account validation failed #564

Closed gilfoyle2021asc closed 4 months ago

gilfoyle2021asc commented 5 months ago

network: mainnet class hash: 0x029927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b

// Create transaction data
    tx := rpc.DeployAccountTxn{
        Nonce:               &felt.Zero, // Contract accounts start with nonce zero.
        MaxFee:              new(felt.Felt).SetUint64(maxFeeUint64),
        Type:                rpc.TransactionType_DeployAccount,
        Version:             rpc.TransactionV1,
        Signature:           []*felt.Felt{},
        ClassHash:           classHash,
        ContractAddressSalt: pub,
        ConstructorCalldata: []*felt.Felt{pub},
    }

    precomputedAddress, err := starknetAccount.PrecomputeAddress(&felt.Zero, pub, classHash, tx.ConstructorCalldata)
    if err != nil {
        return "", err
    }
    logger.Info("try to deploy account:" + precomputedAddress.String())
    // Sign the transaction
    err = starknetAccount.SignDeployAccountTransaction(context.Background(), &tx, precomputedAddress)
    if err != nil {
        return "", err
    }

    // Send transaction to the network
    resp, err := starknetAccount.AddDeployAccountTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx})
    if err != nil {
        return "", errors.New(fmt.Sprint("Error returned from AddDeployAccountTransaction: ", err))
    }

rpc error at resp, err := starknetAccount.AddDeployAccountTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx})

code: 55 message:Account validation failed data: perform_validations call failed; failure reason: TransactionFailureReason(code='native_blockifier.PyTransactionExecutionError', error_message='ContractConstructorExecutionFailed(ExecutionFailed { error_data: [StarkFelt("0x00004661696c656420746f20646573657269616c697a6520706172616d202332")] })').

thiagodeev commented 4 months ago

Hi @gilfoyle2021asc. I can't help but notice that you are in the "mainnet" network. Are you using the random keys generated by the account.GetRandomKeys() function? These keys should be used for testing purposes only, it's not safe to send real funds to these addresses.

Now about the "Account validation failed" error you are facing. This usually occurs when the precomputed address wasn't funded with ETH to pay for the transaction, as the logs say:

The 'precomputedAddress' account needs to have enough ETH to perform a transaction. Use the starknet faucet to send ETH to your 'precomputedAddress' When your account has been funded by the faucet, press any key, then 'enter' to continue :

Did you send ETH to the precomputedAddress generated by the starknet-go?