# Cancel

## sendTransaction (CANCEL) <a href="#sendtransaction-cancel" id="sendtransaction-cancel"></a>

```javascript
caver.klay.sendTransaction(transactionObject [, callback])
```

[Cancel](https://archive-ko.docs.klaytn.foundation/klaytn/design/transactions/basic#txtypecancel) 트랜잭션을 네트워크에 전송합니다.

**Parameters**

The parameters of sendTransaction are a transaction object and a callback function.

| Name              | Type     | Description                                                                                                |
| ----------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
| transactionObject | Object   | The transaction object to send.                                                                            |
| callback          | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |

`CANCEL` 트랜잭션 오브젝트의 구조는 다음과 같습니다.

| Name     | Type   | Description                                                                                                                                                    |
| -------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type     | String | Transaction Type. "CANCEL"                                                                                                                                     |
| from     | String | Address of this transaction sender.                                                                                                                            |
| gas      | Number | The maximum amount of gas willing to pay for the transaction (unused gas is refunded).                                                                         |
| gasPrice | Number | (optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.                                     |
| nonce    | Number | (optional) Integer of a nonce. 이를 통해 같은 논스를 사용하는 펜딩 상태의 트랜잭션을 덮어쓸 수 있습니다. If omitted, it will be set by caver-js via calling `caver.klay.getTransactionCount`. |

**Return Value**

The `callback` will return the 32-byte transaction hash.

`PromiEvent`: A promise combined event emitter. Will be resolved when the transaction receipt is available. Additionally the following events are available:

* `"transactionHash"` returns `String`: Is fired right after the transaction is sent and a transaction hash is available.
* `"receipt"` returns `Object`: Is fired when the transaction receipt is available.
* `"error"` returns `Error`: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

**Example**

```javascript
const account = caver.klay.accounts.wallet.add('0x{private key}')

// using the promise
caver.klay.sendTransaction({
    type: 'CANCEL',
    from: account.address,
    nonce: 7, // It specifies target transaction having the same nonce to cancel.
    gas: '300000',
})
.then(function(receipt){
    ...
});

// using the event emitter
caver.klay.sendTransaction({
    type: 'CANCEL',
    from: account.address,
    nonce: 7, // It specifies target transaction having the same nonce to cancel.
    gas: '300000',
})
.on('transactionHash', function(hash){
    ...
})
.on('receipt', function(receipt){
    ...
})
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
```

## sendTransaction (FEE\_DELEGATED\_CANCEL) <a href="#sendtransaction-fee_delegated_cancel" id="sendtransaction-fee_delegated_cancel"></a>

```javascript
caver.klay.sendTransaction(transactionObject [, callback])
```

[Fee Delegated Cancel](https://archive-ko.docs.klaytn.foundation/klaytn/design/transactions/fee-delegation#txtypefeedelegatedcancel) 트랜잭션을 네트워크에 전송합니다.

**Parameters**

The parameters of sendTransaction are a transaction object and a callback function.

| Name              | Type     | Description                                                                                                |
| ----------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
| transactionObject | Object   | The transaction object to send.                                                                            |
| callback          | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |

`FEE_DELEGATED_CANCEL` 트랜잭션 객체의 구조는 다음과 같습니다.

| Name     | Type   | Description                                                                                                                                                                                     |
| -------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type     | String | Transaction Type. "FEE\_DELEGATED\_CANCEL"                                                                                                                                                      |
| from     | String | Address of this transaction sender.                                                                                                                                                             |
| gas      | Number | The maximum amount of gas willing to pay for the transaction (unused gas is refunded).                                                                                                          |
| gasPrice | Number | (optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.                                                                      |
| nonce    | Number | (optional) Integer of a nonce. This allows replacing your own pending transaction that has the same nonce. If omitted, it will be set by caver-js via calling `caver.klay.getTransactionCount`. |

위의 구조를 가진 `FEE_DELEGATED_CANCEL` 유형의 트랜잭션 오브젝트, 또는 `FEE_DELEGATED_CANCEL` 유형의 `RLP 인코딩된 트랜잭션`은 트랜잭션 발신자의 경우 [caver.klay.accounts.signTransaction](https://archive-ko.docs.klaytn.foundation/content/dapp/sdk/caver-js/v1.4.1/caver.klay.accounts#signtransaction)의 매개 변수로, 수수료 납부자의 경우 [caver.klay.accounts.feePayerSignTransaction](https://archive-ko.docs.klaytn.foundation/content/dapp/sdk/caver-js/v1.4.1/caver.klay.accounts#feepayersigntransaction)의 매개 변수로 사용할 수 있습니다.

In order for the fee payer to sign an RLP encoded transaction signed by the sender and send it to the network, define an object with the following structure and call `caver.klay.sendTransaction`.

| Name                 | Type   | Description                                   |
| -------------------- | ------ | --------------------------------------------- |
| feePayer             | String | The fee payer address of the transaction.     |
| senderRawTransaction | String | The RLP-encoded transaction signed by sender. |

**Return Value**

The `callback` will return the 32-byte transaction hash.

`PromiEvent`: A promise combined event emitter. Will be resolved when the transaction receipt is available. Additionally the following events are available:

* `"transactionHash"` returns `String`: Is fired right after the transaction is sent and a transaction hash is available.
* `"receipt"` returns `Object`: Is fired when the transaction receipt is available.
* `"error"` returns `Error`: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

**Example**

```javascript
const sender = caver.klay.accounts.wallet.add('0x{private key}')
const feePayer = caver.klay.accounts.wallet.add('0x{private key}')

// using the promise
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
  type: 'FEE_DELEGATED_CANCEL',
  from: sender.address,
  nonce: 7, // It specifies target transaction having the same nonce to cancel.
  gas: '300000',
}, sender.privateKey)

caver.klay.sendTransaction({
  senderRawTransaction: senderRawTransaction,
  feePayer: feePayer.address,
})
.then(function(receipt){
    ...
});

// using the event emitter
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
  type: 'FEE_DELEGATED_CANCEL',
  from: sender.address,
  nonce: 7, // It specifies target transaction having the same nonce to cancel.
  gas: '300000',
}, sender.privateKey)

caver.klay.sendTransaction({
  senderRawTransaction: senderRawTransaction,
  feePayer: feePayer.address,
})
.on('transactionHash', function(hash){
    ...
})
.on('receipt', function(receipt){
    ...
})
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
```

## sendTransaction (FEE\_DELEGATED\_CANCEL\_WITH\_RATIO) <a href="#sendtransaction-fee_delegated_cancel_with_ratio" id="sendtransaction-fee_delegated_cancel_with_ratio"></a>

```javascript
caver.klay.sendTransaction(transactionObject [, callback])
```

[Fee Delegated Cancel With Ratio](https://archive-ko.docs.klaytn.foundation/klaytn/design/transactions/partial-fee-delegation#txtypefeedelegatedcancelwithratio) 트랜잭션을 네트워크에 전송합니다.

**Parameters**

The parameters of sendTransaction are a transaction object and a callback function.

| Name              | Type     | Description                                                                                                |
| ----------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
| transactionObject | Object   | The transaction object to send.                                                                            |
| callback          | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |

`FEE_DELEGATED_CANCEL_WITH_RATIO` 트랜잭션 객체의 구조는 다음과 같습니다.

| Name     | Type   | Description                                                                                                                                                                                                            |
| -------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type     | String | Transaction Type. "FEE\_DELEGATED\_CANCEL\_WITH\_RATIO"                                                                                                                                                                |
| from     | String | Address of this transaction sender.                                                                                                                                                                                    |
| gas      | Number | The maximum amount of gas willing to pay for the transaction (unused gas is refunded).                                                                                                                                 |
| gasPrice | Number | (optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.                                                                                             |
| nonce    | Number | (optional) Integer of a nonce. This allows replacing your own pending transaction that has the same nonce. If omitted, it will be set by caver-js via calling `caver.klay.getTransactionCount`.                        |
| feeRatio | Number | Fee ratio of the fee payer. If it is 30, 30% of the fee will be paid by the fee payer. 70% will be paid by the sender. The range of fee ratio is 1 \~ 99, if it is out of range, the transaction will not be accepted. |

위의 구조를 가진 `FEE_DELEGATED_CANCEL_WITH_RATIO` 유형의 트랜잭션 오브젝트, 또는 `FEE_DELEGATED_CANCEL_WITH_RATIO` 유형의 `RLP 인코딩된 트랜잭션`은 트랜잭션 발신자의 경우 [caver.klay.accounts.signTransaction](https://archive-ko.docs.klaytn.foundation/content/dapp/sdk/caver-js/v1.4.1/caver.klay.accounts#signtransaction)의 매개 변수로, 수수료 납부자의 경우 [caver.klay.accounts.feePayerSignTransaction](https://archive-ko.docs.klaytn.foundation/content/dapp/sdk/caver-js/v1.4.1/caver.klay.accounts#feepayersigntransaction)의 매개 변수로 사용할 수 있습니다.

In order for the fee payer to sign an RLP encoded transaction signed by the sender and send it to the network, define an object with the following structure and call `caver.klay.sendTransaction`.

| Name                 | Type   | Description                                   |
| -------------------- | ------ | --------------------------------------------- |
| feePayer             | String | The fee payer address of the transaction.     |
| senderRawTransaction | String | The RLP-encoded transaction signed by sender. |

**Return Value**

The `callback` will return the 32-byte transaction hash.

`PromiEvent`: A promise combined event emitter. Will be resolved when the transaction receipt is available. Additionally the following events are available:

* `"transactionHash"` returns `String`: Is fired right after the transaction is sent and a transaction hash is available.
* `"receipt"` returns `Object`: Is fired when the transaction receipt is available.
* `"error"` returns `Error`: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

**Example**

```javascript
const sender = caver.klay.accounts.wallet.add('0x{private key}')
const feePayer = caver.klay.accounts.wallet.add('0x{private key}')

// using the promise
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
  type: 'FEE_DELEGATED_CANCEL_WITH_RATIO',
  from: sender.address,
  nonce: 7, // It specifies target transaction having the same nonce to cancel.
  gas: '300000',
  feeRatio: 30,
}, sender.privateKey)

caver.klay.sendTransaction({
  senderRawTransaction: senderRawTransaction,
  feePayer: feePayer.address,
})
.then(function(receipt){
    ...
});

// using the event emitter
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
  type: 'FEE_DELEGATED_CANCEL_WITH_RATIO',
  from: sender.address,
  nonce: 7, // It specifies target transaction having the same nonce to cancel.
  gas: '300000',
  feeRatio: 30,
}, sender.privateKey)

caver.klay.sendTransaction({
  senderRawTransaction: senderRawTransaction,
  feePayer: feePayer.address,
})
.on('transactionHash', function(hash){
    ...
})
.on('receipt', function(receipt){
    ...
})
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
```
