@massalabs/wallet-provider v2.0.0
Wallet-provider
Wallet-provider
is a TypeScript library that one could utilize to establish a connection between a frontend application and any browser wallet extensions that implement the massa standard. With this library one can access all massa-blockchain wallets and their standardized functionalities for ready use.
Usage
Wallet-provider
could be used as a library for frameworks or as a stand-alone bundled js file which can be easily loaded into the browser.
Library (Node.js/React/Vue.js) usage
npm install @massalabs/wallet-provider
Browser usage
Add the following script to your html file:
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/@massalabs/wallet-provider@x.x.x/bundle.js"
></script>
whereby the x.x.x is one of the available released versions under Wallet-provider's releases page.
In your code, once the script is fully loaded, just use window.wallet
to access all wallet-provider
's' exported functionalities.
<script>
const providers = window.massa.providers();
console.log("Massa Providers ", providers);
</script>
Documentation
Wallet-provider provides complete documentation of all available functions and objects.
To generate the documentation for a specific branch, run the following command:
npm run doc
The documentation will be generated in the docs/documentation/html
directory.
Web3 Wallet Provider Requirement and Initialization
Requirements
NodeJS 16+
npm / yarn (see package.json)
Initialization
Run
npm install
to install all dependenciesRun
npx playwright install --with-deps
to install playwright and its dependenciesRun
npm run build
to build distribution contentRun
npm run test
to run integration and unit tests
The library exports a function called providers
which can be executed to return a vector of all massa-wallet providers currently initialized in the space. As shown below in the example code, each provider has its own callable methods for listing, importing and deleting accounts. Each account can return its name, address and has methods to retrieve its balance and sign a data array.
import { providers } from "@massalabs/wallet-provider";
// get all available massa-wallet providers
const providers = providers();
// get a provider
const myProvider = providers[0];
console.log("Provider Name", myProvider.name());
// import an account via the massa-wallet provider
console.log("Importing an account ...");
const privateKey = "Sxxxxxxxxxxxxxx";
const publicKey = "Pxxxxxxxxxxxxxxx";
await myProvider.importAccount(publicKey, privateKey);
// get accounts
console.log("Retrieving the accounts ...");
const myAccounts = await myProvider.accounts();
console.log("Provider accounts ...", myAccounts);
// getting one account
const myAccount = myAccounts[0];
console.log("Account address ", myAccount.address());
// getting account balance
console.log("Retrieving the account balance ...");
const accountBalance = await myAccount.balance();
console.log("Account Balance = ", accountBalance.balance);
// signing a message
console.log("Signing a message ...");
const signature = await myAccount.sign([0, 1, 2]);
console.log("Signature = ", signature);
// deleting an account
console.log("Deleting an account ...");
await myProvider.importAccount(myAccount.address());
Contributing
We welcome contributions from the community!
If you would like to contribute to Wallet Provider, please read the CONTRIBUTING file.
16 days ago
30 days ago
30 days ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
10 months ago
9 months ago
10 months ago
10 months ago
6 months ago
9 months ago
9 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
6 months ago
8 months ago
9 months ago
10 months ago
9 months ago
7 months ago
8 months ago
10 months ago
9 months ago
7 months ago
8 months ago
9 months ago
10 months ago
10 months ago
8 months ago
10 months ago
9 months ago
8 months ago
9 months ago
7 months ago
10 months ago
10 months ago
10 months ago
9 months ago
8 months ago
8 months ago
6 months ago
9 months ago
9 months ago
9 months ago
6 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
9 months ago
6 months ago
9 months ago
8 months ago
9 months ago
7 months ago
10 months ago
9 months ago
8 months ago
8 months ago
10 months ago
9 months ago
8 months ago
7 months ago
9 months ago
9 months ago
10 months ago
9 months ago
9 months ago
10 months ago
9 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
11 months ago
11 months ago
12 months ago
12 months ago
11 months ago
12 months ago
1 year ago
1 year ago
1 year ago