buzzup-docs/wallet/eth_sendTransaction.mdx
2024-10-18 12:24:14 +08:00

41 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: eth_sendTransaction
description: 创建新的钱包确认以便从用户帐户进行以太坊交易。此方法要求用户首先授予与其帐户交互的权限因此请确保先调用eth_requestAccounts
---
---
### 参数
- from: 发送交易的地址。
- to: -(创建新合约时可选)将交易定向到的地址。
- value: 表示与此交易一起发送的值的整数。
- data: 合约的编译代码或调用的方法签名和编码参数的哈希。
- gas: (可选) 表示为交易执行提供的燃料的整数。 它将返回未使用的燃料。
---
### 返回值
- 已发送交易的交易哈希。
- TransactionHash 字符串
- 32 hex encoded bytes
---
### Request
```js
const eth_sendTransaction = () => {
try {
const hash = await window.ethereum.request({
"method": "eth_sendTransaction",
"params": [{
to: "0x4B0897b0513FdBeEc7C469D9aF4fA6C0752aBea7",
from: "0xDeaDbeefdEAdbeefdEadbEEFdeadbeefDEADbEEF",
gas: "0x76c0",
value: "0x8ac7230489e80000",
data: "0x",
gasPrice: "0x4a817c800"
}],
});
} catch (error) {
console.log('发送交易失败:',error);
}
}
```