Skip to main content

Authenticate

In Streamr, Ethereum accounts are used for identity. You can generate an Ethereum private key using any Ethereum wallet, or you can use the utility function StreamrClient.generateEthereumAccount(), which returns the address and private key of a fresh Ethereum account. A private key is not required if you are only subscribing to public streams on the Network.

const streamr = new StreamrClient({
auth: {
privateKey: 'your-private-key',
},
});

Authenticating with an Ethereum private key contained in an Ethereum (web3) provider, e.g. MetaMask:

const streamr = new StreamrClient({
auth: {
ethereum: window.ethereum,
},
});

You can also create an anonymous client instance that can interact with public streams:

const streamr = new StreamrClient();

Streamr supports ENS names to allow streams to have human readable names, for example mydomain.eth/traffic/helsinki. More on that in the Streams section.

Generate Ethereum account‚Äč

The Streamr SDK offers a convenience static function StreamrClient.generateEthereumAccount() which will generate a new Ethereum private key and returns an object with fields address and privateKey.

const { address, privateKey } = StreamrClient.generateEthereumAccount();

In order to retrieve the address, an async call must me made to streamr.getAddress

const address = await streamr.getAddress();