Functions

Descriptions of NEOPIN Connect functions

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

TypeDescriptions
  • setClient(wcSession: WCSession, peerMeta: WCPeerMeta): Creates and receives WCSession, WCPeerMeta, connects the Bridge Server, and creates an Instance with the connected session.

  • requestSession(id: String): Requests a session connection to the Wallet by calling requestSession (wc_sessionRequest) with the peerId received during connect.

  • wcConnect Listener: Called when connecting to the Bridge Server.

  • wcSessionApprove Listener: Called when a connection with the Wallet is complete.

  • wcSessionReject Listener: Called when connection with the Wallet fails.

  • disconnect(): Calls KillSession(wc_sessionUpdate approved=false) if there is a connected session, and disconnects WebSocket if WebSocket is open.

  • wcDisconnect Listener: Called when a Disconnect request (KillSession request) is received, or when a SocketException error occurs.

  • getAccounts(): When sessionApprove is reached, userAddress and network(ChainId) are set. If you want to check again while connected, you can check again by sending getAccounts (get_accounts) to your wallet.

  • wcResultResponse Listener: Receives success or failure response values.

  • sendTransaction(transaction: WCEthereumTransaction): Creates and transmits WCEthereumTransaction data to the Wallet to execute a transaction.

  • wcResultResponse Listener: Receives success or failure response values. This value is the return hash value of the executed contract when the transaction is successful.

Signs a transaction that can be submitted to the network

The sign method calculates an Ethereum specific signature with:sign(keccack256("\x19Ethereum Signed Message:\n" + len(message) + message))).

Connect

Create a Session with DeepLink structure to open a Socket and connect to BridgeServer.

ConnectManager.setClient(
    wcSession = WCSession(
        bridge = "https://wc-bridge.neopin.io/",
    ),
    peerMeta = WCPeerMeta(
        appId = "NWC1004HS6VFTPPPLUGFQBQ5SFNWB79B",
        name = "Dapp Sample",
        url = "https://www.sample.com/",
        description = "Dapp Platform",
        icons = listOf(""),
    )
)

When the BridgeServer is connected, events are forwarded to the ConnectManager.wcConnect Listener. When the connection is confirmed, send requestSession(wc_sessionRequest). Call WalletSample via DeepLink.

ConnectManager.wcConnect = { peerId, session ->
    ConnectManager.requestSession(peerId)
    startActivity(Intent(
        Intent.ACTION_VIEW,
        Uri.parse(session.toUri())
    ))
}

Touching the Connect button in WalletSample sends an event to the DAppSample's ConnectManager.wcSessionApprove Listener. When canceled, an event is forwarded to ConnectManager.wcSessionReject Listener.

ConnectManager.wcSessionApprove = { peerId, requestId, accounts ->
    val instance = ConnectManager.getInstance()
    // TODO
}
ConnectManager.wcSessionReject = { peerId, requestId, payload ->
    val instance = ConnectManager.getInstance()
    // TODO
}

Connect using QRCode

Create a Session with DeepLink structure to open a Socket and connect to BridgeServer.

ConnectManager.setClient(
    wcSession = WCSession(
        bridge = "https://wc-bridge.neopin.io/",
    ),
    peerMeta = WCPeerMeta(
        appId = "NWC1004HS6VFTPPPLUGFQBQ5SFNWB79B",
        name = "Dapp Sample",
        url = "https://www.sample.com/",
        description = "Dapp Platform",
        icons = listOf(""),
    )
)

When the BridgeServer is connected, events are forwarded to the ConnectManager.wcConnect Listener. When the connection is confirmed, send a requestSession(wc_sessionRequest). Use DeepLink to generate a QRCode image and display it on the screen. Run WalletSample and scan the QRCode.

ConnectManager.wcConnect = { peerId, session ->
    ConnectManager.requestSession(peerId)
    QrCodeDialog(session.toUri()).let { dialog ->
        qrCodeDialog = dialog
        dialog.show(supportFragmentManager, dialog.tag)
    }
}

Touching the Connect button in WalletSample sends an event to the DAppSample's ConnectManager.wcSessionApprove Listener. When canceled, an event is forwarded to ConnectManager.wcSessionReject Listener. When sessionApprove is reached, the QRCode image is removed from the screen.

ConnectManager.wcSessionApprove = { peerId, requestId, accounts ->
    qrCodeDialog?.dismiss()
    val instance = ConnectManager.getInstance()
    // TODO
}
ConnectManager.wcSessionReject = { peerId, requestId, payload ->
    val instance = ConnectManager.getInstance()
    // TODO
}

Disconnect

Disconnect from DApp: Call ConnectManager.disconnect().

ConnectManager.disconnect()

Disconnect from Wallet: When disconnected from Wallet, an event is forwarded to ConnectManager.wcDisconnect Listener.

ConnectManager.wcDisconnect = { peerId ->
    // TODO
}

GetAccount

Method to check the Address and ChainId of the currently connected Wallet.

Call ConnectManager.getAccounts().

ConnectManager.getAccounts()

The event is forwarded to ConnectManager.wcResultResponse Listener.

ConnectManager.wcResultResponse = { peerId, requestId, payload ->
    val instance = ConnectManager.getInstance()
    // TODO
}

SendTransaction

Method to communicate with Wallet.

To use NEOPIN Connect eth_sendTransaction in DApp, the following procedure is required.

Create and send a WCEthereumTransaction object to ConncetManager.sendTransaction(). You have to create and insert the data that goes into WCEthereumTransaction yourself.

val instance = ConnectManager.getInstance()
// to, nonce, gasPrice, gas, value, data are arbitrary data.
// Each should be modified according to its purpose.
ConnectManager.sendTransaction(
    WCEthereumTransaction(
        
chainId = "8217",
        from = instance?.userAddress ?: "0x0",
        to = "0x0", // Contract Address
        nonce = "0x0001",
        gasPrice = "0x9184e72a000",
        gas = "0x76c0",
        value = "0x0",
        data = "0xa9059cbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    )
)

The success and failure results of SendTransaction are forwarded to ConnectManager.wcResultResponse Listener.

ConnectManager.wcResultResponse = { peerId, requestId, payload ->
    val instance = ConnectManager.getInstance()
    // TODO
}
  • When creating a Client.Transaction object for SendTransaction, specify the ChainID of the target network. (*Required)

  • NEOPIN Connect supports a variety of networks, so specifying a chainID is required.

NetworkMainNetTestNet

Klaytn

8217

1001

Polygon

137

80001

SignTransaction

  • Transfer to the NEOPIN Wallet.

    • Please create a Transaction object after checking Address(From, To).

    • After sending the Transaction to the Wallet, you can receive Response only when the wallet gives a response value.

  • Signs a transaction that can be submitted to the network

val instance = ConnectManager.getInstance()
// to, nonce, gasPrice, gas, value, data are arbitrary data.
// Each should be modified according to its purpose.
ConnectManager.signTransaction(
    WCEthereumTransaction(
        ,
        from = instance?.userAddress ?: "0x0",
        to = "0x0", // Contract Address
        nonce = "0x0001",
        gasPrice = "0x9184e72a000",
        gas = "0x76c0",
        value = "0x0",
        data = "0xa9059cbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    )
)

The success and failure results of SignTransaction are forwarded to ConnectManager.wcResultResponse Listener.

ConnectManager.wcResultResponse = { peerId, requestId, payload ->
    val instance = ConnectManager.getInstance()
    // TODO
}

PersonalSign

  • The sign method calculates an Ethereum specific signature with:sign(keccack256("\\x19Ethereum Signed Message:\\n" + len(message) + message))).

  • Adding a prefix to the message makes the calculated signature recognisable as an Ethereum specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim.

  • Note See ecRecover to verify the signature.

val instance = ConnectManager.getInstance()

ConnectManager.personalSign("message".encodeHex())

The success and failure results of PersonalSign are forwarded to ConnectManager.wcResultResponse Listener.

ConnectManager.wcResultResponse = { peerId, requestId, payload ->
    val instance = ConnectManager.getInstance()
    // TODO
}

Last updated