ethereum.send() - 发送交易
ethereum.send()
是向web3浏览器发送消息的基本的推荐方法。
消息格式与以太坊JSON-RPC API的格式向对应。
ethereum.send()
方法返回一个Promise对象,其解析值为JSON-PRC
响应结果。
示例代码
下面的示例展示了如何使用ethereum.send()
方法来发送以太币、调用智能合约:
params: [{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0", // 30400
"gasPrice": "0x9184e72a000", // 10000000000000
"value": "0x9184e72a", // 2441406250
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}]
ethereum.send({
method: 'eth_sendTransaction',
params: params,
from: accounts[0], // Provide the user's account to use.
})
.then(function (result) {
// The result varies by method, per the JSON RPC API.
// For example, this method will return a transaction hash on success.
})
.catch(function (reason) {
// Like a typical promise, returns a reason on rejection.
})