Comment on page
Functions
Descriptions of NEOPIN Connect functions
Type | Descriptions |
---|---|
| |
| |
| |
| |
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))). |
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
}
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 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
}
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
}
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.
Network | MainNet | TestNet |
---|---|---|
Klaytn | 8217 | 1001 |
Polygon | 137 | 80001 |
- 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(
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 SignTransaction are forwarded to ConnectManager.wcResultResponse Listener.
ConnectManager.wcResultResponse = { peerId, requestId, payload ->
val instance = ConnectManager.getInstance()
// TODO
}
- 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 modified 9mo ago