0.0.0-f8b540 • Published 5 years ago

@dsnp/sdk v0.0.0-f8b540

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

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/sdk

Configure 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 SDK

Storing 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 doc for HTML documentation
  • Run npm run doc:json for JSON documentation
  • Run npm run doc:markdown for markdown documentation (published with the npm package)

Environment Variables

NameDescription
RPC_URLurl of node to make calls to
BATCH_CONTRACT_ADDRESSAddress of contract on chain you are calling to
TESTING_PRIVATE_KEYOnly used in testing - private key of account you are sending transactions from

Testing

How to Test

  1. 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!
  2. In the SDK create a .env file with the following content.
    RPC_URL=http://localhost:8545
    TESTING_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
  3. Replace the value of TESTING_PRIVATE_KEY with the value of LOCAL_NETWORK_ACCOUNT_PRIVATE_KEY in the .env from the contracts repo, or use what is in .github/workflows/main.yml. It may be same as above.
  4. Ensure that the contracts version you would like to use is the correct version. The version of the @dsnp/contracts package is specified in the package.json
  5. 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 clean
    • snapshotHardhat/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.
  • test/matchers
    • Helpful common Jest Matchers like expect("0x0").toMatch(EthAddressRegex)
  • test/customMatchers
    • Custom Loaded Jest expect matchers like expect(tx).transactionRejectsWith("message")
  • test/generators
    • Test Data Generators and fixtures
0.0.0-77f102

3 years ago

0.0.0-9c522e

3 years ago

0.0.0-48d905

4 years ago

0.0.0-7303ed

4 years ago

0.0.0-2d8bb6

4 years ago

0.0.0-e51513

4 years ago

0.0.0-e20826

4 years ago

0.0.0-a965f4

4 years ago

0.0.0-3e0897

4 years ago

0.0.0-8aab7b

4 years ago

0.0.0-7fc294

4 years ago

0.0.0-833aa7

4 years ago

0.0.0-1e3994

4 years ago

3.0.3

4 years ago

0.0.0-7c48e2

4 years ago

0.0.0-1a634c

4 years ago

0.0.0-c4ef10

4 years ago

0.0.0-a6f997

4 years ago

0.0.0-3c2a7a

4 years ago

3.0.2

4 years ago

0.0.0-c27385

4 years ago

0.0.0-a38373

4 years ago

0.0.0-04a188

4 years ago

3.0.1

4 years ago

0.0.0-54f461

4 years ago

0.0.0-ae9c6f

4 years ago

0.0.0-0601cc

4 years ago

3.0.0

4 years ago

0.0.0-c1d95b

4 years ago

0.0.0-5f60c9

4 years ago

0.0.0-01269d

4 years ago

0.0.0-563c71

4 years ago

0.0.0-2709c9

4 years ago

0.0.0-841bd2

4 years ago

0.0.0-4aaafe

4 years ago

0.0.0-8d0236

4 years ago

0.0.0-33f2b8

4 years ago

0.0.0-e5777d

4 years ago

0.0.0-898a31

4 years ago

0.0.0-056cf1

4 years ago

0.0.0-86fe00

4 years ago

0.0.0-86da5a

4 years ago

2.1.2

4 years ago

0.0.0-44a710

4 years ago

0.0.0-b84a15

4 years ago

0.0.0-f3c5c5

4 years ago

0.0.0-15b656

4 years ago

2.1.1

4 years ago

0.0.0-d21e15

4 years ago

0.0.0-80e746

4 years ago

0.0.0-b62952

4 years ago

0.0.0-440437

4 years ago

0.0.0-abd844

4 years ago

2.1.0

4 years ago

0.0.0-6f2dab

4 years ago

0.0.0-e0c7ac

4 years ago

0.0.0-179bde

4 years ago

0.0.0-d06294

4 years ago

0.0.0-1c4cdc

4 years ago

2.0.2

4 years ago

0.0.0-6082ae

4 years ago

0.0.0-47f4fd

4 years ago

0.0.0-c6a5a2

4 years ago

0.0.0-261910

4 years ago

0.0.0-15c3f7

4 years ago

0.0.0-8f2ae6

4 years ago

0.0.0-50a5fe

4 years ago

2.0.1

4 years ago

0.0.0-994458

4 years ago

0.0.0-1e6fd2

4 years ago

0.0.0-a514ec

4 years ago

0.0.0-f39e7f

4 years ago

0.0.0-da02ec

4 years ago

2.0.0

4 years ago

0.0.0-aa2c5b

4 years ago

0.0.0-062c22

4 years ago

0.0.0-ac2374

4 years ago

0.0.0-bb9793

4 years ago

0.0.0-d4e3a7

4 years ago

0.0.0-899c38

4 years ago

0.0.0-e6bade

4 years ago

0.0.0-aee97e

4 years ago

0.0.0-85a1d1

4 years ago

0.0.0-75624c

4 years ago

0.0.0-2c0cd6

4 years ago

0.0.0-f6950a

4 years ago

0.0.0-e29064

4 years ago

0.0.0-fd1aba

4 years ago

0.0.0-f2350e

4 years ago

0.0.0-4d9a01

4 years ago

0.0.0-672eb7

4 years ago

0.0.0-b224f5

4 years ago

0.0.0-998232

4 years ago

0.0.0-d9b78c

4 years ago

0.0.0-23cc64

4 years ago

0.0.0-86342e

4 years ago

0.0.0-3c807d

4 years ago

0.0.0-2ddbab

4 years ago

0.0.0-37dc26

4 years ago

0.0.0-9fbd4b

4 years ago

0.0.0-0fe5bf

4 years ago

0.0.0-562008

4 years ago

0.0.0-56835d

4 years ago

0.0.0-aba284

4 years ago

0.0.0-85874c

4 years ago

0.0.0-2aa1e6

4 years ago

0.0.0-02ba0d

4 years ago

0.0.0-deb0b1

4 years ago

0.0.0-293123

4 years ago

1.0.0

4 years ago

0.0.0-322b6f

4 years ago

0.0.0-e9f4d1

4 years ago

0.0.0-1f5df5

4 years ago

0.0.0-7d4f28

4 years ago

0.0.0-869490

4 years ago

0.0.0-86a3e8

4 years ago

0.0.0-825e8b

4 years ago

0.0.0-c988da

4 years ago

0.0.0-b0dedf

5 years ago

0.0.0-daf646

5 years ago

0.0.0-546ddf

5 years ago

0.0.0-819b90

5 years ago

0.0.0-10b12c

5 years ago

0.0.0-0c04e9

5 years ago

0.0.0-3d7ded

5 years ago

0.0.0-0a73c1

5 years ago

0.0.0-97604a

5 years ago

0.0.0-0fb5a0

5 years ago

0.0.0-fc96b8

5 years ago

0.0.0-720317

5 years ago

0.0.0-875b82

5 years ago

0.0.0-f8b540

5 years ago

0.0.0-33a000

5 years ago

0.0.0-f86662

5 years ago

0.0.0-8391c7

5 years ago

0.0.0-372c56

5 years ago

0.0.0-78def2

5 years ago

0.0.0-513646

5 years ago

0.0.0-960a18

5 years ago

0.0.0-06dac2

5 years ago

0.0.0-58c147

5 years ago

0.1.0

5 years ago

0.0.0-d4cd6c

5 years ago

0.0.0-6803e8

5 years ago

0.0.0-63cb8d

5 years ago

0.0.0-f0b90d

5 years ago

0.0.0-fd18c1

5 years ago

0.0.0-f1a398

5 years ago

0.0.0-9a053e

5 years ago

0.0.0-04ac41

5 years ago

0.0.0-efdb66

5 years ago

0.0.0-ff6ac7

5 years ago

0.0.0-cdb32d

5 years ago

0.0.0-7c33d7

5 years ago

0.0.0-e3daf4

5 years ago

0.0.0-d4a9d4

5 years ago

0.0.0-c43b4e

5 years ago

0.0.0-ee5111

5 years ago

0.0.0-447f11

5 years ago

0.0.0-f67fb3

5 years ago

0.0.0-f4427d

5 years ago

0.0.0-49665c

5 years ago

0.0.0-3aa71c

5 years ago