Skip to main content

Feedback

Loading...

Deploying Document Store Smart Contract (Code)

For the current step, you can either opt to use the CLI or Code.

Installation

npm install --save @tradetrust-tt/tradetrust-core

Usage

To use the package, you will need to provide your own Web3 provider or signer (if you are writing to the blockchain).

Refer to the pre-requisite on setup instructions.

Deploy new document store

import { DocumentStoreFactory } from "@tradetrust-tt/tradetrust-core";
import { TransactionReceipt } from "@ethersproject/abstract-provider";
import { Wallet, ethers } from "ethers";

const unconnectedWallet = new Wallet("privateKey");
const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); // Local network
const wallet = unconnectedWallet.connect(provider);
const walletAddress = await wallet.getAddress();

const factory = new DocumentStoreFactory(wallet);
const transaction = await factory.deploy("Demo Document Store", walletAddress);
const transactionReceipt = await transaction.deployTransaction.wait();
const documentStoreAddress = transactionReceipt.contractAddress;
console.log(documentStoreAddress); // 0x63A223E025256790E88778a01f480eBA77731D04

Connect to existing document store

import { DocumentStoreFactory } from "@tradetrust-tt/tradetrust-core";
import { TransactionReceipt } from "@ethersproject/abstract-provider";
import { Wallet, ethers } from "ethers";

const unconnectedWallet = new Wallet("privateKey");
const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); // Local network
const wallet = unconnectedWallet.connect(provider);

const documentStore = DocumentStoreFactory.connect("0x63A223E025256790E88778a01f480eBA77731D04", wallet);
console.log(`Document Store Name: ${await documentStore.name()}`); // Document Store Name: DemoDocumentStore

Congratulations! You have successfully deployed a document store.

Next we take a look at configuring the DNS.