Skip to content

Send Funds Holesky → Sepolia

import {
import Evm
Evm
,
import EvmZkgmClient
EvmZkgmClient
} from "@unionlabs/sdk-evm"
import {
class ChainRegistry

@since2.0.0

ChainRegistry
} from "@unionlabs/sdk/ChainRegistry"
import {
type UniversalChainId = string & Brand<"UniversalChainId">
const UniversalChainId: brand<filter<typeof String$>, "UniversalChainId">
UniversalChainId
} from "@unionlabs/sdk/schema/chain"
import {
type ChannelId = number & Brand<"ChannelId">
const ChannelId: brand<typeof Int, "ChannelId">
ChannelId
} from "@unionlabs/sdk/schema/channel"
import * as
import TokenOrder
TokenOrder
from "@unionlabs/sdk/TokenOrder"
import * as
import ZkgmClient
ZkgmClient
from "@unionlabs/sdk/ZkgmClient"
import * as
import ZkgmClientRequest
ZkgmClientRequest
from "@unionlabs/sdk/ZkgmClientRequest"
import * as
import ZkgmClientResponse
ZkgmClientResponse
from "@unionlabs/sdk/ZkgmClientResponse"
import * as
import ZkgmIncomingMessage
ZkgmIncomingMessage
from "@unionlabs/sdk/ZkgmIncomingMessage"
import {
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
,
import Logger
Logger
} from "effect"
import {
function http<rpcSchema extends RpcSchema | undefined = undefined, raw extends boolean = false>(url?: string | undefined, config?: HttpTransportConfig<rpcSchema, raw>): HttpTransport<rpcSchema, raw>

@description Creates a HTTP transport that connects to a JSON-RPC API.

http
} from "viem"
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from "viem/accounts"
import {
const holesky: {
blockExplorers: {
readonly default: {
readonly name: "Etherscan";
readonly url: "https://holesky.etherscan.io";
readonly apiUrl: "https://api-holesky.etherscan.io/api";
};
};
... 13 more ...;
serializers?: ChainSerializers<...> | undefined;
}
holesky
} from "viem/chains"
const
const program: Effect.Effect<void, ChainRegistryError | ParseError | ClientError | Evm.CreateWalletClientError | Evm.CreatePublicClientError, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const gen: <YieldWrap<Effect.Effect<Chain, ChainRegistryError, ChainRegistry>> | YieldWrap<Effect.Effect<TokenOrder.TokenOrder, ParseError, never>> | YieldWrap<...> | YieldWrap<...> | YieldWrap<...> | YieldWrap<...>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)

Provides a way to write effectful code using generator functions, simplifying control flow and error handling.

When to Use

Effect.gen allows you to write code that looks and behaves like synchronous code, but it can handle asynchronous tasks, errors, and complex control flow (like loops and conditions). It helps make asynchronous code more readable and easier to manage.

The generator functions work similarly to async/await but with more explicit control over the execution of effects. You can yield* values from effects and return the final result at the end.

Example

import { Effect } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const applyDiscount = (
total: number,
discountRate: number
): Effect.Effect<number, Error> =>
discountRate === 0
? Effect.fail(new Error("Discount rate cannot be zero"))
: Effect.succeed(total - (total * discountRate) / 100)
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
export const program = Effect.gen(function* () {
const transactionAmount = yield* fetchTransactionAmount
const discountRate = yield* fetchDiscountRate
const discountedAmount = yield* applyDiscount(
transactionAmount,
discountRate
)
const finalAmount = addServiceCharge(discountedAmount)
return `Final amount to charge: ${finalAmount}`
})

@since2.0.0

gen
(function*() {
const
const source: Chain
source
= yield*
class ChainRegistry

@since2.0.0

ChainRegistry
.
byUniversalId: (id: string & Brand<"UniversalChainId">) => Effect.Effect<Chain, ChainRegistryError, ChainRegistry>
byUniversalId
(
const UniversalChainId: brand<filter<typeof String$>, "UniversalChainId">
UniversalChainId
.
BrandSchema<string & Brand<"UniversalChainId">, string, never>.make(a: string, options?: MakeOptions): string & Brand<"UniversalChainId">
make
("ethereum.17000"),
)
const
const destination: Chain
destination
= yield*
class ChainRegistry

@since2.0.0

ChainRegistry
.
byUniversalId: (id: string & Brand<"UniversalChainId">) => Effect.Effect<Chain, ChainRegistryError, ChainRegistry>
byUniversalId
(
const UniversalChainId: brand<filter<typeof String$>, "UniversalChainId">
UniversalChainId
.
BrandSchema<string & Brand<"UniversalChainId">, string, never>.make(a: string, options?: MakeOptions): string & Brand<"UniversalChainId">
make
("ethereum.11155111"),
)
const
const tokenOrder: TokenOrder.TokenOrder
tokenOrder
= yield*
import TokenOrder
TokenOrder
.
const make: <{
source: Chain;
destination: Chain;
sender: string;
receiver: string;
baseToken: string;
baseAmount: bigint;
quoteToken: string;
quoteAmount: bigint;
kind: "escrow";
metadata: undefined;
version: 2;
}>(value: {
source: Chain;
destination: Chain;
sender: string;
receiver: string;
baseToken: string;
baseAmount: bigint;
quoteToken: string;
quoteAmount: bigint;
kind: "escrow";
metadata: undefined;
version: 2;
}) => Effect.Effect<...>

@since2.0.0

make
({
source: Chain
source
,
destination: Chain
destination
,
sender: string
sender
: "0x06627714f3F17a701f7074a12C02847a5D2Ca487",
receiver: string
receiver
: "0x50A22f95bcB21E7bFb63c7A8544AC0683dCeA302",
// LINK on Holesky
baseToken: string
baseToken
: "0x685ce6742351ae9b618f383883d6d1e0c5a31b4b",
baseAmount: bigint
baseAmount
: 10n,
// Holesky LINK on Sepolia
quoteToken: string
quoteToken
: "0x80fdbf104ec58a527ec40f7b03f88c404ef4ba63",
quoteAmount: bigint
quoteAmount
: 10n,
kind: "escrow"
kind
: "escrow",
metadata: undefined
metadata
:
var undefined
undefined
,
version: 2
version
: 2,
})
yield*
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const log: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>

Logs one or more messages or error causes at the current log level.

Details

This function provides a simple way to log messages or error causes during the execution of your effects. By default, logs are recorded at the INFO level, but this can be adjusted using other logging utilities (Logger.withMinimumLogLevel). Multiple items, including Cause instances, can be logged in a single call. When logging Cause instances, detailed error information is included in the log output.

The log output includes useful metadata like the current timestamp, log level, and fiber ID, making it suitable for debugging and tracking purposes. This function does not interrupt or alter the effect's execution flow.

Example

import { Cause, Effect } from "effect"
const program = Effect.log(
"message1",
"message2",
Cause.die("Oh no!"),
Cause.die("Oh uh!")
)
Effect.runFork(program)
// Output:
// timestamp=... level=INFO fiber=#0 message=message1 message=message2 cause="Error: Oh no!
// Error: Oh uh!"

@since2.0.0

log
("Token Order V2",
const tokenOrder: TokenOrder.TokenOrder
tokenOrder
)
const
const request: ZkgmClientRequest.ZkgmClientRequest
request
=
import ZkgmClientRequest
ZkgmClientRequest
.
const make: (options: {
source: Chain;
destination: Chain;
channelId: ChannelId;
ucs03Address: string;
instruction: ZkgmInstruction;
}) => ZkgmClientRequest.ZkgmClientRequest

@since2.0.0

make
({
source: Chain
source
,
destination: Chain
destination
,
channelId: number & Brand<"ChannelId">
channelId
:
const ChannelId: brand<typeof Int, "ChannelId">
ChannelId
.
BrandSchema<number & Brand<"ChannelId">, number, never>.make(a: number, options?: MakeOptions): number & Brand<"ChannelId">
make
(2),
ucs03Address: string
ucs03Address
: "0x5fbe74a283f7954f10aa04c2edf55578811aeb03",
instruction: ZkgmInstruction
instruction
:
const tokenOrder: TokenOrder.TokenOrder
tokenOrder
,
})
const
const zkgmClient: ZkgmClient.ZkgmClient
zkgmClient
= yield*
import ZkgmClient
ZkgmClient
.
const ZkgmClient: Tag<ZkgmClient.ZkgmClient, ZkgmClient.ZkgmClient>

@since2.0.0

@since2.0.0

@since2.0.0

ZkgmClient
// NOTE: 1. switch chain is assumed
// NOTE: 2. write in progress
const
const response: ZkgmClientResponse.ZkgmClientResponse
response
:
import ZkgmClientResponse
ZkgmClientResponse
.
interface ZkgmClientResponse

@since2.0.0

ZkgmClientResponse
= yield*
const zkgmClient: ZkgmClient.ZkgmClient
zkgmClient
.
ZkgmClient.With<ClientError, never>.execute: (request: ZkgmClientRequest.ZkgmClientRequest) => Effect.Effect<ZkgmClientResponse.ZkgmClientResponse, ClientError, never>
execute
(
const request: ZkgmClientRequest.ZkgmClientRequest
request
)
// NOTE: 3. write complete (with tx hash)
yield*
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const log: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>

Logs one or more messages or error causes at the current log level.

Details

This function provides a simple way to log messages or error causes during the execution of your effects. By default, logs are recorded at the INFO level, but this can be adjusted using other logging utilities (Logger.withMinimumLogLevel). Multiple items, including Cause instances, can be logged in a single call. When logging Cause instances, detailed error information is included in the log output.

The log output includes useful metadata like the current timestamp, log level, and fiber ID, making it suitable for debugging and tracking purposes. This function does not interrupt or alter the effect's execution flow.

Example

import { Cause, Effect } from "effect"
const program = Effect.log(
"message1",
"message2",
Cause.die("Oh no!"),
Cause.die("Oh uh!")
)
Effect.runFork(program)
// Output:
// timestamp=... level=INFO fiber=#0 message=message1 message=message2 cause="Error: Oh no!
// Error: Oh uh!"

@since2.0.0

log
("Submission Hash",
const response: ZkgmClientResponse.ZkgmClientResponse
response
.
ZkgmClientResponse.txHash: `0x${string}`
txHash
)
const
const completion: Option<{
readonly _tag: "EvmTransactionReceiptComplete";
readonly transactionHash: Hex & Brand<"Hash">;
readonly blockHash: Hex & Brand<"Hash">;
readonly gasUsed: bigint;
}>
completion
= yield*
const response: ZkgmClientResponse.ZkgmClientResponse
response
.
ZkgmIncomingMessage<ResponseError>.waitFor: <{
readonly _tag: "EvmTransactionReceiptComplete";
readonly transactionHash: Hex & Brand<"Hash">;
readonly blockHash: Hex & Brand<"Hash">;
readonly gasUsed: bigint;
}>(refinement: Refinement<...>) => Effect.Effect<...>

  • add default ucompletion handler (index)
  • allow pred fn

waitFor
(
import ZkgmIncomingMessage
ZkgmIncomingMessage
.
const LifecycleEvent: {
readonly EvmTransactionReceiptComplete: Case.Constructor<{
readonly _tag: "EvmTransactionReceiptComplete";
readonly transactionHash: Hex & Brand<"Hash">;
readonly blockHash: Hex & Brand<"Hash">;
readonly gasUsed: bigint;
}, "_tag">;
readonly WaitForSafeWalletHash: Case.Constructor<...>;
readonly Indexed: Case.Constructor<...>;
readonly $is: <Tag extends "EvmTransactionReceiptComplete" | ... 1 more ... | "Indexed">(tag: Tag) => (u: unknown) => u is Extract<...> | ... 1 more ... | Extract<...>;
readonly $match: {
...;
};
}

@since2.0.0

@since2.0.0

LifecycleEvent
.
$is: <"EvmTransactionReceiptComplete">(tag: "EvmTransactionReceiptComplete") => (u: unknown) => u is {
readonly _tag: "EvmTransactionReceiptComplete";
readonly transactionHash: Hex & Brand<"Hash">;
readonly blockHash: Hex & Brand<"Hash">;
readonly gasUsed: bigint;
}
$is
("EvmTransactionReceiptComplete"),
)
// NOTE: 4. tx complete
yield*
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const log: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>

Logs one or more messages or error causes at the current log level.

Details

This function provides a simple way to log messages or error causes during the execution of your effects. By default, logs are recorded at the INFO level, but this can be adjusted using other logging utilities (Logger.withMinimumLogLevel). Multiple items, including Cause instances, can be logged in a single call. When logging Cause instances, detailed error information is included in the log output.

The log output includes useful metadata like the current timestamp, log level, and fiber ID, making it suitable for debugging and tracking purposes. This function does not interrupt or alter the effect's execution flow.

Example

import { Cause, Effect } from "effect"
const program = Effect.log(
"message1",
"message2",
Cause.die("Oh no!"),
Cause.die("Oh uh!")
)
Effect.runFork(program)
// Output:
// timestamp=... level=INFO fiber=#0 message=message1 message=message2 cause="Error: Oh no!
// Error: Oh uh!"

@since2.0.0

log
("Completion",
const completion: Option<{
readonly _tag: "EvmTransactionReceiptComplete";
readonly transactionHash: Hex & Brand<"Hash">;
readonly blockHash: Hex & Brand<"Hash">;
readonly gasUsed: bigint;
}>
completion
)
}).
Pipeable.pipe<Effect.Effect<void, ChainRegistryError | ParseError | ClientError, ChainRegistry | ZkgmClient.ZkgmClient>, Effect.Effect<...>, Effect.Effect<...>, Effect.Effect<...>, Effect.Effect<...>, Effect.Effect<...>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>, cd: (_: Effect.Effect<...>) => Effect.Effect<...>, de: (_: Effect.Effect<...>) => Effect.Effect<...>, ef: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <ZkgmClient.ZkgmClient, never, Evm.WalletClient | Evm.PublicClient>(layer: Layer<ZkgmClient.ZkgmClient, never, Evm.WalletClient | Evm.PublicClient>) => <A, E, R>(self: Effect.Effect<...>) => Effect.Effect<...> (+9 overloads)

Provides necessary dependencies to an effect, removing its environmental requirements.

Details

This function allows you to supply the required environment for an effect. The environment can be provided in the form of one or more Layers, a Context, a Runtime, or a ManagedRuntime. Once the environment is provided, the effect can run without requiring external dependencies.

You can compose layers to create a modular and reusable way of setting up the environment for effects. For example, layers can be used to configure databases, logging services, or any other required dependencies.

Example

import { Context, Effect, Layer } from "effect"
class Database extends Context.Tag("Database")<
Database,
{ readonly query: (sql: string) => Effect.Effect<Array<unknown>> }
>() {}
const DatabaseLive = Layer.succeed(
Database,
{
// Simulate a database query
query: (sql: string) => Effect.log(`Executing query: ${sql}`).pipe(Effect.as([]))
}
)
// ┌─── Effect<unknown[], never, Database>
// ▼
const program = Effect.gen(function*() {
const database = yield* Database
const result = yield* database.query("SELECT * FROM users")
return result
})
// ┌─── Effect<unknown[], never, never>
// ▼
const runnable = Effect.provide(program, DatabaseLive)
Effect.runPromise(runnable).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="Executing query: SELECT * FROM users"
// []

@seeprovideService for providing a service to an effect.

@since2.0.0

provide
(
import EvmZkgmClient
EvmZkgmClient
.
const layerWithoutWallet: Layer<ZkgmClient.ZkgmClient, never, Evm.WalletClient | Evm.PublicClient>

@since0.0.0

layerWithoutWallet
),
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <Evm.WalletClient, Evm.CreateWalletClientError, never>(layer: Layer<Evm.WalletClient, Evm.CreateWalletClientError, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Provides necessary dependencies to an effect, removing its environmental requirements.

Details

This function allows you to supply the required environment for an effect. The environment can be provided in the form of one or more Layers, a Context, a Runtime, or a ManagedRuntime. Once the environment is provided, the effect can run without requiring external dependencies.

You can compose layers to create a modular and reusable way of setting up the environment for effects. For example, layers can be used to configure databases, logging services, or any other required dependencies.

Example

import { Context, Effect, Layer } from "effect"
class Database extends Context.Tag("Database")<
Database,
{ readonly query: (sql: string) => Effect.Effect<Array<unknown>> }
>() {}
const DatabaseLive = Layer.succeed(
Database,
{
// Simulate a database query
query: (sql: string) => Effect.log(`Executing query: ${sql}`).pipe(Effect.as([]))
}
)
// ┌─── Effect<unknown[], never, Database>
// ▼
const program = Effect.gen(function*() {
const database = yield* Database
const result = yield* database.query("SELECT * FROM users")
return result
})
// ┌─── Effect<unknown[], never, never>
// ▼
const runnable = Effect.provide(program, DatabaseLive)
Effect.runPromise(runnable).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="Executing query: SELECT * FROM users"
// []

@seeprovideService for providing a service to an effect.

@since2.0.0

provide
(
import Evm
Evm
.
class WalletClient

A wallet client that can be used for signing transactions

@since0.0.0

WalletClient
.
WalletClient.Live: (options: Parameters<typeof createWalletClient>[0] & {
account: Account;
chain: Chain;
}) => Layer<...>
Live
({
account: {
client: Client<Transport, Chain | undefined, {
address: Address;
nonceManager?: NonceManager | undefined;
sign?: ((parameters: {
hash: Hash;
}) => Promise<Hex>) | undefined | undefined;
... 6 more ...;
type: "local";
} | JsonRpcAccount | undefined>;
... 22 more ...;
source?: undefined;
} | ... 6 more ... | (`0x${string}` & {
...;
})

The Account to use for the Client. This will be used for Actions that require an account as an argument.

account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
(
(
var process: NodeJS.Process
process
.
NodeJS.Process.env: NodeJS.ProcessEnv

The process.env property returns an object containing the user environment. See environ(7).

An example of this object looks like:

{
TERM: 'xterm-256color',
SHELL: '/usr/local/bin/bash',
USER: 'maciej',
PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
PWD: '/Users/maciej',
EDITOR: 'vim',
SHLVL: '1',
HOME: '/Users/maciej',
LOGNAME: 'maciej',
_: '/usr/local/bin/node'
}

It is possible to modify this object, but such modifications will not be reflected outside the Node.js process, or (unless explicitly requested) to other Worker threads. In other words, the following example would not work:

Terminal window
node -e 'process.env.foo = "bar"' &#x26;&#x26; echo $foo

While the following will:

import { env } from 'node:process';
env.foo = 'bar';
console.log(env.foo);

Assigning a property on process.env will implicitly convert the value to a string. This behavior is deprecated. Future versions of Node.js may throw an error when the value is not a string, number, or boolean.

import { env } from 'node:process';
env.test = null;
console.log(env.test);
// => 'null'
env.test = undefined;
console.log(env.test);
// => 'undefined'

Use delete to delete a property from process.env.

import { env } from 'node:process';
env.TEST = 1;
delete env.TEST;
console.log(env.TEST);
// => undefined

On Windows operating systems, environment variables are case-insensitive.

import { env } from 'node:process';
env.TEST = 1;
console.log(env.test);
// => 1

Unless explicitly specified when creating a Worker instance, each Worker thread has its own copy of process.env, based on its parent thread's process.env, or whatever was specified as the env option to the Worker constructor. Changes to process.env will not be visible across Worker threads, and only the main thread can make changes that are visible to the operating system or to native add-ons. On Windows, a copy of process.env on a Worker instance operates in a case-sensitive manner unlike the main thread.

@sincev0.1.27

env
.
string | undefined
KEY
as any) ?? "0x...",
),
chain: {
blockExplorers?: {
[key: string]: ChainBlockExplorer;
default: ChainBlockExplorer;
} | undefined;
... 9 more ...;
testnet?: boolean | undefined;
} & ChainConfig<...>

Chain for the client.

chain
:
const holesky: {
blockExplorers: {
readonly default: {
readonly name: "Etherscan";
readonly url: "https://holesky.etherscan.io";
readonly apiUrl: "https://api-holesky.etherscan.io/api";
};
};
... 13 more ...;
serializers?: ChainSerializers<...> | undefined;
}
holesky
,
transport: Transport

The RPC transport

transport
:
http<undefined, false>(url?: string | undefined, config?: HttpTransportConfig<undefined, false> | undefined): HttpTransport<undefined, false>

@description Creates a HTTP transport that connects to a JSON-RPC API.

http
("https://rpc.17000.ethereum.chain.kitchen"),
})),
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <Evm.PublicClient, Evm.CreatePublicClientError, never>(layer: Layer<Evm.PublicClient, Evm.CreatePublicClientError, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Provides necessary dependencies to an effect, removing its environmental requirements.

Details

This function allows you to supply the required environment for an effect. The environment can be provided in the form of one or more Layers, a Context, a Runtime, or a ManagedRuntime. Once the environment is provided, the effect can run without requiring external dependencies.

You can compose layers to create a modular and reusable way of setting up the environment for effects. For example, layers can be used to configure databases, logging services, or any other required dependencies.

Example

import { Context, Effect, Layer } from "effect"
class Database extends Context.Tag("Database")<
Database,
{ readonly query: (sql: string) => Effect.Effect<Array<unknown>> }
>() {}
const DatabaseLive = Layer.succeed(
Database,
{
// Simulate a database query
query: (sql: string) => Effect.log(`Executing query: ${sql}`).pipe(Effect.as([]))
}
)
// ┌─── Effect<unknown[], never, Database>
// ▼
const program = Effect.gen(function*() {
const database = yield* Database
const result = yield* database.query("SELECT * FROM users")
return result
})
// ┌─── Effect<unknown[], never, never>
// ▼
const runnable = Effect.provide(program, DatabaseLive)
Effect.runPromise(runnable).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="Executing query: SELECT * FROM users"
// []

@seeprovideService for providing a service to an effect.

@since2.0.0

provide
(
import Evm
Evm
.
class PublicClient

A neutral public client that can be used for general-purpose operations that don't specifically target source or destination chains

@since0.0.0

PublicClient
.
PublicClient.Live: (parameters: {
key?: string | undefined | undefined;
name?: string | undefined | undefined;
cacheTime?: number | undefined | undefined;
ccipRead?: {
request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>;
} | false | undefined | undefined;
... 5 more ...;
experimental_blockTag?: BlockTag | undefined;
}) => Layer<...>
Live
({
chain?: Chain | undefined

Chain for the client.

chain
:
const holesky: {
blockExplorers: {
readonly default: {
readonly name: "Etherscan";
readonly url: "https://holesky.etherscan.io";
readonly apiUrl: "https://api-holesky.etherscan.io/api";
};
};
... 13 more ...;
serializers?: ChainSerializers<...> | undefined;
}
holesky
,
transport: Transport

The RPC transport

transport
:
http<undefined, false>(url?: string | undefined, config?: HttpTransportConfig<undefined, false> | undefined): HttpTransport<undefined, false>

@description Creates a HTTP transport that connects to a JSON-RPC API.

http
("https://rpc.17000.ethereum.chain.kitchen"),
})),
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <ChainRegistry, never, never>(layer: Layer<ChainRegistry, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<...> (+9 overloads)

Provides necessary dependencies to an effect, removing its environmental requirements.

Details

This function allows you to supply the required environment for an effect. The environment can be provided in the form of one or more Layers, a Context, a Runtime, or a ManagedRuntime. Once the environment is provided, the effect can run without requiring external dependencies.

You can compose layers to create a modular and reusable way of setting up the environment for effects. For example, layers can be used to configure databases, logging services, or any other required dependencies.

Example

import { Context, Effect, Layer } from "effect"
class Database extends Context.Tag("Database")<
Database,
{ readonly query: (sql: string) => Effect.Effect<Array<unknown>> }
>() {}
const DatabaseLive = Layer.succeed(
Database,
{
// Simulate a database query
query: (sql: string) => Effect.log(`Executing query: ${sql}`).pipe(Effect.as([]))
}
)
// ┌─── Effect<unknown[], never, Database>
// ▼
const program = Effect.gen(function*() {
const database = yield* Database
const result = yield* database.query("SELECT * FROM users")
return result
})
// ┌─── Effect<unknown[], never, never>
// ▼
const runnable = Effect.provide(program, DatabaseLive)
Effect.runPromise(runnable).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="Executing query: SELECT * FROM users"
// []

@seeprovideService for providing a service to an effect.

@since2.0.0

provide
(
class ChainRegistry

@since2.0.0

ChainRegistry
.
type Default: Layer<ChainRegistry, never, never>
Default
),
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <never, never, never>(layer: Layer<never, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, never>> (+9 overloads)

Provides necessary dependencies to an effect, removing its environmental requirements.

Details

This function allows you to supply the required environment for an effect. The environment can be provided in the form of one or more Layers, a Context, a Runtime, or a ManagedRuntime. Once the environment is provided, the effect can run without requiring external dependencies.

You can compose layers to create a modular and reusable way of setting up the environment for effects. For example, layers can be used to configure databases, logging services, or any other required dependencies.

Example

import { Context, Effect, Layer } from "effect"
class Database extends Context.Tag("Database")<
Database,
{ readonly query: (sql: string) => Effect.Effect<Array<unknown>> }
>() {}
const DatabaseLive = Layer.succeed(
Database,
{
// Simulate a database query
query: (sql: string) => Effect.log(`Executing query: ${sql}`).pipe(Effect.as([]))
}
)
// ┌─── Effect<unknown[], never, Database>
// ▼
const program = Effect.gen(function*() {
const database = yield* Database
const result = yield* database.query("SELECT * FROM users")
return result
})
// ┌─── Effect<unknown[], never, never>
// ▼
const runnable = Effect.provide(program, DatabaseLive)
Effect.runPromise(runnable).then(console.log)
// Output:
// timestamp=... level=INFO fiber=#0 message="Executing query: SELECT * FROM users"
// []

@seeprovideService for providing a service to an effect.

@since2.0.0

provide
(
import Logger
Logger
.
const replace: <void, void>(self: Logger.Logger<unknown, void>, that: Logger.Logger<unknown, void>) => Layer<never> (+1 overload)

@since2.0.0

replace
(
import Logger
Logger
.
const defaultLogger: Logger.Logger<unknown, void>

@since2.0.0

defaultLogger
,
import Logger
Logger
.
const prettyLoggerDefault: Logger.Logger<unknown, void>

A default version of the pretty logger.

@since3.8.0

prettyLoggerDefault
)),
)
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runPromise: <void, ChainRegistryError | ParseError | ClientError | Evm.CreateWalletClientError | Evm.CreatePublicClientError>(effect: Effect.Effect<...>, options?: {
readonly signal?: AbortSignal;
} | undefined) => Promise<...>

Executes an effect and returns the result as a Promise.

Details

This function runs an effect and converts its result into a Promise. If the effect succeeds, the Promise will resolve with the successful result. If the effect fails, the Promise will reject with an error, which includes the failure details of the effect.

The optional options parameter allows you to pass an AbortSignal for cancellation, enabling more fine-grained control over asynchronous tasks.

When to Use

Use this function when you need to execute an effect and work with its result in a promise-based system, such as when integrating with third-party libraries that expect Promise results.

Example (Running a Successful Effect as a Promise)

import { Effect } from "effect"
Effect.runPromise(Effect.succeed(1)).then(console.log)
// Output: 1

Example (Handling a Failing Effect as a Rejected Promise)

import { Effect } from "effect"
Effect.runPromise(Effect.fail("my error")).catch(console.error)
// Output:
// (FiberFailure) Error: my error

@seerunPromiseExit for a version that returns an Exit type instead of rejecting.

@since2.0.0

runPromise
(
const program: Effect.Effect<void, ChainRegistryError | ParseError | ClientError | Evm.CreateWalletClientError | Evm.CreatePublicClientError, never>
program
)
.
Promise<void>.then<void, never>(onfulfilled?: ((value: void) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

@paramonfulfilled The callback to execute when the Promise is resolved.

@paramonrejected The callback to execute when the Promise is rejected.

@returnsA Promise for the completion of which ever callback is executed.

then
(
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(...data: any[]): void (+1 overload)
log
)
.
Promise<void>.catch<void>(onrejected?: ((reason: any) => void | PromiseLike<void>) | null | undefined): Promise<void>

Attaches a callback for only the rejection of the Promise.

@paramonrejected The callback to execute when the Promise is rejected.

@returnsA Promise for the completion of the callback.

catch
(
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.error(...data: any[]): void (+1 overload)

Log to stderr in your terminal

Appears in red

@paramdata something to display

error
)