diff --git a/scripts/migrate-itn-data.sh b/scripts/migrate-itn-data.sh
new file mode 100755
index 00000000000..41f1e4b0a59
--- /dev/null
+++ b/scripts/migrate-itn-data.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+if [ $# -lt 1 ] || [ $# -gt 3 ]; then
+    echo "Usage" $0 archive-db [data_file] [update_script]
+    echo "'data_file' and 'update_script' are created when running this script"
+    exit 0
+fi
+
+ARCHIVE_DB=$1
+DATA_FILE=${2:-data_file.tmp}
+UPDATE_SCRIPT=${3:-data_update.sql}
+
+echo "Migrating receipt chain hashes in account preconditions in archive db '"$ARCHIVE_DB"'"
+
+rm -f $DATA_FILE
+rm -f $UPDATE_SCRIPT
+
+echo "Creating temporary file with receipt chain hashes" "'"$DATA_FILE"'"
+echo "select id,receipt_chain_hash from zkapp_account_precondition where receipt_chain_hash is not null;" | \
+    psql --csv -t -q $ARCHIVE_DB > $DATA_FILE
+
+echo "Creating SQL script" "'"$UPDATE_SCRIPT"'"
+for line in `cat $DATA_FILE`
+  do  (
+    ID=$(echo $line | awk -F , '{print $1}');
+    FP=$(echo $line | awk -F , '{print $2}');
+    B58=$(echo $FP | _build/default/src/app/receipt_chain_hash_to_b58/receipt_chain_hash_to_b58.exe);
+    echo -n .
+    echo $ID "'"$B58"'" | awk '{print "UPDATE zkapp_account_precondition SET receipt_chain_hash=" $2 " WHERE id=" $1 ";"}' >> $UPDATE_SCRIPT)
+done
+
+echo
+echo "Receipt chain hash pass done!"
+
+rm -f $DATA_FILE
+
+echo "Creating temporary file with last_vrf_ouput" "'"$DATA_FILE"'"
+echo "select id,last_vrf_output from blocks;" | \
+    psql --csv -t -q $ARCHIVE_DB > $DATA_FILE
+
+echo "Adding to SQL script" "'"$UPDATE_SCRIPT"'"
+for line in `cat $DATA_FILE`
+  do  (
+    ID=$(echo $line | awk -F , '{print $1}');
+    FP=$(echo $line | awk -F , '{print $2}');
+    B64=$(echo $FP | _build/default/src/app/last_vrf_output_to_b64/last_vrf_output_to_b64.exe);
+    echo -n .
+    echo $ID "'"$B64"'" | awk '{print "UPDATE blocks SET last_vrf_output=" $2 " WHERE id=" $1 ";"}' >> $UPDATE_SCRIPT)
+done
+
+echo
+echo "Last VRF output pass done!"
+
+echo "Now run:" "psql -d" $ARCHIVE_DB "<" $UPDATE_SCRIPT
diff --git a/scripts/migrate-receipt-chain-hashes.sh b/scripts/migrate-receipt-chain-hashes.sh
deleted file mode 100755
index e2d22db41b6..00000000000
--- a/scripts/migrate-receipt-chain-hashes.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-
-if [ $# -lt 1 ] || [ $# -gt 3 ]; then
-    echo "Usage" $0 archive-db [hashes_file] [update_script]
-    echo "'hashes_file' and 'update_script' are created when running this script"
-    exit 0
-fi
-
-ARCHIVE_DB=$1
-HASHES_FILE=${2:-hashes_file.tmp}
-UPDATE_SCRIPT=${3:-hashes_update.sql}
-
-echo "Migrating receipt chain hashes in account preconditions in archive db '"$ARCHIVE_DB"'"
-
-rm -f $HASHES_FILE
-rm -f $UPDATE_SCRIPT
-
-echo "Creating temporary file" "'"$HASHES_FILE"'"
-echo "select id,receipt_chain_hash from zkapp_account_precondition where receipt_chain_hash is not null;" | \
-    psql --csv -t -q $ARCHIVE_DB > $HASHES_FILE
-
-echo "Creating SQL script" "'"$UPDATE_SCRIPT"'"
-for line in `cat $HASHES_FILE`
-  do  (
-    ID=$(echo $line | awk -F , '{print $1}');
-    FP=$(echo $line | awk -F , '{print $2}');
-    B58=$(echo $FP | _build/default/src/app/receipt_chain_hash_to_b58/receipt_chain_hash_to_b58.exe);
-    echo -n .
-    echo $ID "'"$B58"'" | awk '{print "UPDATE zkapp_account_precondition SET receipt_chain_hash=" $2 " WHERE id=" $1 ";"}' >> $UPDATE_SCRIPT)
-done
-
-echo
-echo "Done!"
-echo "Now run:" "psql -d" $ARCHIVE_DB "<" $UPDATE_SCRIPT
diff --git a/src/app/last_vrf_output_to_b64/dune b/src/app/last_vrf_output_to_b64/dune
new file mode 100644
index 00000000000..54c9f34dbc5
--- /dev/null
+++ b/src/app/last_vrf_output_to_b64/dune
@@ -0,0 +1,14 @@
+(executable
+ (package last_vrf_output_to_b64)
+ (name last_vrf_output_to_b64)
+ (public_name last_vrf_output_to_b64)
+ (libraries
+   ;; opam libraries
+   base64
+   core_kernel
+   hex
+   ;; local libraries
+ )
+ (preprocessor_deps ../../config.mlh)
+ (instrumentation (backend bisect_ppx))
+ (preprocess (pps ppx_mina ppx_version)))
diff --git a/src/app/last_vrf_output_to_b64/last_vrf_output_to_b64.ml b/src/app/last_vrf_output_to_b64/last_vrf_output_to_b64.ml
new file mode 100644
index 00000000000..4cf7c7074ec
--- /dev/null
+++ b/src/app/last_vrf_output_to_b64/last_vrf_output_to_b64.ml
@@ -0,0 +1,23 @@
+open Core_kernel
+
+let () =
+  let s = Stdlib.read_line () in
+  let b64_check () =
+    match Base64.decode ~alphabet:Base64.uri_safe_alphabet s with
+    | Ok _ ->
+        (* already base64 *)
+        s
+    | Error _ ->
+        failwith "Bad Base64 encoding"
+  in
+  let b64 =
+    (* try unhexing first, because hex chars are also base64 chars *)
+    try
+      match Hex.Safe.of_hex s with
+      | Some unhexed ->
+          Base64.encode_exn ~alphabet:Base64.uri_safe_alphabet unhexed
+      | None ->
+          b64_check ()
+    with _ -> b64_check ()
+  in
+  Format.printf "%s@." b64
diff --git a/src/dune-project b/src/dune-project
index ff60cccc4c4..7a68f9cdfa8 100644
--- a/src/dune-project
+++ b/src/dune-project
@@ -79,6 +79,7 @@
 (package (name kimchi_backend))
 (package (name kimchi_bindings))
 (package (name kimchi_types))
+(package (name last_vrf_output_to_b64))
 (package (name ledger_catchup))
 (package (name ledger_proof))
 (package (name libp2p_ipc))