Skip to content

Commit

Permalink
add testnet-minter route
Browse files Browse the repository at this point in the history
  • Loading branch information
calebtuttle committed Oct 15, 2024
1 parent 99a6f27 commit bcc4c39
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const providers = {
process.env.ALCHEMY_APIKEY
),
};
try {
providers["base-sepolia"] = new ethers.providers.JsonRpcProvider(
process.env.BASE_SEPOLIA_RPC_URL
);
} catch (err) {}
const signer = new ethers.Wallet(process.env.PRIVATE_KEY, providers.optimism);
const thisAddress = signer.address;

Expand Down
8 changes: 8 additions & 0 deletions src/routes/testnet-minter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import express from "express";
import { setKycSbt } from "../services/testnet-minter.js";

const router = express.Router();

router.post("/kyc", setKycSbt);

export default router;
2 changes: 2 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import snapshotStrategies from "./routes/snapshot-strategies.js";
import metrics from "./routes/metrics.js";
import sbtAttestation from "./routes/sbt-attestation.js";
import sbts from "./routes/sbts.js";
import testnetMinter from "./routes/testnet-minter.js";

// ----------------------------
// Setup express app
Expand All @@ -29,6 +30,7 @@ app.use("/snapshot-strategies", snapshotStrategies);
app.use("/metrics", metrics);
app.use("/attestation", sbtAttestation);
app.use("/sbts", sbts);
app.use("/testnet-minter", testnetMinter);

app.get("/", (req, res) => {
console.log(`${new Date().toISOString()} GET /`);
Expand Down
41 changes: 41 additions & 0 deletions src/services/testnet-minter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { randomBytes } from "crypto";
import { ethers } from "ethers";
import { v3KYCSybilResistanceCircuitId } from "../constants/misc.js";
import { providers } from "../init.js";

export async function setKycSbt(req, res) {
try {
const testnetMinterWallet = new ethers.Wallet(
process.env.TESTNET_MINTER_PRIVATE_KEY,
providers["base-sepolia"]
);

const { circuitId, sbtReceiver, expiration, nullifier, publicValues } = req.body;

const abi = [
"function setSBT(bytes32 circuitId, address sbtReceiver, uint expiration, uint nullifier, uint[] calldata publicValues)",
];
const address = "0x98221c937C51f5bBe615CB104435395c93b1AD8D";
const contract = new ethers.Contract(address, abi, testnetMinterWallet);

const tx = await contract.setSBT(
// circuitId,
// sbtReceiver,
// expiration,
// nullifier,
// publicValues
v3KYCSybilResistanceCircuitId,
sbtReceiver,
ethers.constants.MaxUint256,
ethers.BigNumber.from("0x" + randomBytes(31).toString("hex")),
[]
);

await tx.wait();

return res.status(200).json({ TransactionHash: tx.hash });
} catch (err) {
console.log(err);
return res.status(500).json({ error: "An unexpected error occured" });
}
}

0 comments on commit bcc4c39

Please sign in to comment.