# myria-core-sdk-staging

> Latest version SDK

Latest version **0.0.1** (published 2022-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install myria-core-sdk-staging
pnpm add myria-core-sdk-staging
yarn add myria-core-sdk-staging
bun add myria-core-sdk-staging
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2022-07-27 |
| First published | 2022-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 22 |
| Unpacked size | 6.3 MB |
| Known vulnerabilities | 0 (+24 in 2 direct dependencies) |
| Install scripts | no |
| Author | MyriaCoreSDKTeam |
| Maintainers | khang.mai |
| Keywords | myria, typescript, npm, package |

## Links

- npm: https://www.npmjs.com/package/myria-core-sdk-staging
- npm.io page: https://npm.io/package/myria-core-sdk-staging

## Dependencies (22)

- [qs](https://npm.io/package/qs.md) ^6.10.3
- [web3](https://npm.io/package/web3.md) 1.3.0
- [axios](https://npm.io/package/axios.md) ^0.21.4
- [bn.js](https://npm.io/package/bn.js.md) ^5.2.1
- [https](https://npm.io/package/https.md) ^1.0.0
- [assert](https://npm.io/package/assert.md) ^2.0.0
- [big.js](https://npm.io/package/big.js.md) ^6.0.0
- [ethers](https://npm.io/package/ethers.md) ^5.6.4
- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [ts-node](https://npm.io/package/ts-node.md) ^10.7.0
- [@types/node](https://npm.io/package/@types/node.md) ^17.0.30
- [babel-eslint](https://npm.io/package/babel-eslint.md) ^10.1.0
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.0.1
- [@types/big.js](https://npm.io/package/@types/big.js.md) ^6.0.0
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.181
- [@types/elliptic](https://npm.io/package/@types/elliptic.md) ^6.4.12
- [starkware-crypto](https://npm.io/package/starkware-crypto.md) ^1.9.7
- [crypto-browserify](https://npm.io/package/crypto-browserify.md) ^3.12.0
- [stream-browserify](https://npm.io/package/stream-browserify.md) ^3.0.0
- [@babel/eslint-parser](https://npm.io/package/@babel/eslint-parser.md) ^7.17.0
- [eslint-plugin-no-only-tests](https://npm.io/package/eslint-plugin-no-only-tests.md) ^2.6.0
- [@starkware-industries/starkware-crypto-utils](https://npm.io/package/@starkware-industries/starkware-crypto-utils.md) ^0.0.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2022-07-27

## README

# Myria-Core-SDK

Myria core SDK to implement all of transaction and workflow for FE integration

## Setup and installation

Git: 

```bash
git clone git@gitlab.com:myriaworld/myrianet/blockchain/myria-core-sdk.git
```

Using npm: 
```bash
npm install
```

Using yarn:
```bash
yarn install
```

## Environment
SDK is integrated with core-service at stable environment(dev, staging) on core.
We can also checkout the core-service to make and debugging the integration locally in terms of testing.

## Structure Codebase
```bash
.
├── __tests__
│   ├── MyriaClient.ts
│   │
├── config
│   └── fileTransformer.js
│   └── tsconfig.cjs.json
│   └── tsconfig.esm.json
│   └── tsconfig.types.json
│   └── tsconfig.umd.json
│   └── webpack.config.js
│   │
├── dist (build folder)
│   │
├── src
│   ├── clients
│   │   ├── MyriaClient.ts
│   │
├── ├── contracts (abi)
│   │   └── Deposits.json
│   │   └── TokensAndRamping.json
│   │   └── Withdrawals.json
│   │
│   ├── core
│   │   ├── apis
│   │   │   └── Deposits.json
│   │   └── axios
│   │   │   └── error.ts
│   │   │   └── index.ts
│   │   │   └── request-helpers.ts
│   │   │
│   │   └── Contract.ts
│   │   └── ContractFactory.ts
│   │   └── ContractHelpers.ts
│   │   └── DepositContract.ts
│   │   └── WithdrawalContract.ts
│   │
│   ├── modules
│   │   └── DepositModule.ts
│   │   └── WithdrawModule.ts
│   │   └── ModuleFactory.ts
│   │   └── index.ts
│   │
│   ├── types
│   │   └── CommonTypes.ts
│   │   └── ContractTypes.ts
│   │   └── index.ts
├── tools
│   └── cleanup.ts
...
```


## Usage and Example


Deposit ETH transaction for both onchain and offchain:

```javascript

    const initializeClient: IMyriaClient = {
      provider: web3Instance.currentProvider,
      networkId: 5,
      web3: web3Instance
    };

    const moduleFactory = new Modules.ModuleFactory(initializeClient);
    const depositModule = moduleFactory.getDepositModule();


    const amount = Web3.utils.toWei("0.00001");
    const result = await depositModule.depositEth(
      {
        starkKey: '0x' + starkPublicKey,
        tokenType: TokenType.ETH,
        amount
      },
      {
        confirmationType: Types.ConfirmationType.Sender,
        from: accounts[0], 
        value: amount,
      }
    );

```

Deposit ERC20 tokens to Myria L2 Wallets
```javascript

    const initializeClient: IMyriaClient = {
      provider: web3Instance.currentProvider,
      networkId: 5,
      web3: web3Instance
    };

    const moduleFactory = new Modules.ModuleFactory(initializeClient);
    const depositModule = moduleFactory.getDepositModule();
    const quantizedAmount = '11';

    const result = await depositModule.depositERC20Token(
      {
        starkKey: '0x' + starkPublicKey,
        tokenAddress: '0x1b335FD6c49b360D8A7104FCc6c26C28111fC3FC',
        tokenType: TokenType.ERC20,
        quantizedAmount: quantizedAmount,
      },
      {
        from: accounts[0],
      }
    );

```

In case for another third-party want to call directly with onchain transaction ,we can use the contract instance.

Deposit Eth:

```javascript
    const myriaClient: IMyriaClient = {
      provider: web3Instance.currentProvider,
      networkId: 5, // GOERLI NETWORK/ OTHERS/ MAINNET
      web3: web3Instance
    };
    const contractFactory = new ContractFactory(myriaClient);
    const depositContract = contractFactory.getDepositContract();

    const vaultId = '1';

    const result = await depositContract.depositEth(
      '0x' + starkPublicKey,
      assetType,
      vaultId,
      {
        from: accounts[0], 
      }
    );
```

Deposit ERC20 Token:
```javascript
const assetType = asset.getAssetType({
      type: 'ERC20',
      data: {
        quantum: '1',
        tokenAddress: '0x0eD03E6917543a45af099909f07bC5b4C69E868A',
      }
    });

    const initializeClient: IMyriaClient = {
      provider: web3Instance.currentProvider,
      networkId: 5,
      web3: web3Instance
    };

    const myriaClient = new MyriaClient(initializeClient);
    const contractFactory = new ContractFactory(myriaClient);
    const depositContract = contractFactory.getDepositContract();

    const vaultID = '2';

    const result = await depositContract.depositERC20(
      '0x' + starkPublicKey,
      assetType,
      vaultID,
      '1',
      {
        from: accounts[0], 
      }
    );
```
Withdraw and mint:

```javascript
      const assetType = asset.getAssetType({
      type: 'MINTABLE_ERC721',
      data: {
        quantum: '1',
        tokenAddress: '0xD5f1cC0264d0E22BE4488109dbf5d097eb37a576',
      }
    });
  
    const initializeClient: IMyriaClient = {
      provider: web3Instance.currentProvider,
      networkId: 5,
      web3: web3Instance
    };

    const moduleFactory = new Modules.ModuleFactory(initializeClient);
    const withdrawModule = moduleFactory.getWithdrawModule();

    const result = await withdrawModule.withdrawAndMint(
      {
        starkKey: '0x' + starkPublicKey,
        tokenType: TokenType.MINTABLE_ERC721,
        tokenAddress: '0xD5f1cC0264d0E22BE4488109dbf5d097eb37a576',
        assetType: assetType,
        mintingBlob: ''
      },
      {
        confirmationType: Types.ConfirmationType.Sender,
        nonce: '1',
        from: accounts[0]
      }
    );
```


Withdraw offchain:

```javascript
    const assetType = asset.getAssetType({
      type: 'ETH',
      data: {
        quantum: '1',
      }
    });

    const amount = Web3.utils.toWei("0.00001");
  
    const initializeClient: IMyriaClient = {
      provider: web3Instance.currentProvider,
      networkId: 5,
      web3: web3Instance
    };

    const moduleFactory = new Modules.ModuleFactory(initializeClient);
    const withdrawModule = moduleFactory.getWithdrawModule();

    const result = await withdrawModule.withdrawalOffchain(
      {
        starkKey: '0x' + starkPublicKey,
        tokenType: TokenType.ETH,
        amount,
        tokenAddress: '',
        vaultId: undefined,
        assetId: assetType,
        tokenId: '',
      },
      {
        from: accounts[0],
        nonce: '1',
        confirmationType: Types.ConfirmationType.Sender,
      }
    );
```

## Build command

Global build:

```bash
  yarn build
```

Build CJS:

```bash
  yarn build:cjs
```

Build ESM:

```bash
  yarn build:cjs
```

Build UMD:

```bash
  yarn build:umd
```

Build UMD:

```bash
  yarn build:umd
```

Build Types:

```bash
  yarn build:types
```

## Package module

Package modules:

```bash
  yarn package
```

## Lint & Test

Run test:

```bash
  yarn test 
```

Run test with coverage:

```bash
  yarn test:cov 
```

## Publish to NPM

Publish to NPM 

```bash
  yarn publish
```


## License
Myria Core Team

## Project status

On development

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