# @massalabs/as-types

> Massa AS types lib

Latest version **2.1.0** (published 2024-06-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @massalabs/as-types
pnpm add @massalabs/as-types
yarn add @massalabs/as-types
bun add @massalabs/as-types
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2024-06-06 |
| First published | 2022-12-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 105.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | glibert, aurelienft, damip, evgenip, qdr |

## Links

- npm: https://www.npmjs.com/package/@massalabs/as-types
- npm.io page: https://npm.io/package/@massalabs/as-types

## Dependencies (2)

- [as-bignum](https://npm.io/package/as-bignum.md) ^0.3.0
- [assemblyscript](https://npm.io/package/assemblyscript.md) ^0.27.18

## Recent versions

- 2.1.0 (latest) — 2024-06-06
- 2.1.1-dev.20240611142606 (dev) — 2024-06-11
- 2.0.0 (buildnet) — 2023-10-11
- 1.0.1 (testnet) — 2023-06-26
- 2.1.1-dev.20240611142528 — 2024-06-11
- 2.1.1-dev.20240606143326 — 2024-06-06
- 2.0.1-dev.20240606142538 — 2024-06-06
- 2.0.1-dev.20240529131344 — 2024-05-29
- 2.0.1-dev.20240529122344 — 2024-05-29
- 2.0.1-dev.20240524080933 — 2024-05-24
- 2.0.1-dev.20240521132240 — 2024-05-21
- 2.0.1-dev.20240510154659 — 2024-05-10
- 2.0.1-dev.20240322102305 — 2024-03-22
- 2.0.1-dev.20240322102220 — 2024-03-22
- 2.0.1-dev.20240219101218 — 2024-02-19
- … 147 more at https://npm.io/package/@massalabs/as-types/versions

## README

# as-types

**MassaLabs** as-types library.

This library provides useful *AssemblyScript* objects and functions to help you deal with types:

- **Amount** object to safely express amounts in every currency

- **Args** object to serialize assembly script native types into bytes

- **Currency** object to represent monetary units used to express a value

- **Result** object which represents wrapper for a value that can be either a success or an error

- **Serializable** an interface that allows you to use `Args` to serialize/de-serialize your objects

- **SafeMath** a module to avoid overflows and divisions by zero while doing operations

- Serialization and Deserialization methods for arrays, staticArrays, booleans, strings and numbers



The complete documentation of all available functions and objects is here:

- [`as-types documentation`](https://as-types.docs.massa.net)

## Warning
**Non-secure random functions are used here.**

Using non-secure random functions is the only way to have onchain randomness but **these functions do not generate truly random** values, making it easier for attackers to predict the output and exploit weaknesses in your smart contract.

## Install

Packages are independent you can choose to install what you need

```sh
npm i --save-dev @massalabs/as-types
```

## Usage
After installing *as-types*, you can import the object classes and functions that you need in your AssemblyScript file.

One way to use the "args" object is by importing and utilizing it in the following manner:
```typescript
import { Args, i32ToBytes } from  '@massalabs/as-types';

// This main function is called automatically when the smart contract is executed by the blockchain.
//the argument args contains the serialized values n and k as i32
export function sum(binaryArgs: StaticArray<u8>): StaticArray<u8>{
	const args = new  Args(binaryArgs);
	const  a = args.nextI32();
	const  b = args.nextI32();
	return i32ToBytes(a + b)
}
```
## Contributing
We welcome contributions from the community!

If you would like to contribute to Massa-as-sdk, please read the [CONTRIBUTING file](CONTRIBUTING.md).

## License
as-types is released under the [MIT License](LICENSE).

## Powered By
as-types is developed with love by MassaLabs and powered by a variety of [open-source projects](powered-by.md).

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