loading...
Cover image for 2. Create a Commerce.js instance - Create a Commerce.js store with Svelte
Commerce.js

2. Create a Commerce.js instance - Create a Commerce.js store with Svelte

notrab profile image Jamie Barton ・1 min read

Before we begin writing any code, let's first create an instance of Commerce.js we can share around our application to fetch products, categories, and merchant information.



Inside your terminal, install @chec/commerce.js:

npm install -E @chec/commerce.js
Enter fullscreen mode Exit fullscreen mode

Now, inside src, create a new directory lib, and add the file commerce.js. We'll follow the Commerce.js docs on instantiating the SDK, and export it as client.

// src/lib/commerce.js
import CommerceSDK from "@chec/commerce.js";

const client = new CommerceSDK(
  "..." // Insert your Commerce.js Public API Key
);

export default client;
Enter fullscreen mode Exit fullscreen mode

If you don't want to create an account with Commerce.js to follow along with this tutorial, you can use the demo store public key pk_184625ed86f36703d7d233bcf6d519a4f9398f20048ec.

Discussion

pic
Editor guide