Is anyone know how to call localhost API from Moralis cloud httpRequest?
here is my code.
Moralis.Cloud.afterSave(âEthTransactionsâ, (request) => {
const logger = Moralis.Cloud.getLogger();
// Take the transaction and call the API to save the data into mongodb.
const transaction = request.object;
const user_address = transaction.get(âfrom_addressâ);
const chain = âethâ;
const block_hash = transaction.get(âblock_hashâ);
const gas_price = transaction.get(âgas_priceâ);
const block_timestamp = transaction.get(âblock_timestampâ);
const receipt_cumulative_gas_used = transaction.get(âreceipt_cumulative_gas_usedâ);
const ACL = transaction.get(âACLâ);
const receipt_gas_used = transaction.get(âreceipt_gas_usedâ);
const input = transaction.get(âinputâ);
const hash = transaction.get(âhashâ);
const updatedAt = transaction.get(âupdatedAtâ);
const nonce = transaction.get(ânonceâ);
const to_address = transaction.get(âto_addressâ);
const transaction_index = transaction.get(âtransaction_indexâ);
const value = transaction.get(âvalueâ);
const decimal = transaction.get(âdecimalâ);
const gas = transaction.get(âgasâ);
const receipt_status = transaction.get(âreceipt_statusâ);
const createdAt = transaction.get(âcreatedAtâ);
const block_number = transaction.get(âblock_numberâ);
const from_address = transaction.get(âfrom_addressâ);
const confirmed = transaction.get(âconfirmedâ);
const body = {
user_address,
chain,
block_hash,
gas_price,
block_timestamp,
receipt_cumulative_gas_used,
ACL,
receipt_gas_used,
input,
hash,
updatedAt,
nonce,
to_address,
transaction_index,
value,
decimal,
gas,
receipt_status,
createdAt,
block_number,
from_address,
confirmed
}
logger.info("body::: " + body);
Moralis.Cloud.httpRequest({
method: 'POST',
url: 'http://localhost:8080/api/save/transaction',
body: body,
}).then(function (httpResponse) {
logger.info(httpResponse.text);
}, function (httpResponse) {
logger.error('Request failed with response code ' + httpResponse.status);
});
})