Creating a Valist Client
The SDK exports a client class that provides public methods to interact with Valist.
After importing the client in your file, you need to create a Valist client.

Create Function

The create function creates a Valist client using a JSON RPC Provider.
1
export async function create(
2
provider: Provider,
3
options: Partial<Options>
4
): Promise<Client>
Copied!

Input Parameters

Input
Description
Provider
An underlying web3 provider connected to a chain with a supported Chain ID
Options
Additional options for configuring a client.

Alternatively,

If the functions you want to use are read only, i.e they do not make any changes and are used only to query, the createReadonly function can be used. Further, The methods that can be accessed by a readonly client have Readonly next to their headings.

CreateReadOnly Function

1
export function createReadOnly(
2
provider: Provider,
3
options: Partial<Options>
4
): Client
Copied!
Input
Description
Provider
An underlying web3 provider connected to a chain with a supported chain id
Options
Additional options for configuring a client.
1
// The configurable options for a valist client.
2
export interface Options {
3
chainId: number;
4
ipfsHost: string;
5
ipfsGateway: string;
6
metaTx: boolean;
7
wallet: ethers.Wallet;
8
registryAddress: string;
9
licenseAddress: string;
10
}
Copied!

Example Usage

To create a Valist client, you need a Wallet and an RPC provider:
1
// Example
2
const ethers = require('ethers');
3
const create = require('@valist/sdk').create;
4
const Web3HttpProvider = require('web3-providers-http');
5
​
6
async function main() {
7
try {
8
const web3 = new Web3HttpProvider("https://rpc.valist.io/polygon");
9
10
const privateKey = ethers.Wallet.createRandom();
11
const wallet = new ethers.Wallet(privateKey);
12
13
const provider = new ethers.providers.Web3Provider(web3);
14
const valist = await create(provider, { wallet, metaTx: true });
15
16
const accountID = valist.generateID(137, 'acme-co');
17
const projectID = valist.generateID(accountID, 'go-binary')
18
const releaseID = await valist.getLatestReleaseID(projectID)
19
20
const projectMeta = await valist.getProjectMeta(projectID);
21
const latestRelease = await valist.getReleaseMeta(releaseID);
22
23
console.log(projectMeta);
24
console.log(latestRelease);
25
} catch (err) {
26
console.log(err)
27
}
28
}
29
​
30
main()
Copied!
To create a read-only client, you can use the createReadOnly function:
1
// Example
2
const ethers = require('ethers');
3
const createReadOnly = require('@valist/sdk').createReadOnly;
4
const Web3HttpProvider = require('web3-providers-http');
5
​
6
async function main() {
7
try {
8
const web3 = new Web3HttpProvider("https://rpc.valist.io/polygon");
9
const provider = new ethers.providers.Web3Provider(web3);
10
const valist = createReadOnly(provider, { metaTx: false });
11
12
const accountID = valist.generateID(137, 'acme-co');
13
const projectID = valist.generateID(accountID, 'go-binary')
14
const releaseID = await valist.getLatestReleaseID(projectID)
15
16
const projectMeta = await valist.getProjectMeta(projectID);
17
const latestRelease = await valist.getReleaseMeta(releaseID);
18
19
console.log(projectMeta);
20
console.log(latestRelease);
21
} catch (err) {
22
console.log(err)
23
}
24
}
25
​
26
main()
Copied!
Export as PDF
Copy link