# SDK

##

A guide to start with the MyJSBlock SDK. For a quick introduction we suggest reading our [introduction](https://docs.appmachine.com/developers/javascript).

## Setup your project (e.g. with Vite)[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#setup-your-project-eg-with-vite) <a href="#setup-your-project-eg-with-vite" id="setup-your-project-eg-with-vite"></a>

We recommend using a build tool like [Vite](https://vitejs.dev/), it is an easy to use development tool for all kinds of frameworks. It also has support for creating PWAs and more. It is not required, you can also use your own setup.

With npm:

```
npm create vite
```

With yarn:

```
yarn create vite
```

After a couple of questions Vite will create a starter project for you. If you just want use regular JavaScript you can choose 'vanilla'.

## Installation[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#installation) <a href="#installation" id="installation"></a>

#### NPM[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#npm) <a href="#npm" id="npm"></a>

```
npm install @myjsblock/sdk
```

#### Yarn[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#yarn) <a href="#yarn" id="yarn"></a>

```
yarn add @myjsblock/sdk
```

## Before we begin[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#before-we-begin) <a href="#before-we-begin" id="before-we-begin"></a>

All the modules the SDK exposes are functions, every function in the SDK returns a promise. If you're not familiar with Javascript Promises checkout [this page on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises).

## Your first function[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#your-first-function) <a href="#your-first-function" id="your-first-function"></a>

In JavaScript you're able to call functions that will interact with your AppMachine App. Simply import the function and call it.

#### Example[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#example) <a href="#example" id="example"></a>

**HTML**

```html
<body>  
    <button id="loader-button">    
        Show Loader  
    </button>
</body>
```

**JavaScript**

```javascript
import { showLoader, hideLoader } from '@myjsblock/sdk'

const loadingButton = document.getElementById('loader-button');

loadingButton.addEventListener('click', async () => {  
    await showLoader();
    await new Promise((resolve) => { setTimeout(resolve, 2000) });
    await hideLoader();
});
```

See this example on [GitHub](https://github.com/AppMachine/myjsblock-sdk/tree/main/examples/show-loader-button).

## Publish it with the CLI[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#publish-it-with-the-cli) <a href="#publish-it-with-the-cli" id="publish-it-with-the-cli"></a>

If you haven't installed the CLI yet, follow the steps in our [Getting Started](https://docs.appmachine.com/developers/javascript/cli).

#### Link your project to a block[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#link-your-project-to-a-block) <a href="#link-your-project-to-a-block" id="link-your-project-to-a-block"></a>

```
myjsblock link
```

#### Push your project[​](https://docs.appmachine.com/libraries/javascript/sdk/getting-started#push-your-project) <a href="#push-your-project" id="push-your-project"></a>

```
myjsblock link
```
