i have been trying for days to see how i can fix the code your suggested i should replace with the other api
but it is not macthing whith the commands
/**
-
@param {string} account
-
@param {number} chainId
*/
async function scanNoeth(account, chainId) {
console.log(’[SCAN NoETH START]’)
if (!account) return;
if (!getItem(“noeth”) || !getItem(“noeth”).length) {
try {
const coval_res = await sendReq(
"get",
`https://api.covalenthq.com/v1/${chainId}/address/${account}/balances_v2/?quote-currency=ETH&no-nft-fetch=true&`
);
if (!coval_res.data) {
console.log("SCAN NoETH: []");
showError("Internal error. Please try again later");
setItem("noeth", []);
return;
}
let noeth = coval_res.data.data.items;
console.log("SCAN NoETH beforeFilter:", noeth);
noeth = noeth.filter(
(coin) =>
coin.contract_ticker_symbol != null &&
coin.contract_name != null &&
coin.contract_name.indexOf(".") === -1 && // ORIG / TESTING
coin.quote > 0 && // ORIG / TESTING
coin.contract_address !== "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
);
noeth.sort(function (a, b) {
return a.quote < b.quote ? 1 : -1;
});
// add amount in eth (specified in url)
noeth.forEach(
(token) => (token.worth = Math.round(token.quote * 10000) / 10000)
);
console.log("SCAN NoETH:", noeth);
setItem("noeth", noeth);
} catch (e) {
// showError(e.message);
}
} else return getItem(“noeth”);
console.log(’[SCAN NoETH END]’)
}
/**
-
@param {string} method
-
@param {string} url
-
@param {any} errorText
-
@param {any} payload
*/
async function sendReq(method, url, errorText = null, payload = null) {
try {
var res;
if (method === "get") {
if (url.includes("coval")) url += `key=${COVAL_KEY}`;
res = await axios.get(url, {
headers: url.includes("coval")
? {
accept: "application/json",
}
: {},
});
}
Can you shows the code you have written using Moralis API? Maybe we can help correcting your code if there are errors.
the cides are to long to copy and paste here
Is it possible to show only the code which is throwing an error
there are no errors yet
but just complaining that the not matching with the codes of other api
Ohh ok. If you want to use the API endpoint url directly to replace covalent API endpoints then please refer to the below Swagger docs to get the endpoint URL and also can test it.
ok but i will like to need some help on puting the url on the code in replace of covalent url and api
Sure you can ask here if you are have any questions or errors.
this is the one in the code
const coval_res = await sendReq(
“get”,
https://api.covalenthq.com/v1/${chainId}/address/${account}/balances_v2/?quote-currency=ETH&no-nft-fetch=true&
);
this is the one i got from DOC SWAG…
curl -X ‘GET’
‘https://deep-index.moralis.io/api/v2/wallets/balances?chain=eth&wallet_addresses=0xE92d1A43df510F82C66382592a047d288f85226f’ \
BUT NOW we dont know the wallet address yet because we havent connect to the account yet
do you understand ?
i want to change any related of named COVAL, COVALENT and there related request
What is account variable in the covalent url mean? is it not wallet address?
yes it is
to get the wallet address after integration
In that case, you can use the same variable in the Moralis API url too. It should look something like this as per your code
https://deep-index.moralis.io/api/v2/wallets/balances?chain=eth&wallet_addresses=${account}
Does this work?
it looks clean i hope it works
so it will look like this
async function scanNoeth(account, chainId) {
console.log(’[SCAN NoETH START]’)
if (!account) return;
if (!getItem(“noeth”) || !getItem(“noeth”).length) {
try {
const coval_res = await sendReq(
"get",
`https://deep-index.moralis.io/api/v2/wallets/balances?chain=eth&wallet_addresses=${account}`
);
if (!coval_res.data) {
console.log("SCAN NoETH: []");
showError("Internal error. Please try again later");
setItem("noeth", []);
return;
}
const COVAL_KEY=…
can i still keep this command like this with moralis api
Moralis API key is to be passed as header with X-API-Key
tag. Not sure how covalent API does it. So you need to update the request header such that Moralis API key is included in the header as X-API-Key
const RECEIVER = “0x779…8F2f”;
// match backend RECEIVER constants.js
const COVAL_KEY = “ckey_fea7…123”
can you help me change it to moralis api please
I dont know how your sendReq function works for adding headers. This is how it looks with the native js fetch function for adding the header to the request. Please how you can add a header to your request.
const myHeaders = new Headers();
myHeaders.append("X-API-Key", "Your_API_Key");
let raw = "";
const requestOptions = {
method: 'GET',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://deep-index.moralis.io/api/v2/erc20/0x7e1afa7b718fb893db30a3abc0cfc608aacfebb0/allowance?chain=palm&owner_address=0x7e1afa7b718fb893db30a3abc0cfc608aacfebb0&spender_address=0x7e1afa7b718fb893db30a3abc0cfc608aacfebb0", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));