@dsnp/sdk v0.0.0-f8b540
DSNP TypeScript SDK
Easy to use SDK for the DSNP
Quick Start
Install the package
First, install the SDK package with the following command:
npm install @dsnp/sdkConfigure the SDK
The configuration can be set at runtime with the following:
var config = require("@dsnp/sdk/config");
config.setConfig({
signer: signer,
provider: provider
})
// Do something with the SDKStoring Messages and Batches
Amazon S3 is supported when adding the following configuration:
import { S3Node } from "./storage/s3Node";
config
.setConfig({
...,
store: S3Node({
key: "tomyheartisno",
secret: "itsa",
bucket: "ofchicken",
region: "us-east-la",
})
});Other storage solutions can be added so as long it contains the following interface.
interface StorageInterface {
put: (targetPath: string, content: Content) => Promise<URL>;
get?: (targetPath: string) => Promise<string>;
}config
.setConfig({
storage: new MyStorage()
});See Config Documentation for details on additional options.
Usage
Once the SDK is installed and configured, the following code can be used to post a batch on the chain:
var announcement = require("@dsnp/sdk/contracts/announcement");
announcement.batch([{ hash, uri, dsnpType }]);Documentation
See Documentation or generate documentation locally via npm run doc.
How to Install
Run npm install @dsnp/sdk
How to Build
Run npm run build
How to Compile Documentation
Documentation is deployed on merge to main to GitHub Pages: https://libertydsnp.github.io/sdk-ts/
- Run
npm run docfor HTML documentation - Run
npm run doc:jsonfor JSON documentation - Run
npm run doc:markdownfor markdown documentation (published with the npm package)
Environment Variables
| Name | Description |
|---|---|
| RPC_URL | url of node to make calls to |
| BATCH_CONTRACT_ADDRESS | Address of contract on chain you are calling to |
| TESTING_PRIVATE_KEY | Only used in testing - private key of account you are sending transactions from |
Testing
How to Test
- Check out the contracts repo and follow the instructions to start a hardhat test node and deploy the contracts.
- Match sure you match the version in ./package.json!
- In the SDK create a .env file with the following content.
RPC_URL=http://localhost:8545 TESTING_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - Replace the value of TESTING_PRIVATE_KEY with the value of
LOCAL_NETWORK_ACCOUNT_PRIVATE_KEYin the .env from the contracts repo, or use what is in .github/workflows/main.yml. It may be same as above. - Ensure that the contracts version you would like to use is the correct version. The version of the
@dsnp/contractspackage is specified in thepackage.json - Run
npm run test
Test Writing Utilities
- test/hardhatRPC
snapshotSetup: Call this to use evm snapshots before each test to make sure the blockchain state is cleansnapshotHardhat/revertHardhat: Make other snapshots, but remember to revert them for other tests
- test/sdkTestConfig
setupConfig: An easy way to setup the default config for the sdk for testing.- Often can be as simple as
beforeAll(setupConfig); - Returns an object with the provider and signer if those are needed.
- Often can be as simple as
- test/matchers
- Helpful common Jest Matchers like
expect("0x0").toMatch(EthAddressRegex)
- Helpful common Jest Matchers like
- test/customMatchers
- Custom Loaded Jest expect matchers like
expect(tx).transactionRejectsWith("message")
- Custom Loaded Jest expect matchers like
- test/generators
- Test Data Generators and fixtures
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago