**@tevm/contract** ∙ [README](../README.md) ∙ [API](../API.md)

***

[API](../API.md) > Script

# Type alias: Script`<TName, THumanReadableAbi>`

> **Script**\<`TName`, `THumanReadableAbi`\>: `object`

An action creator for `Tevm.script`, `Tevm.contract` and more
representing a solidity contract bytecode and ABI.
Scripts are akin to Foundry scripts you can run in the Tevm vm.

Script is also is the type solidity contract imports are turned into.

Scripts and contracts generate actions that can be dispatched to tevm methods
such as `contract` and `script`

## Example

```typescript
tevm.script(
-  { deployedBytecode: '0x60242....', abi: [...], args: ['0x1234...'], functionName: 'balanceOf' },
+  MyScript.withAddress('0x420...').read.balanceOf('0x1234...'),
)
```

A script can be made via the `createScript` function

## Example

```typescript
import { type Contract, createScript} from 'tevm/contract'

const contract: Contract = createScript({
  name: 'MyScript',
 	abi: [
 		...
 	],
})
```
These scripts can be automatically generated by using [@tevm/bundler](https://todo.todo)
and then importing it. The Tevm bundler will automatically resolve your solidity imports into
tevm contract instances

## Example

```typescript
import { MyScript } from './MyScript.sol'

console.log(MyScript.humanReadableAbi)
```
Address can be added to a contract using the `withAddress` method

## Example

```typescript
import { MyScript } from './MyScript.sol'

const MyScript = MyScript.withAddress('0x420...')
```
Scripts can also be used with other libraries such as Viem and ethers.

## Example

```typescript
import { MyScript } from './MyScript.sol'
import { createPublicClient } from 'viem'

// see viem docs
const client = createPublicClient({...})

const result = await client.readContract(
  MyScript.withAddress('0x420...').read.balanceOf('0x1234...'),
)

## Type parameters

| Parameter |
| :------ |
| `TName` extends `string` |
| `THumanReadableAbi` extends `ReadonlyArray`\<`string`\> |

## Type declaration

### abi

> **abi**: `ParseAbi`\<`THumanReadableAbi`\>

The json abi of the contract

#### Example

```typescript
import { MyScript } from './MyScript.sol'
console.log(MyScript.abi) // [{name: 'balanceOf', inputs: [...], outputs: [...], ...}]
```

### bytecode

> **bytecode**: `Hex`

The contract bytecode. This can be used for deploying the contract
bytecode is different from deployedBytecode in that the bytecode
includes the code to deploy the contract whereas the deployed
bytecode is the code that is deployed

### deployedBytecode

> **deployedBytecode**: `Hex`

The deployed contract bytecode. TThis can be used with the `script` tevm method
to execute arbitrary solidity code that isn't necessarily deployed to the chain
deployedBytecode is different from bytecode in that the bytecode includes the code
to deploy the contract whereas the deployed bytecode is the code that is deployed

### events

> **events**: [`EventActionCreator`](EventActionCreator.md)\<`THumanReadableAbi`, `Hex`, `Hex`, `undefined`\>

Action creators for events. Can be used to create event filters in a typesafe way

#### Example

```typescript
tevm.eth.getLog(
  MyScript.withAddress('0x420...').events.Transfer({ from: '0x1234...' }),
)
===

### humanReadableAbi

> **humanReadableAbi**: `THumanReadableAbi`

The human readable abi of the contract

#### Example

```typescript
import { MyScript } from './MyScript.sol'
console.log(MyScript.humanReadableAbi)
// ['function balanceOf(address): uint256', ...]
```

### name

> **name**: `TName`

The name of the contract. If imported this will match the name of the contract import

### read

> **read**: [`ReadActionCreator`](ReadActionCreator.md)\<`THumanReadableAbi`, `Hex`, `Hex`, `undefined`\>

Action creators for contract view and pure functions

#### Example

```typescript
tevm.contract(
  MyScript.withAddress('0x420...').read.balanceOf('0x1234...'),
)
```

### withAddress

> **withAddress**: \<`TAddress`\>(`address`) => `Omit`\<[`Script`](Script.md)\<`TName`, `THumanReadableAbi`\>, `"events"` \| `"read"` \| `"write"` \| `"address"`\> & `object`

Adds an address to the contract. All action creators will return
the address property if added.

#### Example

```typescript
import { MyScript } from './MyScript.sol'
const MyScript = MyScript.withAddress('0x420...')
```
Note this is not necessary with `tevm.script` method that doesn't require
a contract address to execute

Adds an address to the contract. All action creators will return
the address property if added.

#### Type parameters

▪ **TAddress** extends `Address`

#### Parameters

▪ **address**: `TAddress`

#### Returns

#### Example

```typescript
import { MyScript } from './MyScript.sol'
const MyScript = MyScript.withAddress('0x420...')
```
Note this is not necessary with `tevm.script` method that doesn't require
a contract address to execute

### write

> **write**: [`WriteActionCreator`](WriteActionCreator.md)\<`THumanReadableAbi`, `Hex`, `Hex`, `undefined`\>

Action creators for contract payable and nonpayable functions

#### Example

```typescript
tevm.contract(
  MyScript.withAddress('0x420...').read.balanceOf('0x1234...'),
)
```

## Source

[packages/contract/src/Script.ts:65](https://github.com/evmts/tevm-monorepo/blob/main/packages/contract/src/Script.ts#L65)

***
Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/)
