nptconnect-client
v1.0.13
Published
Client for NPT Connect
Downloads
27
Maintainers
Readme
NPTConnect Client
Client for NeopinConnect
Install
yarn add nptconnect-client
# OR
npm install --save nptconnect-client
Initiate Connection
import NeopinConnect from "nptconnect-client";
// Create a connector
const connector = new NeopinConnect({
bridge: "https://bridge.walletconnect.org", // Required
});
connector.on("session_update", (error, payload) => {
if (error) {
throw error;
}
// Get updated accounts and chainId
const { accounts, chainId } = payload.params[0];
});
connector.on("disconnect", (error, payload) => {
if (error) {
throw error;
}
// Delete connector
});
const { accounts, chainId } = await connector.connect();
get account & chainId
...
const {accounts, chainId} = connector ;
// accounts is array
const address = accounts[0];
console.log(chainId)
...
Send Transaction (eth_sendTransaction)
// Draft transaction
const tx = {
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
};
// Send transaction
connector
.sendTransaction(tx)
.then(result => {
// Returns transaction id (hash)
console.log(result);
})
.catch(error => {
// Error returned when rejected
console.error(error);
});
Sign Transaction (eth_signTransaction)
// Draft transaction
const tx = {
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 transaction
connector
.signTransaction(tx)
.then(result => {
// Returns signed transaction
console.log(result);
})
.catch(error => {
// Error returned when rejected
console.error(error);
});