Quick Start
Installing Webmavryk using npmโ
For quick-start, you may also like to try out our template/boilerplate app here
The following instructions assume you have a project already created, and you have npm installed and operable.
npm install @mavrykdynamics/webmavryk
Import the library in your projectโ
Import MavrykToolkit from @mavrykdynamics/webmavryk and instantiate itโ
The constructor of the MavrykToolkit class takes an RPC URL as a parameter. It can be a string or a RpcClient object. A list of community-run nodes can be accessed here.
import { MavrykToolkit } from '@mavrykdynamics/webmavryk';const mavryk = new MavrykToolkit('https://YOUR_PREFERRED_RPC_URL');
In some cases, it can be useful to make more than one instance of Webmavryk, perhaps if you wanted to communicate with two different RPC nodes or offer other Signing options. You can now up separate instances with various providers or configurations per instance.
Configurationโ
Changing the underlying signerโ
Webmavryk's Contract API supports different signers. There is no default signer configured. A signer is required if you intend to inject operations into the Mavryk blockchain.
You can set which signer you wish to use as follows:
import { MavrykToolkit } from '@mavrykdynamics/webmavryk';import { RemoteSigner } from '@mavrykdynamics/webmavryk-remote-signer';const Mavryk = new MavrykToolkit('https://YOUR_PREFERRED_RPC_URL');Mavryk.setProvider({signer: new RemoteSigner(pkh, rootUrl, { headers: requestHeaders });,});
Alternatively, you can use a WalletProvider to interact with a wallet. Please refer to the Wallet API documentation for more information.
Examplesโ
Get the current Mavryk spendable balance for an addressโ
Using the inMemory Signer and Importing a keyโ
The InMemorySigner package is useful for development and testing. It's an easy way to get started with Mavryk when you don't need to interact with a user's wallet. The InMemorySigner is suitable for testing and development. Should you be writing code for production that deals with real value tokens, we strongly recommend that you use a RemoteSigner that an HSM backs.
This feature will import your private key in memory and sign operations using this key.
Importing a Private keyโ
If you have a private key, you can import it as follows:
import { MavrykToolkit } from '@mavrykdynamics/webmavryk';import { InMemorySigner, importKey } from '@mavrykdynamics/webmavryk-signer';const Mavryk = new MavrykToolkit('https://YOUR_PREFERRED_RPC_URL');Mavryk.setProvider({signer: new InMemorySigner('YOUR_PRIVATE_KEY'),});
The following link can be used to fund an address on the different testnets: https://teztnets.com/.
Transferโ
The transfer operation requires a configured signer. In this example, we will use a private key to fetch a key service implemented for demonstration purposes. You should only use this key service for testing and development purposes.
- Contract API
- Wallet API
Interact with a smart contractโ
Calling smart contract operations requires a configured signer. The Ligo source code for the smart contract KT1BJadpDyLCACMH7Tt9xtpx4dQZVKw9cDF7 used in this example can be found in a Ligo Web IDE.
- Contract API
- Wallet API