Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/web3w/web3-provider
Wallet Connect Client compatible with Web3.js and ethers.js
https://github.com/web3w/web3-provider
ethereum ethersjs walletconnect web3js
Last synced: 5 days ago
JSON representation
Wallet Connect Client compatible with Web3.js and ethers.js
- Host: GitHub
- URL: https://github.com/web3w/web3-provider
- Owner: web3w
- License: mit
- Created: 2022-06-26T05:14:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-05T11:41:28.000Z (about 2 years ago)
- Last Synced: 2024-08-11T09:55:18.366Z (3 months ago)
- Topics: ethereum, ethersjs, walletconnect, web3js
- Language: TypeScript
- Homepage: https://web3w.github.io/web3-provider
- Size: 14.4 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# web3-provider
Wallet Connect Client compatible with Web3.js and ethers.jsexample: https://web3w.github.io/web3-provider/
##install
`npm i web3-signer-provider`
node 18
`NODE_OPTIONS=--openssl-legacy-provider`## For ethers.js
### connect
```ts
import {WalletProvider} from 'web3-signer-provider'
public connect = async () => {
const provider = new WalletProvider({qrcodeModal: QRCodeModal, bridge});
const ethersSigner = new ethers.providers.Web3Provider(provider).getSigner()
if (!provider.connected) {
await provider.connect();
}
// subscribe to events
provider.on("connect", (error, payload) => {
if (error) {
throw error;
}
this.onConnect(payload);
});
provider.on("disconnect", (error, payload) => {
if (error) {
throw error;
}
this.onDisconnect();
});
};
```
### signMessage
```ts
public testStandardSignMessage = async () => {
const {address, ethersSigner, chainId} = this.state;if (!ethersSigner) {
return;
}// test message
const message = `My email is [email protected] ethers.js - ${new Date().toUTCString()}`;
try {
const result = await ethersSigner.signMessage(message);// verify signature
const hash = hashMessage(message);
const valid = await verifySignature(address, result, hash, chainId);
const formattedResult = {
method: "eth_sign (standard)",
address,
valid,
result,
};
} catch (error) {
console.error(error);
}
};
```
### close
```ts
public killSession = async () => {
const {provider} = this.state;
if (provider) {
provider.close();
}
this.resetApp();
};
```## For web3.js
### connect
```ts
import {WalletProvider} from 'web3-signer-provider'
public connect = async () => {
const provider = new WalletProvider({qrcodeModal: QRCodeModal, bridge});
const web3Signer = new Web3(provider)if (!provider.connected) {
await provider.connect();
}
// subscribe to events
provider.on("connect", (error, payload) => {
if (error) {
throw error;
}
this.onConnect(payload);
});provider.on("disconnect", (error, payload) => {
if (error) {
throw error;
}
this.onDisconnect();
});
};
```
### signMessage
```ts
public testStandardSignMessage = async () => {
const {address, ethersSigner, chainId} = this.state;if (!ethersSigner) {
return;
}// test message
const message = `My email is [email protected] ethers.js - ${new Date().toUTCString()}`;
try {
const result = await web3Signer.eth.signMessage(msgParams);// verify signature
const hash = hashMessage(message);
const valid = await verifySignature(address, result, hash, chainId);
const formattedResult = {
method: "eth_sign (standard)",
address,
valid,
result,
};
} catch (error) {
console.error(error);
}
};
```### cloes
```ts
public killSession = async () => {
const {provider} = this.state;
if (provider) {
provider.close();
}
this.resetApp();
};
```## Test
`export NODE_OPTIONS=--openssl-legacy-provider`