Myria-Core-SDK
Myria core SDK to implement all of transaction and workflow for FE integration
Setup and installation
Git:
git clone git@gitlab.com:myriaworld/myrianet/blockchain/myria-core-sdk.git
Using npm:
npm install
Using yarn:
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
.
├── __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:
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
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:
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:
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:
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:
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:
yarn build
Build CJS:
yarn build:cjs
Build ESM:
yarn build:cjs
Build UMD:
yarn build:umd
Build UMD:
yarn build:umd
Build Types:
yarn build:types
Package module
Package modules:
yarn package
Lint & Test
Run test:
yarn test
Run test with coverage:
yarn test:cov
Publish to NPM
Publish to NPM
yarn publish
License
Myria Core Team
Project status
On development