Created
April 17, 2023 13:40
-
-
Save madis/a4f5ea27fc34c8f9b2f4537e0cbb3af0 to your computer and use it in GitHub Desktop.
Ethers & hardhat with ClojureScript & nbb (Node Babashka)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns first | |
(:require | |
["@nomicfoundation/hardhat-chai-matchers/withArgs" :refer [anyValue]] | |
["@nomicfoundation/hardhat-network-helpers" :as hnh :refer [hh-time loadFixture]] | |
["ethers" :as ethers-js])) | |
(def test-seed "easy leave proof verb wait patient fringe laptop intact opera slab shine") | |
(defn ** [x n] | |
(loop [acc 1 n n] | |
(if (zero? n) acc | |
(recur (* x acc) (dec n))))) | |
(defn time-now [] | |
(.now js/Date)) | |
(def wallet (.-Wallet ethers-js)) | |
(defn generate-addresses | |
([seed-phrase] (generate-addresses seed-phrase 0)) | |
([seed-phrase counter] | |
(lazy-seq (cons | |
(.-address (.fromMnemonic wallet seed-phrase (str "m/44'/60'/0'/0/" counter))) | |
(generate-addresses seed-phrase (inc counter)))))) | |
(defn first-test [] | |
(let [one-year-in-secs (* 365 24 60 60) | |
one-gwei (** 10 9) | |
locked-amount one-gwei | |
unlock-time (+ (time-now) one-year-in-secs) | |
[owner other-account] (take 2 (generate-addresses test-seed)) | |
lock-contract () | |
] | |
(println "Addresses: " (take 10 (generate-addresses test-seed))))) | |
(first-test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment