<p>You can check the changelog here for some examples and explanations: <a href="https://github.com/Emurgo/cardano-serialization-lib/releases/tag/10.0.0" rel="nofollow noreferrer">https://github.com/Emurgo/cardano-serialization-lib/releases/tag/10.0.0</a></p>
<p>A rough example could look something like this:</p>
<pre><code>function createExampleTx() {

  const protocolParams = await blockfrost.fetchParameters();
  
  // Create TransactionBuilderConfig (see func below)
  const txBuilderConfig = getTxBuilderConfig(protocolParams);

  // Create TransactionBuilder
  const txBuilder = TransactionBuilder.new(txBuilderConfig);

  txBuilder.set_ttl(protocolParams.slot + 10000);

  // Create and add outputs
  const txOut = TransactionOutputBuilder.new()
    .with_address(RECEIVER)
    .next()
    .with_coin(BigNum.from_str(&quot;5000000&quot;))
    .build();

  txBuilder.add_output(txOut);

  // Create and add Inputs
  const utxos = await getUtxos(SENDER);
  txBuilder.add_inputs_from(utxos, CoinSelectionStrategyCIP2.LargestFirst);

  // Add change and fees
  txBuilder.add_change_if_needed(SENDER);

  // Build transaction
  const txBody = txBuilder.build();

  const unsignedTx = Transaction.new(
    txBody,
    TransactionWitnessSet.new()
  );

  // ...
}

function getTxBuilderConfig(protocolParams: ProtocolParameters): TransactionBuilderConfig {

  return TransactionBuilderConfigBuilder.new()
    .fee_algo(LinearFee.new(
      BigNum.from_str(protocolParams.linearFee.minFeeA),
      BigNum.from_str(protocolParams.linearFee.minFeeB)
    ))
    .pool_deposit(BigNum.from_str(protocolParams.poolDeposit))
    .key_deposit(BigNum.from_str(protocolParams.keyDeposit))
    .max_tx_size(protocolParams.maxTxSize)
    .max_value_size(parseInt(protocolParams.maxValSize!))
    .coins_per_utxo_word(BigNum.from_str(protocolParams.coinsPerUtxoWord!))
    .build()

}
</code></pre>

CC BY-SA 4.0
2022-04-24T05:38:17.900Z
2022-04-24T05:38:17.900Z
sean
<p>I'm using cardano-serialization-lib <code>^9.1.2</code> to create transaction.</p>
<p>I'm using method that are now deprecated in version <code>10</code>, so is there an example of transaction with serialization-lib latest version used on nodejs?</p>

<transaction><cardano-serialization-lib><javascript>
Create transaction serialization-lib > version 10
# Create transaction serialization-lib > version 10

(Asked by: username_0 on 2022-04-23)

I'm using cardano-serialization-lib `^9.1.2` to create transaction.

I'm using method that are now deprecated in version `10`, so is there an example of transaction with serialization-lib latest version used on nodejs?

**Tags:** transaction, cardano-serialization-lib, javascript

---

## 1 answers

### Answer by username_1 on 2022-04-24. Score: 1

You can check the changelog here for some examples and explanations: https://github.com/Emurgo/cardano-serialization-lib/releases/tag/10.0.0
A rough example could look something like this:
function createExampleTx() {

  const protocolParams = await blockfrost.fetchParameters();
  
  // Create TransactionBuilderConfig (see func below)
  const txBuilderConfig = getTxBuilderConfig(protocolParams);

  // Create TransactionBuilder
  const txBuilder = TransactionBuilder.new(txBuilderConfig);

  txBuilder.set_ttl(protocolParams.slot + 10000);

  // Create and add outputs
  const txOut = TransactionOutputBuilder.new()
    .with_address(RECEIVER)
    .next()
    .with_coin(BigNum.from_str("5000000"))
    .build();

  txBuilder.add_output(txOut);

  // Create and add Inputs
  const utxos = await getUtxos(SENDER);
  txBuilder.add_inputs_from(utxos, CoinSelectionStrategyCIP2.LargestFirst);

  // Add change and fees
  txBuilder.add_change_if_needed(SENDER);

  // Build transaction
  const txBody = txBuilder.build();

  const unsignedTx = Transaction.new(
    txBody,
    TransactionWitnessSet.new()
  );

  // ...
}

function getTxBuilderConfig(protocolParams: ProtocolParameters): TransactionBuilderConfig {

  return TransactionBuilderConfigBuilder.new()
    .fee_algo(LinearFee.new(
      BigNum.from_str(protocolParams.linearFee.minFeeA),
      BigNum.from_str(protocolParams.linearFee.minFeeB)
    ))
    .pool_deposit(BigNum.from_str(protocolParams.poolDeposit))
    .key_deposit(BigNum.from_str(protocolParams.keyDeposit))
    .max_tx_size(protocolParams.maxTxSize)
    .max_value_size(parseInt(protocolParams.maxValSize!))
    .coins_per_utxo_word(BigNum.from_str(protocolParams.coinsPerUtxoWord!))
    .build()

}


---

