This documentation provides a guide to broadcast Ethereum Classic transactions to the mainnet using a Node.js script and the CryptoAPIs service.
- Node.js installed on your machine
- Axios' library for making HTTP requests
-
Install the required package by running:
npm install axios
-
Obtain an API Key from CryptoAPIs:
- Sign up for cryptoapis.io
- Create a new api-key here
Create a new file called broadcastETCTransaction.js
and add the following script:
import axios from 'axios';
// Replace with your API key
const apiKey = 'your-api-key-here';
// Replace with your signed transaction hex
const signedTransactionHex = 'your-signed-transaction-hex-here';
const broadcastTransaction = async () => {
try {
const response = await axios.post(
'https://rest.cryptoapis.io/blockchain-tools/ethereum-classic/mainnet/transactions/broadcast?context=broadcastETC',
{
context: '', // Optional
data: {
item: {
signedTransactionHex: signedTransactionHex
}
}
},
{
headers: {
'x-api-key': apiKey,
'Content-Type': 'application/json'
}
}
);
console.log('Transaction Broadcasted Successfully:', response.data);
} catch (error) {
console.error('Error broadcasting transaction:', error.response ? error.response.data : error.message);
}
};
broadcastTransaction();
- Replace the
apiKey
andsignedTransactionHex
variables with your actual API key and signed transaction hex. - Run the script:
node broadcastETCTransaction.js
If successful, the script will output a JSON object with the following structure:
{
"apiVersion": "string",
"requestId": "string",
"context": "string",
"data": {
"item": {
"transactionId": "string"
}
}
}
The response will contain the following fields:
-
apiVersion
(string): The version of the API. -
requestId
(string): The ID of the request. -
context
(string): The context of the response. -
data
(object):-
item
(object):transactionId
(string): The ID of the broadcasted transaction.
-