> For the complete documentation index, see [llms.txt](https://poseidon.seaeye.cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://poseidon.seaeye.cn/evm/contract/call_function.md).

# call\_function

通过传入函数名称及参数来调用该合约内的函数。

## 方法定义

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

## 参数说明

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

## 返回值

返回 TransactionReceiptData 对象,包含以下字段:

| 字段                  | 类型                           | 说明               |
| ------------------- | ---------------------------- | ---------------- |
| transaction\_hash   | HexBytes                     | 交易哈希             |
| block\_number       | BlockNumber                  | 区块高度             |
| transaction\_index  | int                          | 交易在区块中的索引        |
| transaction\_status | int                          | 交易状态(1 成功,0 失败)  |
| transaction\_type   | int                          | 交易类型             |
| action              | str                          | 交易动作类型           |
| sender              | ChecksumAddress              | 发送者地址            |
| to                  | ChecksumAddress              | 接收者地址            |
| nonce               | Nonce                        | 交易序号             |
| value               | Wei                          | 转账金额             |
| gas\_used           | int                          | 实际使用的 Gas        |
| gas\_limit          | int                          | Gas 上限           |
| gas\_price          | Optional\[Wei]               | Gas 价格           |
| contract\_address   | Optional\[ChecksumAddress]   | 部署的合约地址(仅合约创建交易) |
| logs                | Optional\[List\[LogReceipt]] | 交易日志             |
| input\_data         | HexBytes                     | 交易输入数据           |
| r                   | HexBytes                     | 签名 r 值           |
| s                   | HexBytes                     | 签名 s 值           |
| v                   | HexBytes                     | 签名 v 值           |

## 示例代码

```python
# 调用合约函数
receipt = contract.call_function(
    "transfer",  # 函数名
    "0x...",    # 接收者地址
    1000        # 转账金额
)

if receipt and receipt.transaction_status:
    print(f"Transaction successful: {receipt.transaction_hash.hex()}")
    print(f"Gas used: {receipt.gas_used}")
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://poseidon.seaeye.cn/evm/contract/call_function.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
