eth_cancelPrivateTransaction - Ethereum
Request to cancel private transactions on Ethereum that are sent via eth_sendPrivateTransaction
eth_cancelPrivateTransaction stops private transactions from being submitted for future blocks. A transaction can only be cancelled if the request sent through the the same alchemy app/API key that the eth_sendPrivateTransaction call was sent to in first place.
NOTE: This method is currently only supported on Ethereum mainnet.

Parameters

  • txHash: [string] transaction hash for private transaction to be cancelled

Response

  • result: [boolean] true if transaction was successfully cancelled, false if not

Example

Request

alchemyweb3.js
ethers.js
cURL
Postman
1
// Installation instructions: https://github.com/alchemyplatform/alchemy-web3
2
3
async function main() {
4
// Import the AlchemyWeb3 library. Filepath to functions:
5
// /@alch/alchemy-web3/dist/alchemyWeb3.js
6
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
7
8
// Replace with your Alchemy API key:
9
const apiKey = "demo";
10
11
// Initialize an alchemy-web3 instance:
12
const web3 = createAlchemyWeb3(
13
`https://eth-mainnet.g.alchemy.com/v2/${apiKey}`);
14
15
// Query the blockchain (replace example parameters)
16
const hash = await web3.eth.cancelPrivateTransaction({
17
signed_data: '0x7e5814a'
18
});
19
20
// Print the output to console
21
console.log(hash);
22
}
23
24
main();
Copied!
1
// Installation instructions: https://docs.ethers.io/v5/getting-started/#installing
2
3
async function main() {
4
const { ethers } = require("ethers");
5
6
// Replace with your Alchemy API key:
7
const apiKey = "demo";
8
9
// Initialize an ethers instance
10
const provider = new ethers.providers.AlchemyProvider("homestead", apiKey);
11
12
// Query the blockchain (replace example parameters)
13
const hash = await provider.cancelPrivateTransaction({
14
signed_data: '0x7e5814a'
15
});
16
17
// Print the output to console
18
console.log(hash);
19
}
20
21
main()
Copied!
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","method":"eth_cancelPrivateTransaction","params":[{"txHash": "0x45df1bc3de765927b053ec029fc9d15d6321945b23cac0614eb0b5e61f3a2f2a"}],"id":1}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_sendPrivateTransaction",
7
"params":[{"txHash": "0x45df1bc3de765927b053ec029fc9d15d6321945b23cac0614eb0b5e61f3a2f2a"}],"id":1}'
8
"id":1
9
}
Copied!

Response

1
{
2
"jsonrpc": "2.0",
3
"id": 1,
4
"result": true // true if tx successfully cancelled, false if not
5
}
Copied!

FAQ

How to cancel a private transaction

You can cancel a private transaction by simply calling eth_cancelPrivateTransaction with the transaction hash of the transaction you wish to cancel. It is not guaranteed that the cancellation will persist if the transaction has already been mined.