ethereum.sendAsync() - 异步发送交易
ethereum.sendAsync()
方法采用异步形式向web3浏览器发送消息。
消息格式与以太坊JSON-RPC API的格式向对应,RPC API的响应结果在回调函数
中获得。
示例代码
下面的示例展示了如何使用ethereum.send()
方法来发送以太币、调用智能合约:
params: [{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0", // 30400
"gasPrice": "0x9184e72a000", // 10000000000000
"value": "0x9184e72a", // 2441406250
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}]
ethereum.sendAsync({
method: 'eth_sendTransaction',
params: params,
from: accounts[0], // Provide the user's account to use.
}, function (err, result) {
// A typical node-style, error-first callback.
// The result varies by method, per the JSON RPC API.
// For example, this method will return a transaction hash on success.
})