GlacierClient
As we mentioned in the previous chapter, GlacierClient
is the carrier we use to access Glacier
. If you want to create a read-only client
, you don't need to specify privateKey
when instantiating or provider
. You only need to specify the endpoint
of the service, such as:
import { GlacierClient } from '@glacier-network/client';
const client = new GlacierClient('https://p0.onebitdev.com/glacier-gateway');
You can query Glacier
for data through the above client
.
But suppose you need to write to Glacier.
In that case, you need to specify the privateKey
or provider
required for the signature. Usually, privateKey
is only used for the Node.js
server or script code. However, since it needs to be signed by the browser wallet at runtime in the browser, provider
is passed in, as in the following example:
src/server.ts
import { GlacierClient } from '@glacier-network/client';
const privateKey = `0xf7311f908890f7aeaf46d0185cf4234ae926cf896b2c50590d6735a37c827045`;
const client = new GlacierClient('https://p0.onebitdev.com/glacier-gateway', {
privateKey,
});
src/browser.ts
import { GlacierClient } from '@glacier-network/client';
const client = new GlacierClient('https://p0.onebitdev.com/glacier-gateway', {
provider: window.ethereum,
});