跳到主要内容

以太坊

personal_sign

sign方法计算以太坊特定的签名: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))) .

通过向消息添加前缀,计算出的签名可识别为以太坊特定的签名。这防止了恶意的DApp可以对任意数据签名的误用 (e.g. transaction) ,并使用签名冒充受害者。

笔记 请参见ecRecover验证签名。

参数

message, account

  1. DATA, N Bytes - message to sign.
  2. DATA, 20 Bytes - address.

返回值

DATA: Signature

示例

// Request
{
"id": 1,
"jsonrpc": "2.0",
"method": "personal_sign",
"params":["0xdeadbeaf","0x9b2055d370f73ec7d8a03e965129118dc8f5bf83"],
}

// Result
{
"id": 1,
"jsonrpc": "2.0",
"result": "0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"
}

eth_sign

sign方法计算以太坊特定的签名: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))).

通过向消息添加前缀,计算出的签名可识别为以太坊特定的签名。这防止了恶意的DApp可以对任意数据签名的误用。(e.g. transaction) ,并使用签名冒充受害者。

笔记 要签名的地址必须解锁。

参数

account, message

  1. DATA, 20 Bytes - address.
  2. DATA, N Bytes - message to sign.

返回值

DATA: Signature

示例

// Request
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_sign",
"params": ["0x9b2055d370f73ec7d8a03e965129118dc8f5bf83", "0xdeadbeaf"],
}


// Result
{
"id": 1,
"jsonrpc": "2.0",
"result": "0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"
}

举例说明如何使用solid ecrecover对计算的签名进行验证 eth_sign 看这里. 合同部署在测试网Ropsten和Rinkeby上。

eth_signTypedData

计算表单中特定于以太坊的签名 keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))

通过向消息添加前缀,计算出的签名可识别为以太坊特定的签名。这防止了恶意的DApp可以对任意数据签名的误用。(e.g. transaction) ,并使用签名冒充受害者。

笔记要签名的地址必须解锁。

参数

account, message

  1. DATA, 20 Bytes - address.
  2. DATA, N Bytes - 要签名的消息,其中包含类型信息、域分隔符和数据

示例 参数

[
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
{
types: {
EIP712Domain: [
{
name: "name",
type: "string",
},
{
name: "version",
type: "string",
},
{
name: "chainId",
type: "uint256",
},
{
name: "verifyingContract",
type: "address",
},
],
Person: [
{
name: "name",
type: "string",
},
{
name: "wallet",
type: "address",
},
],
Mail: [
{
name: "from",
type: "Person",
},
{
name: "to",
type: "Person",
},
{
name: "contents",
type: "string",
},
],
},
primaryType: "Mail",
domain: {
name: "Ether Mail",
version: "1",
chainId: 1,
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
},
message: {
from: {
name: "Cow",
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
},
to: {
name: "Bob",
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
},
contents: "Hello, Bob!",
},
},
];

返回值

DATA: Signature

示例

// Request
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_signTypedData",
"params": ["0x9b2055d370f73ec7d8a03e965129118dc8f5bf83", {see above}],
}
'

// Result
{
"id": 1,
"jsonrpc": "2.0",
"result": "0x4355c47d63924e8a72e509b65029052eb6c299d53a04e167c5775fd466751c9d07299936d304c153f6443dfa05f40ff007d72911b6f72307f996231605b915621c"
}

eth_sendTransaction

如果数据字段包含代码,则创建新的消息调用事务或合约创建。

参数

  1. Object - The transaction object
  2. from: DATA, 20 Bytes - 发送事务的地址。
  3. to: DATA, 20 Bytes - (可选 当创建新合约) 交易定向到的地址。
  4. data: DATA - 合约的编译代码或被调用方法签名和编码的散列参数.详情 Ethereum Contract ABI
  5. gas: QUANTITY - (可选, default: 90000) 为交易执行提供的gas:整型。它将返回未使用的gas。
  6. gasPrice: QUANTITY - (可选, 默认: 待定) gas价格的:整形,为每一个支付的gas价格
  7. value: QUANTITY - (可选) value:整型.
  8. nonce: QUANTITY - (可选) nonce:整型. This allows to overwrite your own pending transactions that use the same nonce.

示例 参数

[
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
data:
"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
gas: "0x76c0", // 30400
gasPrice: "0x9184e72a000", // 10000000000000
value: "0x9184e72a", // 2441406250
nonce: "0x117", // 279
},
];

返回值

DATA, 32 Bytes -事务哈希,如果交易还不可用,则为零哈希。

eth_getTransactionReceipt获取合约地址, 在交易被Miner之后。

示例

// Request
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_sendTransaction",
"params":[{see above}],
}

// Result
{
"id": 1,
"jsonrpc": "2.0",
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}

eth_signTransaction

签署可以在以后使用with提交到网络的交易 eth_sendRawTransaction

参数

  1. Object - The transaction object
  2. from: DATA, 20 Bytes - 发送事务的地址。
  3. to: DATA, 20 Bytes - (创建新合约时可选) 交易定向到的地址。
  4. data: DATA - 合约的编译代码或被调用方法签名和编码的散列参数. 详情 Ethereum Contract ABI
  5. gas: QUANTITY - (可选, 默认: 90000)为交易执行提供的gas:整数。它将返回未使用的gas。
  6. gasPrice: QUANTITY - (可选, 默认: 待定) gas价格:整数,为每一个支付的gas价格
  7. value: QUANTITY - (可选) 与此交易一起发送的值:整数
  8. nonce: QUANTITY - (可选) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.

示例 参数

[
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
data:
"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
gas: "0x76c0", // 30400
gasPrice: "0x9184e72a000", // 10000000000000
value: "0x9184e72a", // 2441406250
nonce: "0x117", // 279
},
];

返回值

DATA - 签名的事务数据

示例

// Request
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_signTransaction",
"params":[{see above}],
}

// Result
{
"id": 1,
"jsonrpc": "2.0",
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}

eth_sendRawTransaction

Creates new message call transaction or a contract creation for signed transactions.

参数

  1. DATA,签名的交易数据。

返回值

DATA, 32 Bytes -交易哈希,如果事务还不可用,则为零哈希。

当您创建合约时使用 eth_getTransactionReceipt获取合约地址, 在交易被Miner之后。

示例

// Request
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_sendRawTransaction",
"params":[
"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f07244567"
],
}

// Result
{
"id": 1,
"jsonrpc": "2.0",
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}
```