Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Set up pnpm
uses: pnpm/action-setup@v4
uses: pnpm/action-setup@v6
with:
version: 9.15.9

- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
Expand All @@ -39,5 +39,8 @@ jobs:
- name: Build
run: pnpm build

- name: Test
run: pnpm test
- name: Validate published package
run: pnpm check:package

- name: Test with coverage
run: pnpm test:coverage
26 changes: 13 additions & 13 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Set up pnpm
uses: pnpm/action-setup@v4
uses: pnpm/action-setup@v6
with:
version: 9.15.9

- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
Expand All @@ -48,7 +48,7 @@ jobs:
run: pnpm docs:build

- name: Upload build output
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: docs-dist
path: site/dist/public
Expand All @@ -66,15 +66,15 @@ jobs:
url: https://contract.tevm.sh
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Set up pnpm
uses: pnpm/action-setup@v4
uses: pnpm/action-setup@v6
with:
version: 9.15.9

- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
Expand All @@ -85,10 +85,10 @@ jobs:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
run: |
if [ -z "$VERCEL_TOKEN" ]; then
echo "::warning::VERCEL_TOKEN is not set; skipping deploy."
exit 0
if [ -z "$VERCEL_ORG_ID" ] || [ -z "$VERCEL_PROJECT_ID" ] || [ -z "$VERCEL_TOKEN" ]; then
echo "::error::VERCEL_ORG_ID, VERCEL_PROJECT_ID, and VERCEL_TOKEN are required."
exit 1
fi
npx --yes vercel@latest pull --yes --environment=production --token="$VERCEL_TOKEN" --cwd site
npx --yes vercel@latest build --prod --token="$VERCEL_TOKEN" --cwd site
npx --yes vercel@latest deploy --prebuilt --prod --token="$VERCEL_TOKEN" --cwd site
npx --yes vercel@58.4.0 pull --yes --environment=production --token="$VERCEL_TOKEN" --cwd site
npx --yes vercel@58.4.0 build --prod --token="$VERCEL_TOKEN" --cwd site
npx --yes vercel@58.4.0 deploy --prebuilt --prod --token="$VERCEL_TOKEN" --cwd site
24 changes: 18 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,42 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Set up pnpm
uses: pnpm/action-setup@v4
uses: pnpm/action-setup@v6
with:
version: 9.15.9

- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
registry-url: https://registry.npmjs.org

- name: Ensure npm supports provenance
run: npm install --global npm@latest

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm lint

- name: Typecheck
run: pnpm typecheck

- name: Build
run: pnpm build

- name: Validate published package
run: pnpm check:package

- name: Test with coverage
run: pnpm test:coverage

- name: Create release PR or publish
uses: changesets/action@v1
with:
Expand All @@ -50,5 +64,3 @@ jobs:
title: "chore: version packages"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# @tevm/contract

`@tevm/contract` is Tevm's shared, type-safe contract kernel. It defines the contract surface used by both the
[Tevm core node](https://github.com/evmts/tevm-monorepo) and Tevm's bundler packages, so contract descriptions and
[Tevm core node](https://github.com/evmts/tevm) and Tevm's bundler packages, so contract descriptions and
generated actions have one stable representation across the ecosystem.

This repository is the standalone home of the package formerly maintained at `packages/contract` in the Tevm
Expand All @@ -16,6 +16,10 @@ pnpm add @tevm/contract
The package does not require a Tevm node at runtime. Consumers that execute the actions produced here should install
the appropriate Tevm client separately.

The package temporarily consumes the published `@tevm/utils` compatibility package from Tevm core. That dependency
will be replaced by [Voltaire](https://github.com/evmts/voltaire); there is intentionally no standalone
`tevm-utils` repository.

## Usage

```ts
Expand Down
5 changes: 3 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"preset": "recommended",
"style": {
"useImportType": "off",
"noNonNullAssertion": "off"
Expand All @@ -99,7 +99,8 @@
"complexity": {
"noForEach": "off",
"noBannedTypes": "off",
"useLiteralKeys": "off"
"useLiteralKeys": "off",
"noImportantStyles": "off"
},
"suspicious": {
"noExplicitAny": "off",
Expand Down
45 changes: 18 additions & 27 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,27 @@

***

<p align="center">
<a href="https://tevm.sh/">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/35039927/218812217-92f0f784-cb85-43b9-9ca6-e2b9effd9eb2.png">
<img alt="wagmi logo" src="https://user-images.githubusercontent.com/35039927/218812217-92f0f784-cb85-43b9-9ca6-e2b9effd9eb2.png" width="auto" height="300">
</picture>
</a>
</p>
# @tevm/contract

<p align="center">
Execute solidity scripts in browser
</p>
## Type Aliases

[![CI](https://github.com/evmts/tevm-monorepo/actions/workflows/e2e.yml/badge.svg)](https://github.com/evmts/tevm-monorepo/actions/workflows/e2e.yml)
[![CI](https://github.com/evmts/tevm-monorepo/actions/workflows/unit.yml/badge.svg)](https://github.com/evmts/tevm-monorepo/actions/workflows/unit.yml)
<a href="https://www.npmjs.com/package/@tevm/contracts" target="\_parent">
<img alt="" src="https://img.shields.io/npm/dm/@tevm/contracts.svg" />
</a>
<a href="https://bundlephobia.com/package/@tevm/contracts@latest" target="\_parent">
<img alt="" src="https://badgen.net/bundlephobia/minzip/@tevm/contracts" />
</a>
- [Contract](type-aliases/Contract.md)
- [CreateContractFn](type-aliases/CreateContractFn.md)
- [CreateContractParams](type-aliases/CreateContractParams.md)
- [EventActionCreator](type-aliases/EventActionCreator.md)
- [MaybeExtractEventArgsFromAbi](type-aliases/MaybeExtractEventArgsFromAbi.md)
- [ReadActionCreator](type-aliases/ReadActionCreator.md)
- [ValueOf](type-aliases/ValueOf.md)
- [WriteActionCreator](type-aliases/WriteActionCreator.md)

# tevm-monorepo
## Variables

tevm enables direct evm execution clientside with forge cheat codes and direct solidity file imports.
- [AdvancedContract](variables/AdvancedContract.md)
- [ERC20](variables/ERC20.md)
- [ERC721](variables/ERC721.md)
- [ErrorContract](variables/ErrorContract.md)
- [SimpleContract](variables/SimpleContract.md)

## Visit [Docs](https://tevm.sh/) for docs, guides, API and more!
## Functions

## See [Tevm Beta project board](https://github.com/orgs/tevm/projects/1) for progress on the upcoming beta release

## License 📄

<a href="_media/LICENSE"><img src="https://user-images.githubusercontent.com/35039927/231030761-66f5ce58-a4e9-4695-b1fe-255b1bceac92.png" width="200" /></a>
- [createContract](functions/createContract.md)
22 changes: 0 additions & 22 deletions docs/_media/LICENSE

This file was deleted.

62 changes: 34 additions & 28 deletions docs/functions/createContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

***

[@tevm/contract](../globals.md) / createContract
[@tevm/contract](../README.md) / createContract

# Function: createContract()

> **createContract**\<`TName`, `TAbi`, `TAddress`, `TBytecode`, `TDeployedBytecode`, `TCode`, `THumanReadableAbi`\>(`__namedParameters`): [`Contract`](../type-aliases/Contract.md)\<`TName`, `THumanReadableAbi`, `TAddress`, `TBytecode`, `TDeployedBytecode`, `TCode`\>

Defined in: [createContract.js:73](https://github.com/evmts/tevm-monorepo/blob/main/packages/contract/src/createContract.js#L73)
Defined in: [createContract.js:73](https://github.com/evmts/tevm-contract/blob/main/src/createContract.js#L73)

Creates a Tevm Contract instance from a human-readable ABI or JSON ABI.
This function is the core of Tevm's contract interaction capabilities,
Expand Down Expand Up @@ -40,11 +40,19 @@ allowing for type-safe and easy-to-use contract interfaces.

If neither humanReadableAbi nor abi is provided.

## Throws

If `address` is not a valid Ethereum address.

## Throws

If a human-readable ABI item cannot be parsed.

## Examples

Using a human-readable ABI:
```typescript
import { createContract } from 'tevm/contract'
import { createContract } from '@tevm/contract'

const contract = createContract({
name: 'ERC20',
Expand All @@ -56,46 +64,44 @@ const contract = createContract({
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F' // DAI token address
})

// Read contract state
const balanceAction = contract.read.balanceOf('0x1234...')
const balance = await tevm.contract(balanceAction)

// Write to contract
const transferAction = contract.write.transfer('0x5678...', 1000n)
const result = await tevm.contract(transferAction)

// Create event filter
const transferFilter = contract.events.Transfer({ fromBlock: 'latest' })
const logs = await tevm.eth.getLogs(transferFilter)
const balanceAction = contract.read.balanceOf(
'0x0000000000000000000000000000000000000001',
)
const transferAction = contract.write.transfer(
'0x0000000000000000000000000000000000000002',
1000n,
)
const transferFilter = contract.events.Transfer({
fromBlock: 'latest',
args: { from: contract.address },
})
```

Using a JSON ABI:
```typescript
import { createContract } from 'tevm/contract'
import { createContract } from '@tevm/contract'

const contract = createContract({
name: 'ERC20',
abi: [
{
"inputs": [{"name": "account", "type": "address"}],
"name": "balanceOf",
"outputs": [{"type": "uint256"}],
"stateMutability": "view",
"type": "function"
inputs: [{ name: 'account', type: 'address' }],
name: 'balanceOf',
outputs: [{ type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
// ... other ABI entries
],
] as const,
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
bytecode: '0x60806040...', // Optional: Creation bytecode
deployedBytecode: '0x608060405...', // Optional: Deployed bytecode
code: '0x608060405...' // Optional: Runtime bytecode
})

// Use the contract as in the previous example
const action = contract.read.balanceOf(
'0x0000000000000000000000000000000000000001',
)
```

## See

- [Contract](../type-aliases/Contract.md) for the full API of the returned Contract instance.
- [https://tevm.sh/learn/contracts/](https://tevm.sh/learn/contracts/) for more information on working with contracts in Tevm.
- [https://tevm.sh/reference/tevm/contract/types/Contract/](https://tevm.sh/reference/tevm/contract/types/Contract/) for detailed Contract type documentation.
- [https://contract.tevm.sh/guides/creating-contracts](https://contract.tevm.sh/guides/creating-contracts) for more information on working with contracts in Tevm.
- [https://contract.tevm.sh/api/contract](https://contract.tevm.sh/api/contract) for detailed Contract type documentation.
28 changes: 0 additions & 28 deletions docs/globals.md

This file was deleted.

Loading