Search
setDatabaseFieldValue
@vinspee
An interactive, runnable TypeScript val by vinspee
Script
export const setDatabaseFieldValue = async () => {
const { Client } = await import("npm:@notionhq/client");
const { config } = await import("npm:dotenv");
const { default: SendGrid } = await import("npm:@sendgrid/mail");
config();
SendGrid.setApiKey(process.env.SENDGRID_KEY);
const notion = new Client({ auth: process.env.NOTION_KEY });
const databaseId = process.env.NOTION_DATABASE_ID;
* Local map to store task pageId to its last status.
coverpatch
@yawnxyz
// import { covertest as test } from "../covertest/covertest.ts";
Script
project: { name: "Project A", status: "In Progress" },
client: { name: "ACME Corp", location: "New York" }
const additionalData = {
projectDetails: { budget: 50000, deadline: "2024-12-31" },
clientInfo: { industry: "Technology", contactPerson: "John Doe" }
const prompt = "Combine the project and client information from baseData with the additional details from additionalData. Create a comprehensive enriched object that includes all relevant information.";
console.log("Base Data:", JSON.stringify(baseData, null, 2));
test.assertEquals(result.enrichedData.project.budget, 50000, "Project budget should be added");
test.assertEquals(result.enrichedData.client.industry, "Technology", "Client industry should be added");
* Tests the patchObjectsWithNotionAndAirtable function by combining Notion and Airtable data.
normalizeURL
@stef
An interactive, runnable TypeScript val by stef
Script
import compareUrls from "npm:compare-urls";
const urlA =
"https://dimillian.medium.com/the-making-of-ice-cubes-an-open-source-swiftui-mastodon-client-45ebea5cf6b6?source=user_profile---------0----------------------------";
const urlB = "https://dimillian.medium.com/the-making-of-ice-cubes-an-open-source-swiftui-mastodon-client-45ebea5cf6b6";
console.log(compareUrls(urlA, urlB));
console.log(normalizeURL(urlA, {
twitterFollowingsMigrations
@stevekrouse
Example Hosted SQLite on Turso Creates a database of twitter users and followers Requires tursoURL and tursoToken in your secrets. It references @stevekrouse.stevekrouseFollowing to get a list of all the twitter IDs of the users I follow on twitter and insert them to the users table and the followings table as people I follow. @stevekrouse.populateTwitterDB is a poll job that runs every minute and tries to populate this table with the twitter handles of these users.
Script
export const twitterFollowingsMigrations = (async () => {
let client = await turso({
url: process.env.tursoURL,
return [
// await client.execute("drop table if exists twitter_follows"),
// await client.execute("drop table if exists twitter_users"),
// await client.execute(`create table twitter_users (
// twitter_id TEXT PRIMARY KEY,
// twitter_handle TEXT
// await client.execute(`create table twitter_follows (
// follower_id TEXT,
// FOREIGN KEY (following_id) REFERENCES twitter_users (twitter_id)
// await client.batch("write", [
// sql: "insert into twitter_users values (:id, :handle)",
// args: { id: "431200836", handle: "stevekrouse" },
// await client.batch(
// "write",
// args: { id: id, handle: null },
// await client.batch(
// "write",
gameIdeaApi
@xkonti
This Val is a part of Creating GPT Actions with ValTown tutorial: Video on YouTube Article on xkonti.tech The GPT using it: Game Idea Exchange GPT
HTTP
Video Game Idea API allows users to store, retrieve, list, and delete data. The data stored can be of any type as inputted by the user. We do not restrict or control the content of the data stored. Video Game Idea API serves as a public database accessible to anyone with an API key. The API is not intended for storing any personal data.
## 3. User Restrictions
Video Game Idea API does not impose age or user restrictions. However, the API is not intended for use by children under the age of 13. Users are advised to consider the sensitivity of the information they share.
## 4. Global Use
Our API is accessible globally. Users from all regions can store and access data on Video Game Idea API.
The API code is run and data is stored by val.town. They act as a third-party service provider for Video Game Idea API.
## 8. Use Restrictions
The API is not intended for use in any mission-critical applications. By submitting ideas, users are responsible for the content they submit. The ideas submitted by the user will be considered public domain.
## 9. Disclaimer
The API is provided as-is without any guarantees.
animalInfoIngpracticalBlushAlbatross
@junhoca
@jsxImportSource https://esm.sh/react
HTTP
/** @jsxImportSource https://esm.sh/react */
import React, { useState, useEffect } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function StarRating({ rating, onRate }) {
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
ethereumTokenBalances
@jamiedubs
fetch token balances from an Ethereum wallet. uses Alchemy. don't abuse my API key or I'll turn this off Use it like: https://jamiedubs-ethereumtokenbalances.web.val.run/?address=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
HTTP
import { alchemyFetch } from "https://esm.town/v/jamiedubs/alchemyClient";
export async function getBalances(address: string) {
const [tokens, eth] = await Promise.all([
rawUrl
@karfau
A helper for creating the URL to request the raw data of a val,
defaulting to use the very nice implementation from @pomdtr.raw .
Also look at @karfau.getRaw to get the data of a val inside a val.
Script
defaulting to use the very nice implementation from [@pomdtr.raw](https://www.val.town/v/pomdtr.raw).
Also look at [@karfau.getRaw](https://www.val.town/v/karfau.getRaw) to get the data of a val inside a val.
sentry_crons_example
@gaprl
Sentry Crons monitoring for scheduled functions in val.town Use this val to monitor your schedule jobs for any issues and report them directly to Sentry Crons . How to configure After forking, find the DSN for your Sentry project by going to Settings > Projects > Select your project >Settings > Client Keys (DSN). Add your DSN to as a SENTRY_DSN in your val.town environment variables . Change the monitorConfig.schedule.value Crontab expression to match your job run. Replace the run() function with your scheduled function. Alter any other monitor config properties to better fit your scheduled function. Learn more . Benefits This val will automatically create and set up a Cron monitor in Sentry, and report all of your runs as check-ins. If your job ever misses a run or fails, Sentry will notify you. Any errors that occur in your scheduled function will be reported directly into Sentry:
Cron
## How to configure
1. After forking, find the DSN for your Sentry project by going to Settings > Projects > Select your project >Settings > Client Keys (DSN).
2. Add your DSN to as a `SENTRY_DSN` in your [val.town environment variables](https://www.val.town/settings/environment-variables).
uniswapV3Position
@midnightlightning
An endpoint to calculate additional metadata for a Uniswap v3 liquidity position. In order to keep on-chain fees low, the Uniswap cryptocurrency exchange balances how much data it writes to the blockchain when users take out a liquidity position. Properties are saved in a few different contracts and so knowing exactly what a liquidity position entails takes a bit of additional calculation. This endpoint takes in a token identifier that represents a liquidity position, and follows the math to make the values more human-friendly. This script uses the bignumber.js library to do higher-precision floating-point math than JavaScript can do on its own with number variables. Usage Find the token ID of the Uniswap position you wish to get details about. If you own the liquidity position, you can head to https://app.uniswap.org/pool and click on the v3 position. The ID of that position will be in the URL of the details page. Append the token ID to the end of this val's URL to fetch data about it (e.g. to get information about token ID 12345 , fetch the url https://midnightlightning-uniswapv3position.web.val.run/12345 ) Reference This val fetches blockchain data from the following smart contracts: NonfungiblePositionManager( 0xc36442b4a4522e871399cd717abdd847ab11fe88 ) Manages the liquidity position tokens as an ERC721 contract. The positions function is used to determine what tokens and tick ranges the individual liquidity position has. UniswapV3Factory ( 0x1F98431c8aD98523631AE4a59f267346ea31F984 ) Contract that manages liquidity pools, and acts as a registry to record where each pairing is deployed to. The getPool function is used to find where the smart contract for a specific pairing of ERC20 tokens is deployed to. ERC20 tokens Each position has two tokens it's balancing between, and each token has its own instance of an ERC20 contract deployed to the blockchain. The name and symbol functions are used to determine how to describe each token, and the decimals function to determine how to scale the price value for the ratio between them. UniswapV3Pool Contract that handles swaps between specific pairs of tokens. The slot0 function is used to fetch the current price the two tokens are swapping at.
HTTP
import BigNumber from "npm:bignumber.js";
import { createPublicClient, http, parseAbi } from "npm:viem";
import { mainnet } from "npm:viem/chains";
BigNumber.config({ DECIMAL_PLACES: 50, POW_PRECISION: 50, EXPONENTIAL_AT: 20 });
const client = createPublicClient({
chain: mainnet,
try {
positionData = await retryOnRateLimit(() => client.readContract({
address: "0xc36442b4a4522e871399cd717abdd847ab11fe88",
abi: parseAbi([
"function positions(uint256 tokenId) external view returns (uint96 nonce, address operator, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1)",
functionName: "positions",
liquidity,
feeGrowthInside0LastX128,
feeGrowthInside1LastX128,
tokensOwed0,
try {
tokenData = await retryOnRateLimit(() => client.multicall({
contracts: [
try {
poolAddress = await retryOnRateLimit(() => client.readContract({
address: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
try {
slot0Data = await retryOnRateLimit(() => client.readContract({
address: poolAddress,
list_the_facts
@robsimmons
An interactive, runnable TypeScript val by robsimmons
Script
import { Dusa } from "https://unpkg.com/dusa@0.1.4/lib/client.js";
const dusa = new Dusa(`
#builtin INT_MINUS minus
sqlite_docs
@andreterron
Val Town SQLite - https://docs.val.town/std/sqlite
Script
import { API_URL } from "https://esm.town/v/std/API_URL";
import { LibsqlError, type TransactionMode } from "npm:@libsql/client";
import { z } from "npm:zod";
* Every Val Town account comes with its own private
captcha
@loading
Captcha The Game
HTTP
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
import React, { useEffect, useRef, useState } from "https://esm.sh/react@18.2.0";
type Category = "bicycle" | "palm" | "hydrant" | "crosswalk";
</div>
function client() {
createRoot(document.getElementById("root")!).render(<App />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {