[SOLVED] Wix Integration with Basic Moralis API Call

Iā€™m working on getting a proof of concept going for Wix integration so I can give myself a trajectory of learning. Wix has really annoying code integration tools, but I donā€™t need that much extra for what Iā€™m doing and if I can make this work, itā€™ll save me a toooooon of time with not having to create a complex custom website. Basically trying to get their first call function to work on Wix, just to get my bearings, and I canā€™t figure it out.

Iā€™ve tried making a custom element, but that only attaches to the java code and a custom HTML file wonā€™t associate with the java code. I donā€™t really know how the file structures work in Wix, but I made the test.js in root, so I figured the html calling for java.js to be in root would work, but it doesnā€™t. Does anyone have any advice for how to get this to work properly? Thank you in advance!

This is the code from the tutorial (obv in my code, I have my API key replacing the ā€˜your API keyā€™ bit):

Firstly open your index.html file and add this code, it simply calls your javascript and adds a result area to print your data.

1<h1>Moralis API Response:</h1>
2<div id="result"></div>
3<script src="./test.js"></script>

Secondly open your Javascript file and copy and paste this Javascript code there. It will make a data query to Ethereum Chain, Block number 1000.

1const options = {
2  method: 'GET',
3  headers: { 'Accept': 'application/json', 'X-API-Key': 'your API Key' },
4};
5fetch('https://deep-index.moralis.io/api/v2/block/1000?chain=eth', options)
6  .then((response) => response.json())
7  .then((response) => printResult(response))
8  .catch((err) => console.error(err))
9
10const printResult = (response) => {
11  const container = document.getElementById('result')
12  container.innerHTML = "<pre>" + JSON.stringify(response ,null, 2) + "</pre>"
13}

Do you see any errors? Can you check the console?

UPDATE: I managed to get it working. I just stopped calling the script in the HTML embed and wrote the script directly within the html lines and that made it work. I will continue troubleshooting the ability to call upon javascript files, but Iā€™ll take that to the Wix forums unless anyone has any solutions here.

OG: No errors. Nothing on the console. Itā€™s like the code isnā€™t running, which makes no sense to me.

Thereā€™s nothing particularly noteworthy I can see from the code that I need to set in ā€œattributesā€, I believe.

I know this should ā€œtheoreticallyā€ work. I just need to sort out how to get an html embed to speak to a custom element, or vice versa.

2 Likes

Great to hear that! @Darknuke

Since you have solved your issue, we will close this thread :raised_hands:

Feel free to create a new one in case you face any issue, we will be available 24/7 to assist you~