hi guys,
i go along the tutorial on youtube to build the swap, but i want to change it to bnb network but cant find anything about it? have someone an idea how i change it to bnb network?
hi guys,
i go along the tutorial on youtube to build the swap, but i want to change it to bnb network but cant find anything about it? have someone an idea how i change it to bnb network?
Hi @laalaaala
You will only need to modify the API endpoint or it params to make it work on BNB chain. In the tutorial we use Moralis API and 1Inch API.
You can update the Moralis API chain params to use BNB chain Id and also use appropriate 1inch endpoint to work with BNB chain.
and where can i change the endpoint on moralis? i cant find anything with the new UI
Hi @laalaaala
On your backend where you are using the Moralis sdk functions, you have to add or update the chain param to Binance chain.
const express = require("express");
const Moralis = require("moralis").default;
const app = express();
const cors = require("cors");
require("dotenv").config();
const port = 3001;
app.use(cors());
app.use(express.json());
app.get("/tokenPrice", async (req, res) => {
const {query} = req;
const responseOne = await Moralis.EvmApi.token.getTokenPrice({
EvmChain:BSC_TESTNET, address: query.addressOne
})
const responseTwo = await Moralis.EvmApi.token.getTokenPrice({
EvmChain:BSC_TESTNET, address: query.addressOne
})
const usdPrices = {
tokenOne: responseOne.raw.usdPrice,
tokenTwo: responseTwo.raw.usdPrice,
ratio: responseOne.raw.usdPrice/responseTwo.raw.usdPrice
}
return res.status(200).json(usdPrices);
});
Moralis.start({
apiKey: process.env.MORALIS_KEY,
}).then(() => {
app.listen(port, () => {
console.log(`Listening for API Calls`);
});
});
u mean this way?
It seems like you are passing the chain params wrong.
Please check this doc for an example on how to use the chain param