manta-signer-interface
v0.0.21
Published
JS interface for interacting with Manta Signer
Downloads
22
Readme
Manta Signer Interface
An interface to simplify interacting with Manta Signer
Installation
yarn add manta-signer-interface
Usage
Initialization
// get an instance of polkadot.js api
import { ApiPromise, WsProvider } from '@polkadot/api';
const api = new ApiPromise({ provider, types, rpc: jsonrpc });
await api.isReady;
// Get some subclass of AddressStore depending on use case
// Browser address store for web app, memory address store for cli testing, or your own implementation
import { MemoryAddressStore };
const addressStore = MemoryAddressStore.testnet();
const signerInterface = new SignerInterface(api, addressStore);
Recovering (or refreshing) a wallet
// returns an array of ClientAsset
const myRecoveredAssets = signerInterface.recoverAccount();
Doing a private transfer (or reclaim, similarly)
// The transfer you want to do
const assetId = 1;
const targetValue = 100;
const receivingAddress = "AAAAAAABBBBBBCCCCCCCDDDDDD...";
// install 'manta-coin-selection' with yarn
import { selectCoins, CoinSelection } from 'manta-coin-selection';
// returns a `CoinSelection`, which contains the selected coins and associated metadata
const coinSelection = selectCoins(
targetValue, myRecoveredAssets.filter(asset => asset.assetId === assetId)
);
const transaction = await signerInterface.buildExternalPrivateTransferTxs(
receivingAddress, coinSelection
);
// Submit the transaction using polkadot.js
// wait ...
// If transaction fails, run:
signerInterface.cleanupTxFailure();
// If transaction succeeds, run:
signerInterface.cleanupTxSuccess();