# new WithdrawalModule(IMyriaClient)
Create WithdrawalModule instance object
Parameters:
Name | Type | Description |
---|---|---|
IMyriaClient |
IMyriaClient
|
Interface of Myria Client |
Methods
# async checkUserRegisterOnchain(starkKey) → {TxResult|undefined}
Function to check if user has registered on-chain with Starkware dedicated instance
Parameters:
Name | Type | Description |
---|---|---|
starkKey |
string
|
Public stark key of user |
On-chain transactions results information (block confirmed, transaction hash,....)
TxResult
|
undefined
# async getWithdrawalBalance(ownerKey, assetId) → {Promise.<TxResult>}
The function is to get the available fund for user to be withdraw in the L1 and it requests to StarkEx smart contract
Parameters:
Name | Type | Description |
---|---|---|
ownerKey |
string
|
The owner key of users (Wallet Address / Stark Key) where it locates the fund in the on-chain |
assetId |
string
|
The asset ID (hex string) to be represent for the tokens that we'd to check with the available balance for withdraw |
The transaction result data which is on-chain data object
Promise.<TxResult>
# async withdrawAndMint(withdrawalParams, optionsnullable) → {Promise.<TxResult>}
Withdraw and mint the assets NFTs (ERC_721) in the on-chain and send the NFTs/tokens to user
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
withdrawalParams |
WithdrawAndMintParams
|
Withdraw and mint params options |
|
options |
SendOptions
|
<nullable> |
The native options for transaction in Web3 |
Transaction results in the on-chain after withdraw and mint action
Promise.<TxResult>
# async withdrawNftComplete(payload) → {APIResponseType.<WithdrawNftCompleteResponse>|undefined}
As long as the NFTs has been completed with the on-chain withdraw and user receive the NFTs/tokens into their wallet (Metamask,etc...) This is one last step for tracking and notify to Myria service that this NFTs has been completed on withdraw process and the token is no longer existed in Myria system
Parameters:
Name | Type | Description |
---|---|---|
payload |
WithdrawNftCompleteParams
|
The payload for requesting the NFTs withdraw completed in Myria system |
The withdraw nft completion response from Myria services
APIResponseType.<WithdrawNftCompleteResponse>
|
undefined
# async withdrawNftOffChain(payload) → {APIResponseType.<WithdrawNftOffChainResponse>|undefined}
The withdraw nft off-chain actions to bring the NFTs to user's wallet (Metamask/Trust Wallet)
Parameters:
Name | Type | Description |
---|---|---|
payload |
WithdrawNftOffChainParams
|
Withdraw NFTs Off-chain params |
The withdraw NFT off-chain response including transaction details data
APIResponseType.<WithdrawNftOffChainResponse>
|
undefined
# async withdrawalOffchainV2(withdrawalParams) → {TransactionData}
The withdraw offchain function in V2
Parameters:
Name | Type | Description |
---|---|---|
withdrawalParams |
WithdrawOffchainParamsV2
|
Withdraw off-chain params input |
Exception: Sender starkKey is required!
string
Exception: Receiver eth address is required!
string
Exception: Quantum is required!
string
Exception: Amount is required!
string
Exception: Token Type is required.
string
Exception: Token Address is required!
string
Exception: Token ID is required!
string
Transactions data which indicate the transaction results, transaction details information (such as transactionID, transactionStatus...)
Example
const mClient: IMyriaClient = {
networkId: Network.GOERLI,
provider: web3Instance.currentProvider,
web3: web3Instance,
env: EnvTypes.STAGING,
};
const senderStarkKey = '0xfb....'; // Sample of sender stark public key
const senderEthAddress = '0x....'; // Sender wallet address
const QUANTUM_CONSTANT = 10000000000; // Quantum 10^10
const weiAmount = 1000000000000000000; // 1 ETH we can use this page to convert the ETH to wei: https://eth-converter.com/
const withdrawParamsV2: WithdrawOffchainParamsV2 = {
senderPublicKey: senderStarkKey,
senderEthAddress: senderEthAddress,
receiverPublicKey: senderEthAddress,
amount: String(weiAmount),
tokenType: TokenType.ETH, // tokenType is ETH if users want to withdraw ETH
quantum: QUANTUM_CONSTANT.toString(),
};
responseWithdraw = await withdrawModule.withdrawalOffchainV2(
withdrawParamsV2,
);
console.log('Transaction result -> ', result);