npm install status-js-api
Alternatively, you can use yarn
.
This package requires geth
, status-go
, or murmur
to be able to connect to Whisper v6.
geth
Use the following command and flags to start geth
$ geth --testnet --syncmode=light --ws --wsport=8546 --wsaddr=localhost --wsorigins=statusjs --rpc --maxpeers=25 --shh --shh.pow=0.002 --wsapi=web3,shh,admin
Also, due to the lack of nodes with Whisper enabled, you need to create a static-nodes.json file, that must be placed in a specific path (if using ropsten
in a linux environment, ~/.ethereum/testnet/geth/static-nodes.json
murmur
$ murmur-client --ws --no-bridge
See murmur
documentation for additional details.
status-go
$ /path/to/status-go/statusd
See status-go
documentation for additional details.
Constructs a new status client object
new StatusJS();
// basic instantiation
const StatusJS = require('status-js-api');
const status = new StatusJS();
Connect to a web3 whisper provider
status.connect(url, [privateKey]);
await status.connect("ws://localhost:8546", "0x1122...9900");
Arguments
Connect to a custom web3 whisper provider
status.connectToProvider(provider, [privateKey]);
await status.connect(murmurClient.provider, "0x1122...9900");
Arguments
Checks if the node is listening for peers.
status.isListening()
if (status.isListening()) {
// Do something
}
Joins a public channel
status.joinChat(channel);
await status.joinChat("#mytest");
Arguments
Process incoming private messages
status.onUserMessage(cb); // private messages
status.onUserMessage((err, data) => {
if(err)
console.error(err);
else
console.dir(data); // message information
});
Arguments
Process incoming public messages
status.onChannelMessage(channel, cb); // public messages
status.onChannelMessage("#mytest", (err, data) => {
if(err)
console.error(err);
else
console.dir(data); // message information
});
Arguments
Process both incoming public and private messages
status.onMessage(channel, cb); // public messages
status.onMessage(cb); // private messages
status.onMessage("#mytest", (err, data) => {
if(err)
console.error(err);
else
console.dir(data); // message information
});
Arguments
Process incoming chat requests messages from other users
status.onChatRequest(cb);
status.onChatRequest((err, data) => {
if(err)
console.error(err);
else
console.dir(data);
// message information
// {
// displayName, // Display Name
// profilePic, // Base64 Profile picture
// username // Random username (Adjective1 Adjective2 Animal)
// }
});
Arguments
Check if client has joined a channel
status.isSubscribedTo(channel);
if (status.isSubscribedTo("#mytest")) {
// Do something
}
Arguments
Leaves a public channel
status.leaveChat(channel);
status.leaveChat("#mytest");
Arguments
Send a message to a public channel
status.sendGroupMessage(channel, message, [cb]);
status.sendGroupMessage("#mytest", "Hello world!", (err, data) => {
if (err) {
console.error(err);
return;
}
// Do something
});
Arguments
Send a message to a contact code
status.sendUserMessage(pubKey, message, [cb]);
status.sendUserMessage("0x1122...9900", "Hello world!", (err, data) => {
if (err) {
console.error(err);
return;
}
// Do something
});
Arguments
Returns a string with the public key
status.getPublicKey();
await status.getPublicKey(); // "0x1122...9900"
Returns the random username for the public key
status.getUserName([pubKey]);
await status.getUserName(); // "Adjective1 Adjective2 Animal"
await status.getUserName("0x1122...9900");
Arguments
Add a contact by pubKey. (TODO: send contact request msg)
status.addContact(pubKey, [cb]);
status.addContact("0x1122...9900");
Arguments
Remove a contact by pubKey.
status.removeContact(pubKey);
status.removeContact("0x1122...9900");
Arguments
Use a specific mailserver to obtain old messages. Active mailservers from Status.im can be found here
status.mailservers.useMailserver(enode, [cb]);
const enode = "enode://[email protected]:30303";
status.mailservers.useMailserver(enode, (err, res) => {
if (err) {
console.err("Error: " + err);
return;
}
// Do something
});
Arguments
Once a mailserver is selected, request old private messages. Messages will be received in the onMessage
or onUserMessage
handler.
* mailservers.requestUserMessages(options, [cb])
const enode = "enode://[email protected]:30303";
status.mailservers.useMailserver(enode, (err, res) => {
if (err) {
console.err("Error: " + err);
return;
}
const from = parseInt((new Date()).getTime() / 1000 - 86400, 10);
const to = parseInt((new Date()).getTime() / 1000, 10);
// User messages
status.mailservers.requestUserMessages({from, to}, (err, res) => {
if(err)
console.log(err);
// Do something
});
});
Arguments
Options
status-go
, default is 30status-go
, default is 0Once a mailserver is selected, request old public messages for a channel. Messages will be received in the onMessage
or onChannelMessage
handler.
* mailservers.requestChannelMessages(channel, [cb])
const enode = "enode://[email protected]:30303";
status.mailservers.useMailserver(enode, (err, res) => {
if (err) {
console.err("Error: " + err);
return;
}
const from = parseInt((new Date()).getTime() / 1000 - 86400, 10);
const to = parseInt((new Date()).getTime() / 1000, 10);
// Channel messages
status.mailservers.requestChannelMessages("mytest", {from, to}, (err, res) => {
if(err)
console.log(err);
// Do something
});
});
Arguments
Options
status-go
, default is 30status-go
, default is 0Clone the repo via git:
$ git clone https://github.com/status-im/status-js.git
And then install the dependencies with yarn
.
$ cd status-js
$ yarn
To develop:
$ yarn run start
$ yarn run lint
Thank you for considering to help out with the source code! We welcome contributions from anyone on the internet, and are grateful for even the smallest of fixes!
If you'd like to contribute to status-js
, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. If you wish to submit more complex changes though, please check up with the core devs first on #status-js channel to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple.