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.
npm i zkturk-contract-artifacts
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;
});
{
"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
}
}
"dependencies": {
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"zkturk-contract-artifacts": "^0.0.7"
},
"devDependencies": {
"@types/node": "^20.4.0"
}