1

Having some issues getting a submit Stake Registration certificate using cardano-serialization-lib. The transaction builds, can can be signed, but what's weird is the correct fee is not being calculated. I have a console.log output of the fee that is being calculated at "calculated fee:166953" but the network is asking for 171177

Error: {"requiredFee":171177,"actualFee":166953}

Any ideas why the fee is not being calculated correctly by CSL ?

buildStakeRegistrationTransaction = async () => {

        const txBuilder = await this.initTransactionBuilder();
        const shelleyChangeAddress = Address.from_bech32(this.state.changeAddress);

        //obtaining my payment address
        const baseAddress = BaseAddress.from_address(Address.from_bech32(this.state.changeAddress));


        // Find the available UTXOs in the wallet and
        // us them as Inputs
        const txUnspentOutputs = await this.getTxUnspentOutputs();
        txBuilder.add_inputs_from(txUnspentOutputs, 1)

  
        const certs = Certificates.new();

        //Adding StakeRegistration Certificate
        certs.add(
            Certificate.new_stake_registration(
                StakeRegistration.new(
                    baseAddress.stake_cred()
                )
            )
        );

        txBuilder.set_certs(certs)  
    
        txBuilder.add_change_if_needed(Address.from_bech32(this.state.changeAddress))

        const txBody = txBuilder.build();

        //
        console.log("calculated fee:" + txBuilder.get_fee_if_set().to_str() );

        // add witness --> shouldnt really be needed as its just a StakeReg cert ?
        const transactionWitnessSet = TransactionWitnessSet.new();
        const tx = Transaction.new(
            txBody,
            TransactionWitnessSet.from_bytes(transactionWitnessSet.to_bytes())
        )

        // transaction witness / sign:
        let txVkeyWitnesses = await this.API.signTx(Buffer.from(tx.to_bytes(), "utf8").toString("hex"), true);
        console.log("txVkeyWitnesses:" + txVkeyWitnesses)
        txVkeyWitnesses = TransactionWitnessSet.from_bytes(Buffer.from(txVkeyWitnesses, "hex"));
        transactionWitnessSet.set_vkeys(txVkeyWitnesses.vkeys());
    

        const signedTx = Transaction.new(
            tx.body(),
            transactionWitnessSet
        );

        // submit TX:
        const submittedTxHash = await this.API.submitTx(Buffer.from(signedTx.to_bytes(), "utf8").toString("hex"));
        console.log("Submitted TX Hash:" + submittedTxHash)
        this.setState({submittedTxHash});

}

Error:

Uncaught (in promise) Error: submit tx failed: Error: 400:
0: {"requiredFee":171177,"actualFee":166953}

2 Answers 2

1

When you initialized the CSL you should enter the protocol parameters.

That is the first place I would be looking at.

const txBuilderCfg = CardanoWasm.TransactionBuilderConfigBuilder.new() .fee_algo(linearFee) .pool_deposit(CardanoWasm.BigNum.from_str('500000000')) .key_deposit(CardanoWasm.BigNum.from_str('2000000')) .max_value_size(4000) .max_tx_size(8000) .coins_per_utxo_word(CardanoWasm.BigNum.from_str('34482')) .build();

Also fee structures changed with the Vasil hard-fork. So if you have not updated your CLS to the latest version it will probably not calculate the fees corectly.

1
  • Hi Leo, thanks for the input. That is also what i thought, however other transactions calculate fee correctly. I have the parameters: this.protocolParams = { linearFee: { minFeeA: "44", minFeeB: "155381", }, minUtxo: "34482", poolDeposit: "500000000", keyDeposit: "2000000", maxValSize: 5000, maxTxSize: 16384, priceMem: 0.0577, priceStep: 0.0000721, coinsPerUtxoWord: "34482", } Commented Oct 31, 2022 at 19:08
0

I encountered this same issue: Fee too small required vs actual. I sent the available ADA in the wallet to itself....i.e. an 'internal' transfer? After doing that, the fee too small error did not occur. I suspect it has something to do with how there was not enough ADA in any one utxo that was selected for use in the tx - but I ma not sure. Doing that consolidated the available ADA into a single utxo though, and that was what allowed me to get past the "fee too small" error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.