Skip to main content

Transaction

Signs an unsigned Hedera or EVM transaction and broadcasts it to chain.
FieldDescriptionType - Optional
kindTransactionString
transactionThe unsigned hex encoded transaction as shown below.String
externalIdA unique ID from your system. It can be leveraged to be used as an idempotency key (read more here).String (optional)
{
  "kind": "Transaction",
  "transaction": "0x0a6c2a6a0a660a1a0a0b08f6f89fc80610ecf1bf1912090800100018c7b1a303180012060800100018051880c2d72f22020878320072350a330a200a1a0800100022140c78f5e80fe0107ba1ab52048b4b2053ee948611100218000a0f0a090800100018c7b1a303100118001200"
}

Typescript Example with Hiero JavaScript SDK

First install the Hiero JavaScript SDK. You can find the full documentation here: https://github.com/hiero-ledger/hiero-sdk-js Here a code sample to broadcast a transaction via the Dfns TypeScript SDK:
import { Hbar, TransferTransaction } from '@hashgraph/sdk'

const walletId = 'wa-172um-hgi5f-xxxxxxxxxxxxxxxx'
const wallet = await dfnsClient.wallets.getWallet({ walletId })

const recipient = '0x956fbb0c88b3c597d4afdbab3e26939051ff6725'

const client = Client.forMainnet()

const transaction = await new TransferTransaction()
  .addHbarTransfer(recipient, Hbar.fromTinybars(1))
  .addHbarTransfer(wallet.address!, Hbar.fromTinybars(-1))
  .freezeWith(client)

const res = await dfnsClient.wallets.broadcastTransaction({
  walletId,
  body: {
    kind: 'Transaction',
    transaction: `0x${Buffer.from(transaction.toBytes()).toString('hex')}`,
  },
})