The following information is deprecated and may limit its use. Please refer to the WalletConnect 2.0 tab for the latest version of NEOPIN wallet integration: WalletConnect 2.0
Initiate Connection
Create a connector by putting the wallet connect bridge URL as 'bridge' props and attach an event to the connector.
import NeopinConnect from"nptconnect-client";import QRCodeModal from"nptconnect-qrcode-modal";// Create a connector object.constconnector=newNeopinConnect({ bridge:"https://bridge.walletconnect.org",// Required qrcodeModal: QRCodeModal });// Session created after connection. > Open the QRCodeModal passed to the connector param.if (!connector.connected) {connector.createSession();}const { accounts,chainId } =awaitconnector.connect();
After a connection is established (asynchronous), events are registered in the connector.
Accounts and chainID in the connector drop their values when they connect to the bridge server.
...const {accounts,chainId} = connector ;// accounts is arrayconstaddress= accounts[0];console.log(chainId)...
PeerMeta (Client Meta Data)
You can customize PeerMeta (ClientMeta) data.
The appID of PeerMeta data is issued when registering an affiliate, and the issued appID value must be used.
constclientMeta= { description: string; url: string; icons: string[]; name: string; appId?: string;}// When creating a connector object, pass it as clientMeta paramconstconnector=newNeopinConnect({ bridge:"https://bridge.walletconnect.org",// Required qrcodeModal: QRCodeModal, clientMeta // IClientMeta});// Type information of ClientMeta of nptconnect-typesexportinterfaceIClientMeta { description:string; url:string; icons:string[]; name:string; appId?:string;}
Send Transaction (eth_sendTransaction)
This is a method that creates and sends a transaction.
This is a method that can be executed when there is a value in the accounts of the connector (when a connection is established).
// to, nonce, gasPrice, gas, value, data are random data.// Each must be modified to suit its purpose.consttx= { from:"0xbc28Ea04101F03aA7a94C1379bc3AB32E65e62d3",// Required to:"0x89D24A7b4cCB1b6fAA2625Fe562bDd9A23260359",// Required (for non contract deployments) data:"0x",// Required chainId:"8217",// Required gasPrice:"0x02540be400",// Optional gasLimit:"0x9c40",// Optional value:"0x00",// Optional nonce:"0x0114",// Optional};// Send transactionconnector.sendTransaction(tx).then(result => {// Returns transaction id (hash)console.log(result); }).catch(error => {// Error returned when rejectedconsole.error(error); });
Sign Transaction (eth_signTransaction)
// Draft transactionconsttx= { from:"0xbc28Ea04101F03aA7a94C1379bc3AB32E65e62d3",// Required to:"0x89D24A7b4cCB1b6fAA2625Fe562bDd9A23260359",// Required (for non contract deployments) data:"0x",// Required gasPrice:"0x02540be400",// Optional gasLimit:"0x9c40",// Optional value:"0x00",// Optional nonce:"0x0114",// Optional};// Sign transactionconnector.signTransaction(tx).then(result => {// Returns signed transactionconsole.log(result); }).catch(error => {// Error returned when rejectedconsole.error(error); });