1.1.6 • Published 2 years ago

@waves/provider-metamask v1.1.6

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

ProviderMetamask

Overview

ProviderMetamask

Getting Started

1. Library installation

To install Signer and ProviderMetamask libraries use

npm i @waves/signer @waves/provider-metamask

2. Library initialization

Add library initialization to your app.

  • For Stagenet:

    	```js
    	import { Signer } from '@waves/signer';
    	import { ProviderMetamask } from '@waves/provider-metamask';
    
    	const signer = new Signer({
    		// Specify URL of the node on Stagenet
    		NODE_URL: 'https://nodes-stagenet.wavesnodes.com'
    	});
    	const provider = new ProviderMetamask({
    		wavesConfig: {
    			nodeUrl: 'https://nodes-stagenet.wavesnodes.com',
    			chainId: 'S'.charCodeAt(0)
    		}
    	});
    	signer.setProvider(provider);
    	```
  • For Mainnet:

    	```js
    	import { Signer } from '@waves/signer';
    	import { ProviderMetamask } from '@waves/provider-metamask';
    
    	const signer = new Signer();
    	const provider = new ProviderMetamask();
    	signer.setProvider(provider);
    	```

3. Basic example

Now your application is ready to work with Waves Platform. Let's test it by implementing basic functionality. For example, we could try to authenticate user and transfer funds.

const user = await signer.login();
const [transfer] = await signer
  .transfer({
	amount: 1,
	recipient: 'alias:T:merry',
  })
  .broadcast();
const user = await signer.login();
const [invoke] = await signer
  .invoke({
	dApp: "3F4bY4PsS8E1tShx9ruSYthie3uzYiSffSv",
	call:{
		 function: "deposit",
		 args:[{ type: "string", value: "string" }]
	},
	payment:[]
  })
  .broadcast();

For more information see Signer documentation.

4. How to sign order

Set the order parameters:

  • Omit senderPublicKey.
  • Specify asset IDs in Waves format: 32 bytes in base58. For WAVES use the string WAVES.
const orderData = {
  orderType: 'sell',
  version: 4,
  assetPair: {
	amountAsset: '8KTfWNoWYf9bP3hg1QYBLpkk9tgRb5wiUZnT1HUiNa9r',
	priceAsset: 'WAVES',
  },
  price: 100000,
  amount: 100000,
  timestamp: 1634563969123,
  expiration: 1637069590926,
  matcherFee: 300000,
  matcherFeeAssetId: null,
};
const provider = new ProviderMetamask();
const sign = await provider.signOrder(orderData);

5. How to get Ethereum address

import { ProviderMetamask } from '@waves/provider-metamask';
import { wavesAddress2eth } from '@waves/node-api-js';

const user = await signer.login();
const ethereumAddress = wavesAddress2eth(user.address);

6. How to sign message

const message = 'message text';
const provider = new ProviderMetamask();
const sign = await provider.signMessage(message);
1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.9

3 years ago

0.0.16

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago