# Transaction

### Classes

[Transaction](#Transaction)

### Typedefs

[TransactionMeta](#TransactionMeta) : `CallRequest`

### Transaction

**Kind**: global class

* [Transaction](#Transaction)
  * [new Transaction(options)](#new_Transaction_new)
  * *instance*
    * [.hash](#Transaction+hash) ⇒ `string` | `undefined`
    * [.sign(privateKey, networkId)](#Transaction+sign) ⇒ [`Transaction`](#Transaction)
    * [.recover()](#Transaction+recover) ⇒ `string`
    * [.encode(\[includeSignature\])](#Transaction+encode) ⇒ `Buffer`
    * [.serialize()](#Transaction+serialize) ⇒ `string`
  * *static*
    * [.decodeRaw(raw)](#Transaction.decodeRaw) ⇒ [`Transaction`](#Transaction)

#### new Transaction(options)

Create a transaction.

| Param                   | Type                 | Description                                                                                                                                                 |
| ----------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| options                 | `object`             |                                                                                                                                                             |
| \[options.from]         | `string`             | The sender address.                                                                                                                                         |
| \[options.nonce]        | `string` \| `number` | This allows to overwrite your own pending transactions that use the same nonce.                                                                             |
| \[options.gasPrice]     | `string` \| `number` | The price of gas for this transaction in drip.                                                                                                              |
| \[options.gas]          | `string` \| `number` | The amount of gas to use for the transaction (unused gas is refunded).                                                                                      |
| \[options.to]           | `string`             | The destination address of the message, left undefined for a contract-creation transaction.                                                                 |
| \[options.value]        | `string` \| `number` | The value transferred for the transaction in drip, also the endowment if it’s a contract-creation transaction.                                              |
| \[options.storageLimit] | `string` \| `number` | The storage limit specified by the sender.                                                                                                                  |
| \[options.epochHeight]  | `string` \| `number` | The epoch proposed by the sender. Note that this is NOT the epoch of the block containing this transaction.                                                 |
| \[options.chainId]      | `string` \| `number` | The chain ID specified by the sender.                                                                                                                       |
| \[options.data]         | `string` \| `Buffer` | Either a ABI byte string containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialisation code. |
| \[options.r]            | `string` \| `Buffer` | ECDSA signature r                                                                                                                                           |
| \[options.s]            | `string` \| `Buffer` | ECDSA signature s                                                                                                                                           |
| \[options.v]            | `number`             | ECDSA recovery id                                                                                                                                           |

#### transaction.hash ⇒ `string` | `undefined`

Getter of transaction hash include signature.

> Note: calculate every time.

**Kind**: instance property of [`Transaction`](#Transaction)\
**Returns**: `string` | `undefined` - If transaction has r,s,v return hex string, else return undefined.<br>

#### transaction.sign(privateKey, networkId) ⇒ [`Transaction`](#Transaction)

Sign transaction and set 'r','s','v'.

**Kind**: instance method of [`Transaction`](#Transaction)

| Param      | Type     | Description             |
| ---------- | -------- | ----------------------- |
| privateKey | `string` | Private key hex string. |
| networkId  | `number` | fullnode's network id.  |

#### transaction.recover() ⇒ `string`

Recover public key from signed Transaction.

**Kind**: instance method of [`Transaction`](#Transaction)<br>

#### transaction.encode(\[includeSignature]) ⇒ `Buffer`

Encode rlp.

**Kind**: instance method of [`Transaction`](#Transaction)

| Param               | Type      | Default | Description                              |
| ------------------- | --------- | ------- | ---------------------------------------- |
| \[includeSignature] | `boolean` | `false` | Whether or not to include the signature. |

#### transaction.serialize() ⇒ `string`

Get the raw transaction hex string.

**Kind**: instance method of [`Transaction`](#Transaction)\
**Returns**: `string` - Hex string<br>

#### Transaction.decodeRaw(raw) ⇒ [`Transaction`](#Transaction)

Decode rlp encoded raw transaction hex string

**Kind**: static method of [`Transaction`](#Transaction)\
**Returns**: [`Transaction`](#Transaction) - A Transaction instance

| Param | Type     | Description                        |
| ----- | -------- | ---------------------------------- |
| raw   | `string` | rlp encoded transaction hex string |

### TransactionMeta : `CallRequest`

**Kind**: global typedef


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://confluxnetwork.gitbook.io/js-conflux-sdk/api/transaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
