Cardano-rest how to create and submit transaction with javascript

Im using cardano-wallet package to build transaction manually and get stuck in encode transaction as cbor format. Any one can help?

const Cardano = require(‘cardano-wallet’)

const txFinalizer = new Cardano.TransactionFinalized(unsignedTx)
const setting = Cardano.BlockchainSettings.from_json({
  protocol_magic: PROTOCOL_MAGICS.testnet
})

// sign Transaction
utxos.forEach(() => {
  const witness = Cardano.Witness.new_extended_key(
    setting,
    Cardano.PrivateKey.from_hex(privateKey),
    txFinalizer.id()
  )
  txFinalizer.add_witness(witness)
})
const txid = txFinalizer.id().to_hex()
const signedTx = txFinalizer.finalize()
const txEncoded = CBOR.encode(Buffer.from(signedTx.to_hex(), 'hex')


const response = await axios({
  headers: {
    'Content-Type': 'application/cbor'
  },
  method: 'post',
  url: `${submitUrl}/api/submit/tx`,
  'data-binary': txEncoded
})

I’m not familiar with the cardano-wallet package, but I can see you’re missing a parentheses at the end of

const txEncoded = CBOR.encode(Buffer.from(signedTx.to_hex(), 'hex')

That might be it :slight_smile:

thank you, but it’s not the problem :grimacing:

I addressed the problem myself
const txEncoded = Buffer.from(signedTx.to_hex(), ‘hex’)

const response = await axios({
  headers: {
    'Content-Type': 'application/cbor'
  },
  method: 'post',
  url: `${submitUrl}/api/submit/tx`,
  data: txEncoded
})