> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dfns.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Solana

## Transaction

Signs an unsigned transaction and broadcasts it to chain.

| Field         | Description                                                                                                                                                           | Type - Optional     |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| `kind`        | `Transaction`                                                                                                                                                         | String              |
| `transaction` | The unsigned hex encoded transaction as shown below                                                                                                                   | String              |
| `externalId`  | A unique ID from your system. It can be leveraged to be used as an idempotency key (read more [here](https://docs-legacy.dfns.co/d/advanced-topics/api-idempotency)). | String *(optional)* |

```json theme={null}
{
  "kind": "Transaction",
  "transaction": "0x01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008001000103b25c8c464080ab2835a166d2b3f13195c2ff3c8f281c7ebe492f0d45d830ff4824a8b38a94b73d2756f2be68655a49706be9b1dc900978984d6eeaf65ab62e900000000000000000000000000000000000000000000000000000000000000000280c73cfb9caeb41b8508d20057917b568ac1f5a4175b5befa94532b3fd0b92e01020200010c02000000010000000000000000"
}
```

<Note>
  Solana web3.js expects the serialized transaction to include 0-padded placeholder signatures, otherwise deserialization will failed. If you are using a different library to construct the serialized transaction, such as the Go SDK, please make sure to include the placeholder signatures.
</Note>

### Typescript Example with Solana web3.js

First install the Solana web3.js SDK. You can find the full documentation [here](https://solana.com/docs/clients/official/javascript).

Here a code sample to broadcast a transaction via [the Dfns TypeScript SDK](https://github.com/dfns/dfns-sdk-ts):

```typescript theme={null}
import {
  clusterApiUrl,
  Connection,
  PublicKey,
  SystemProgram,
  TransactionMessage,
  VersionedTransaction,
} from '@solana/web3.js'

const walletId = 'wa-6lbfv-9esgj-xxxxxxxxxxxxxxxx'
const wallet = await dfnsClient.wallets.getWallet({ walletId })

const myAddress = new PublicKey(wallet.address)
const toAddress = new PublicKey('3U6stgsD1FmA7o3omUguritCU8iWmUM7Rs6KqAHHxHVZ')

const connection = new Connection(clusterApiUrl('devnet'), 'confirmed')
const latestBlockhash = await connection.getLatestBlockhash()

const message = new TransactionMessage({
  payerKey: myAddress,
  recentBlockhash: latestBlockhash.blockhash,
  instructions: [
    SystemProgram.transfer({
      fromPubkey: myAddress,
      toPubkey: toAddress,
      lamports: 1n,
    }),
  ],
}).compileToV0Message()
const transaction = new VersionedTransaction(message)

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

## Complete examples

For complete working examples, see the SDK examples on GitHub:

* [Basic transaction](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/solana/basic-tx) - Simple SOL transfer
* [Durable nonce transaction](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/solana/durable-nonce-tx) - Transaction with durable nonce for replay protection
* [Mint creation](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/solana/mint-creation) - SPL token minting
* [Staking](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/libs/solana/staking) - SOL staking operations
