# encode\_function\_calldata

通过传入函数名及参数进行编码,生成调用该函数的 CallData。

## 方法定义

```python
def encode_function_calldata(self, function_name: str, *args: Optional[Any]) -> Optional[HexStr]
```

## 参数说明

| 参数             | 类型             | 说明   |
| -------------- | -------------- | ---- |
| function\_name | str            | 函数名称 |
| \*args         | Optional\[Any] | 函数参数 |

## 返回值

| 类型                | 说明     |
| ----------------- | ------ |
| Optional\[HexStr] | 调用数据编码 |

## 示例代码

```python
# 编码函数调用数据
calldata = contract.encode_function_calldata(
    "transfer",     # 函数名
    "0x...",       # 接收者地址
    1000           # 转账金额
)
if calldata:
    print(f"Encoded CallData: {calldata}")

# 使用编码后的数据手动构造交易
if calldata:
    receipt = account.send_transaction(
        to=contract.address,
        data=HexBytes(calldata)
    )
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://poseidon.seaeye.cn/evm/contract/encode_function_calldata.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
