Skip to content

Instantly share code, notes, and snippets.

@shobhitic
Created January 30, 2022 07:47
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save shobhitic/e396008231edf64992367f25d55a7781 to your computer and use it in GitHub Desktop.
Save shobhitic/e396008231edf64992367f25d55a7781 to your computer and use it in GitHub Desktop.
Wallet Connect Integration Code - https://youtu.be/Ws5jIo4NMDc
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Wallet Connect</title>
<script src="https://cdn.jsdelivr.net/npm/@walletconnect/web3-provider@1.7.1/dist/umd/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
</head>
<body>
<button onclick="connectWC()">Connect Wallet Connect</button>
<script type="text/javascript">
var account;
// https://docs.walletconnect.com/quick-start/dapps/web3-provider
var provider = new WalletConnectProvider.default({
rpc: {
1: "https://cloudflare-eth.com/", // https://ethereumnodes.com/
137: "https://polygon-rpc.com/", // https://docs.polygon.technology/docs/develop/network-details/network/
// ...
},
// bridge: 'https://bridge.walletconnect.org',
});
var connectWC = async () => {
await provider.enable();
// Create Web3 instance
const web3 = new Web3(provider);
window.w3 = web3
var accounts = await web3.eth.getAccounts(); // get all connected accounts
account = accounts[0]; // get the primary account
}
var sign = async (msg) => {
if (w3) {
return await w3.eth.personal.sign(msg, account)
} else {
return false
}
}
var contract = async (abi, address) => {
if (w3) {
return new w3.eth.Contract(abi, address)
} else {
return false
}
}
var disconnect = async () => {
// Close provider session
await provider.disconnect()
}
var address = "0x4b4f8ca8fb3e66b5ddafcebfe86312cec486dae1"
var abi = [{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"increment","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
</script>
</body>
</html>
@pauloreis7
Copy link

It is working too well, please launch a version using react!!

@laxmikantasahoo1997
Copy link

please launch this module using react js

@kapilchandekar
Copy link

please launch this module using react.js

@Awaistahirpro
Copy link

please launch with react js

@lingjianrui
Copy link

Well well done ! . Simple! Easy! Just one file ! Use any file service can host it. Thanks a million!

@shobhitic
Copy link
Author

For everyone asking to create a react version, walletconnect repository supports react directly but they had no documentation on vanilla JS. Check their repo for react version.

@smithego
Copy link

is not working again

@NGUYENDANGVU-coder
Copy link

it not working for now, Can anybody explain this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment