Created
January 30, 2022 07:47
-
-
Save shobhitic/e396008231edf64992367f25d55a7781 to your computer and use it in GitHub Desktop.
Wallet Connect Integration Code - https://youtu.be/Ws5jIo4NMDc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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/[email protected]/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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it not working for now, Can anybody explain this problem