1.0.29 • Published 7 months ago

zkturk-contract-artifacts v1.0.29

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago

zkturk-contract-artifacts

Package consists of following artifacts useful for ZkTurk contract interaction:

  • contracts/ - json artifacts of the contracts. Useful contract abi are here,
  • typechain-types/ - typechain-types of all contracts,
  • frontend-clients - frontend oriented classes those need only signer and abi to initiate and then used to interact with contract logic. Kinda API with the contracts in the blockchain.

Install

npm i zkturk-contract-artifacts

Example Repo Code

Script code that you may run with ts-node <script.ts> is below:

import {ZkTurk} from "zkturk-contract-artifacts/dist/typechain-types";
import {ethers} from "ethers";
import {ZkTurkClient} from "zkturk-contract-artifacts/dist/frontend-clients/ZkTurkClient";
// For the line below "resolveJsonModule": true policy should be used.
import ZkTurkArtifacts from "zkturk-contract-artifacts/dist/contracts/ZkTurk.sol/ZkTurk.json";

// ZkTurk contract deployed address (You should know the address).
const contractAddress = "0x5FbDB2315678afecb367f032d93F642f64180aa3"
// Hardhat network localhost (You should have node available on rpc).
const rpcProviderUrl = "http://localhost:8545"


async function workWithFrontendClientExample() {
    // Bad example of how to use wallet from a private key.
    const privateKeyFoo = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"  // From Hardhat network.
    const provider = new ethers.providers.JsonRpcProvider(rpcProviderUrl)  // harhdat localhost
    const signer = new ethers.Wallet(privateKeyFoo, provider);

    // RM ts-ignore if uses real frontend provider, like commented below:
    // const provider = new ethers.providers.Web3Provider(window.ethereum);
    // const signer = provider.getSigner()
    // @ts-ignore
    const client = new ZkTurkClient(signer, ZkTurkArtifacts.abi, contractAddress)

    console.log('client.getAllProblems()', await client.getAllProblems())
}

async function workWithContractExample() {
    const provider = new ethers.providers.JsonRpcProvider(rpcProviderUrl)
    const contractInstance = new ethers.Contract(contractAddress, ZkTurkArtifacts.abi, provider) as ZkTurk;

    // Signer is not needed for contract call
    console.log('await contractInstance.owner()', await contractInstance.owner())
}


async function main() {
    console.log('Starting...')
    await workWithFrontendClientExample()
    await workWithContractExample()
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Example of tsconfig.json

{
  "compilerOptions": {
    "incremental": true,            /* Enable incremental compilation */
    "target": "es5",                /* Specify ECMAScript target version: */
    "module": "commonjs",           /* 'none', 'commonjs', 'amd', 'system', etc */
    "declaration": true,            /* Concatenate & emit output to single file.*/
    "outDir": "dist",                /* Redirect output to the directory. */
    "esModuleInterop": true,        /* Enables intero between CommonJS and ES */
    "skipLibCheck": true,           /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true, /* Disallow inconsistently */
    "resolveJsonModule": true
  }
}

Example of package.json dependency entities

  "dependencies": {
    "ts-node": "^10.9.1",
    "typescript": "^5.1.6",
    "zkturk-contract-artifacts": "^0.0.7"
  },
  "devDependencies": {
    "@types/node": "^20.4.0"
  }
1.0.29

7 months ago

1.0.28

7 months ago

1.0.27

8 months ago

1.0.26

8 months ago

1.0.25

8 months ago

1.0.24

8 months ago

1.0.23

8 months ago

1.0.22

8 months ago

1.0.21

8 months ago

1.0.20

8 months ago

1.0.19

9 months ago

1.0.18

9 months ago

1.0.17

9 months ago

1.0.16

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago

0.0.0

10 months ago