SIMPLE problem trying to use 0x. Here’s the given sample code for getting a swap quote:
const qs = require('qs');
const params = {
sellToken: 'DAI',
buyToken: 'WETH',
sellAmount: '100000000000000000000',
}
const response = await fetch(
`https://api.0x.org/swap/v1/quote?${qs.stringify(params)}`
);
console.log(await response.json());
And my simple html file wrapper for it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>0x Demo Code</title>
</head>
<body>
<script type="module">
import qs from 'qs';
const params = {
// Not all token symbols are supported. The address of the token can be used instead.
sellToken: 'DAI',
buyToken: 'WETH',
// Note that the DAI token uses 18 decimal places, so `sellAmount` is `100 * 10^18`.
sellAmount: '100000000000000000000',
}
export async function getQuote() {
const response = await fetch(
`https://api.0x.org/swap/v1/quote?${qs.stringify(params)}`
);
console.log(await response.json());
}
</script>
<button onclick="getQuote()">Get Quote</button>
</body>
</html>
But that’s not NodeJS, which shouldn’t be a problem. But I can’t figure out how to get
import qs from 'qs';
to work without going full blown ReactJS.
This should be stupid simple, but I can’t find any example of how to do it online.
Thoughts?