Last active
July 4, 2020 05:24
-
-
Save saitejach127/9794f4d3622bd65bd9d14f14ba1a93ff to your computer and use it in GitHub Desktop.
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
var WalletConnect = require("@walletconnect/node"); | |
/* | |
Tried using | |
"@walletconnect/browser": "^1.0.0-beta.47", | |
"@walletconnect/client": "^1.0.11", | |
"@walletconnect/node": "^1.0.0", | |
but no use | |
*/ | |
var WalletConnectQRCodeModal = require("@walletconnect/qrcode-modal"); | |
WalletConnect = WalletConnect.default; | |
WalletConnectQRCodeModal = WalletConnectQRCodeModal.default; | |
window.WalletConnect = WalletConnect; | |
window.WalletConnectQRCodeModal = WalletConnectQRCodeModal; | |
// Create a connector | |
const connector = new WalletConnect( | |
{ | |
bridge: "https://bridge.walletconnect.org", // Required | |
}, | |
{ | |
clientMeta: { | |
description: "WalletConnect NodeJS Client", | |
url: "https://nodejs.org/en/", | |
icons: ["https://nodejs.org/static/images/logo.svg"], | |
name: "WalletConnect", | |
}, | |
} | |
); | |
window.connector = connector; | |
// Check if connection is already established | |
if (!connector.connected) { | |
connector.createSession().then(() => { | |
// get uri for QR Code modal | |
const uri = connector.uri; | |
// display QR Code modal | |
WalletConnectQRCodeModal.open(uri, () => { | |
}); | |
//return uri; | |
}); | |
} | |
// Subscribe to connection events | |
connector.on("connect", (error, payload) => { | |
if (error) { | |
throw error; | |
} | |
// Get provided accounts and chainId | |
const { accounts, chainId } = payload.params[0]; | |
console.log(accounts, chainId); | |
WalletConnectQRCodeModal.close(); | |
update(); | |
toggletutorial(); | |
}); | |
connector.on("session_update", (error, payload) => { | |
if (error) { | |
throw error; | |
} | |
// Get updated accounts and chainId | |
const { accounts, chainId } = payload.params[0]; | |
update(); | |
}); | |
connector.on("disconnect", (error, payload) => { | |
if (error) { | |
throw error; | |
} | |
console.log("disconnected"); | |
// Delete connector | |
}); | |
// Signin works perfectly with QR code and metamask wallet app | |
var tx = { | |
from: "0xAd111A7860a7e39D9943D96A8Acb85a132F718Ed", | |
to: "0x23490eA92D4d3532A18737AC7e6B3767A7dc49Af", | |
gas: 850000, | |
gaslimit: 500000, | |
nonce: parseInt(nonce) , | |
value: '0x00', | |
data: data.encodeABI() | |
} | |
// The below line doesnt send any message to the mobile wallet | |
connector.signTransaction(tx) | |
.then((signedTx) => { | |
console.log(signedTx) | |
}); | |
// The below line shows Error : [object Object] | |
connector.sendTransaction(tx) | |
.then((res) => { | |
console.log(res); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above output occurs for running the code