1.0.2 • Published 2 years ago

@dsnp/contracts v1.0.2

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

DSNP Contracts

The official DSNP interface and implementations.

Overview

Installation

$ npm install @dsnp/contracts

JavaScript ABI Usage

const announcer = require("@dsnp/contracts/abi/Announcer.json");
const annoucerABI = announcer.abi;

TypeScript ABI Usage

// Requires "resolveJsonModule": true in [tsconfig](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
import { abi as announcerABI } from "@dsnp/contracts/abi/Announcer.json";

TypeScript Contract Types

To maintain types, it is suggested to use TypeChain.

  1. Follow the install directions and add the correct package for your toolset.
  2. Add a postinstall or other step to run typechain:
  • "postinstall": "typechain --target=(ethers-v5|web3-v1|other...) ./node_modules/@dsnp/contracts/**/*.json --outDir ./types/typechain"
  • "build:web3types": "typechain --target=web3-v1 ./node_modules/@dsnp/contracts/**/*.json --outDir ./types/typechain"
  1. Make sure your --outDir is in tsconfig typeRoots.
  2. Use the types:
// web3 example
import web3 from "web3";
import { Announcer } from "./types/typechain/Announcer";
import { abi as announcerABI } from "@dsnp/contracts/abi/Announcer.json";

const getAnnouncerContract = (contractAddress: string) => {
  // web3 requires the type casts
  return (new web3.eth.Contract(announcerABI, contractAddress) as any) as Announcer;
}
// ethersjsv5 example
import { Provider } from "@ethersproject/providers";
import { Announcer } from "./types/typechain/Announcer";

const getAnnouncerContract = (contractAddress: string, provider: Provider) => {
  // TypeChain for Ethers provides factories
  return Announcer__factory.connect(contractAddress, provider);
}

Contract Usage

Once installed, you can use the contracts in the library by importing them:

pragma solidity ^0.8.0;

import "@dsnp/contracts/IAnnounce.sol";

contract MyAnnouncer is IAnnounce {
    // ...
}

Development

We are using hardhat to compile and deploy the contracts

Key Commands and Tasks

Basic Command List:

  • npm install
  • npm run clean - clears the cache and deletes all artifacts
  • npm run compile - compiles the entire project, building all artifacts
  • npm run console - opens a hardhat console
  • npm run test - runs mocha tests
  • npm run lint - to run the linter
  • npm run format - to trigger formatting
  • npm run deploy:testnet - deploys our deploy.ts script to our POA testnet defined in the hardhat.config.ts

Environment Variables 1. create a .env file and set values for all variables in .env.sample

Env Variable NameDescription
LOCAL_NETWORK_PRIVATE_KEYprivate key for an account we have on our local network that has eth.
STAGENET_ACCOUNT_PRIVATE_KEYprivate key for an account we have on our test network that has eth.
STAGENET_CHAIN_URLUrl to connect to tesnet
VALIDATOR1hex prefixed address for validator running on node called liberty-chain
VALIDATOR2hex prefixed address for validator running on node called liberty-chain1
BOOTNODEenode address of the node our node would like to connect to

Accounts

Deployments

Ports

Development

  • This repo uses Hardhat + ethers for interfacing with Ethereum,
  • Waffle for testing,
  • And Truffle or truffle-style for contract migration.
0.0.0-f2a972

2 years ago

0.0.0-297343

2 years ago

1.0.2

2 years ago

0.0.0-f7c4cf

2 years ago

0.0.0-ed3576

2 years ago

0.0.0-e94a72

3 years ago

0.0.0-0bc3c3

3 years ago

0.0.0-bc313e

3 years ago

1.0.1

3 years ago

0.0.0-e7cefb

3 years ago

0.0.0-d64f10

3 years ago

1.0.0

3 years ago

0.0.0-5c945f

3 years ago

0.0.0-622366

3 years ago

0.0.0-cfa944

3 years ago

0.0.0-386b96

3 years ago

0.0.0-7eb972

3 years ago

0.1.0

3 years ago

0.0.0

3 years ago

0.0.0-9e8770

3 years ago

0.0.0-54f452

3 years ago

0.0.0-9c117e

3 years ago

0.0.0-d2067e

3 years ago

0.0.0-83d788

3 years ago

0.0.0-89312d

3 years ago

0.0.0-83c461

3 years ago

0.0.0-4b6581

3 years ago