# soar_sdk

> Sdk bindings for the SOAR smart contract.

Latest version **0.1.7** (published 2023-09-25) · 0 weekly downloads

## Install

```sh
npm install soar_sdk
pnpm add soar_sdk
yarn add soar_sdk
bun add soar_sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.7 |
| Published | 2023-09-25 |
| First published | 2023-09-25 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | gabriele.picco |

## Links

- npm: https://www.npmjs.com/package/soar_sdk
- npm.io page: https://npm.io/package/soar_sdk

## Dependencies (6)

- [bs58](https://npm.io/package/bs58.md) ^5.0.0
- [bn.js](https://npm.io/package/bn.js.md) ^5.2.1
- [@solana/web3.js](https://npm.io/package/@solana/web3.js.md) ^1.73.2
- [@coral-xyz/anchor](https://npm.io/package/@coral-xyz/anchor.md) ^0.26.0
- [@solana/spl-token](https://npm.io/package/@solana/spl-token.md) ^0.3.7
- [@metaplex-foundation/beet-solana](https://npm.io/package/@metaplex-foundation/beet-solana.md) ^0.4.0

## Recent versions

- 0.1.7 (latest) — 2023-09-25

## README

# SOAR SDK

This Typescript sdk provides a convenient interface and methods for interacting with the on-chain soar program.

## Contents

- [SOAR SDK](#soar-sdk)
  - [Contents](#contents)
  - [Getting started](#getting-started)
  - [Classes](#classes)
    - [SoarProgram](#soarprogram)
    - [GameClient](#gameclient)
    - [InstructionBuilder](#instructionbuilder)
  - [Contributing](#contributing)
    - [Tests](#tests)

## Getting started

```typescript
import { SoarProgram, GameType, Genre } from "@soar/sdk";

const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);

const client = SoarProgram.get(provider);

let game = Keypair.generate();
let title = "Game1";
let description = "Description";
let genre = Genre.Action;
let gameType = GameType.Web; 
let nftMeta = Keypair.generate().publicKey;
let _auths = auths.map((keypair) => keypair.publicKey);

// Retrieve the bundled transaction.
let { newGame, transaction } = await client.initializeNewGame(game.publicKey, title, description, genre, gameType, nftMeta, _auths);
// Send and confirm the transaction with the game keypair as signer. 
await client.sendAndConfirmTransaction(transaction, [game]);
```

## Classes

### SoarProgram

The `SoarProgram` class gives client access to every instruction in the on-chain SOAR program.

It also gives utility functions for deriving PDAs:

```typescript
const user = Keypair.generate().publicKey;
const playerAddress = client.utils.derivePlayerAddress(user)[0],
```

fetching an account:

```typescript
const account = await client.fetchLeaderBoardAccount(address);
```

and fetching multiple accounts:

```typescript
const accounts = await client.fetchAllLeaderboardAccounts([]);
```

### GameClient

The `GameClient` provides a more specific set of functions tailored to a single Game account.

```typescript
import { GameClient } from "@soar/sdk";
```

Get an instance representing an existing on-chain Game account:

```typescript
const soar = SoarProgram.get(provider);
const gameClient = new GameClient(soar, address);
```

Register a new game:

```typescript
const soar = SoarProgram.get(provider);
const game = new GameClient.register(soar, ...);
```

```typescript
// Create a new leaderboard:
await game.addLeaderboard(....);

// Access the game's state.
await game.init();

// Refresh the game's state.
await game.refresh();

// Get the most recently-created achievement for a game
const achievement = game.recentAchievementAddress();
```

## InstructionBuilder

```typescript
import { InstructionBuilder } from "@soar/sdk"
```

Provides a set of methods for conveniently bundling transactions.

```typescript
const transaction = await this.builder
      .andInitializePlayer({username, nftMeta}, user)
      .andRegisterPlayerEntry(/*...*/)
      .andSubmitScoreToLeaderboard(/*...*/)
      .and(/*some other transaction*/)
      .then((builder) => builder.build());
```

## Contributing

The community is encouraged to contribute to the Soar SDK.

Fixes and features are always welcome! Please feel free to submit a PR for review.

### Tests.

Test files are located in `client/tests/*`. To run the tests, enter `anchor test` from the root directory of the repository.

---
_Source: https://npm.io/package/soar_sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
