ethrpc

package module
v1.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

README

以太坊JsonRpc协议

文档参考

##代币价格

Unit Wei Value Wei
wei 1 1
Kwei (babbage) 1e3 wei 1,000
Mwei (lovelace) 1e6 wei 1,000,000
Gwei (shannon) 1e9 wei 1,000,000,000
microether (szabo) 1e12 wei 1,000,000,000,000
milliether (finney) 1e15 wei 1,000,000,000,000,000
ether 1e18 wei 1,000,000,000,000,000,000

##Gas-燃料

  • Gas limit:燃料限制,是用户愿意为执行某个操作或确认交易支付的最大Gas量(最少21,000)、
  • Gas Price:燃料价格,用户愿意花费于每个 Gas 单位的价钱。

##参考

Documentation

Index

Constants

View Source
const (
	BlockTag_Earliest = "earliest" //创世纪块
	BlockTag_Latest   = "latest"   //最新块
	BlockTag_Pending  = "pending"  //待定
)

* QUANTITY|TAG The following options are possible for the defaultBlock parameter:

HEX String - an integer block number String "earliest" for the earliest/genesis block String "latest" - for the latest mined block String "pending" - for the pending state/transactions

View Source
const (
	ContractInfoCode_Name         = "0x06fdde03" //获取合约名称
	ContractInfoCode_Abbreviation = "0x95d89b41" //合约简称
	ContractInfoCode_Balance      = "0x70a08231" //查询余额
	ContractInfoCode_Accuracy     = "0x313ce567" //合约精度
	ContractInfoCode_Total        = "0x18160ddd" //发行总量
)
View Source
const (
	TTtransferCode     = "0xa9059cbb" //转账签名编码
	TTbalanceOfCode    = "0x70a08231" //余额查询编码
	TTDecimalsCode     = "0x313ce567" //位數
	TTallowanceCode    = "0xdd62ed3e" //合约拥有者
	TTsymbolCode       = "0x95d89b41" //合约简称
	TTtotalSupplyCode  = "0x18160ddd" //发行总量
	TTnameCode         = "0x06fdde03" //合约名称
	TTapproveCode      = "0x095ea7b3" //认证
	TTtransferFromCode = "0x23b872dd" //交易
)
View Source
const Fromadd = "0x7f5CeDBb4CAC1e31dE6Aa8F02b6Bf882a04Fca35" //转账地址
View Source
const GASADDRES = "0x7260c1661793170694344bc813be6857ed16e58c" //手续费地址
View Source
const PWD = "luce!1989@9922sdf" //密钥
View Source
const TADDR = "0x59f8b414805E0Bb0246A0b0CaF72a889cfb92a16" //归集地址三

const TAddress = "0xa376Bd485433699D3D2c1A5322931879503330da"// 归集地址 const TADDR = "0x031CdC6C680Dd7889605f1d9EAE15D22797d0b3E" //归集地址二

View Source
const (
	V2 = "2.0"
)

Variables

This section is empty.

Functions

func AddPrefixZero added in v1.1.4

func AddPrefixZero(str string) string

补齐64位,不够前面用0补齐

func BigToHex

func BigToHex(bigInt big.Int) string

BigToHex covert big.Int to hexadecimal representation 到十六进制 长整型到十六进制表示

func CheckETHAddr added in v1.1.6

func CheckETHAddr(addr string) bool

验证地址是否是ETH地址

func Eth1

func Eth1() *big.Int

Eth1 returns 1 ethrpc value (10^18 wei)

func IntToHex

func IntToHex(i int) string

将int转换为十六进制表示

func ParseBigInt

func ParseBigInt(value string) (big.Int, error)

将十六进制字符串值解析为big.Int

func ParseInt

func ParseInt(value string) (int, error)

将十六进制字符串值解析为int

func TrimPrefixZero added in v1.1.4

func TrimPrefixZero(str string) string

去除前缀0

func USDTCollect added in v1.1.0

func USDTCollect()

USDT 归集

Types

type Block

type Block struct {
	Number           int           //QUANTITY - 块编号,挂起块为null
	Hash             string        // DATA, 32 Bytes-块哈希,挂起块为null
	ParentHash       string        //  DATA, 32 Bytes-父哈希
	Nonce            string        //DATA, 8 Bytes - 生成的pow哈希,挂起块为null(随机值)
	Sha3Uncles       string        //DATA, 32 Bytes - 块中叔伯数据的SHA3哈希
	LogsBloom        string        //DATA, 256 Bytes-快日志的bloom过滤器,挂起块为null
	TransactionsRoot string        //DATA, 32 Bytes - 块中的交易树根节点
	StateRoot        string        //DATA, 32 Bytes - 块最终状态树的根节点
	ReceiptsRoot     string        //DATA, 32 Bytes - 块交易收据树的根节点
	Miner            string        //DATA, 20 Bytes - 挖矿奖励的接收账户
	Difficulty       big.Int       // QUANTITY - 块难度,整数
	TotalDifficulty  big.Int       //QUANTITY - 截止到本块的链上总难度
	ExtraData        string        // DATA - 块额外数据
	Size             int           //QUANTITY - 本块字节数
	GasLimit         int           //QUANTITY -本块允许的最大gas用量
	GasUsed          int           //QUANTITY -本块中所有交易使用的总gas用量
	Timestamp        int           //QUANTITY - 块时间戳
	Uncles           []string      //Array - 叔伯哈希数组
	Transactions     []Transaction //Array - 交易对象数组,或32字节长的交易哈希数组
}

Block - block object "number": "0x1b4", // 436 "hash": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5", "nonce": "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2", "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff", "miner": "0x4e65fda2159562a496f9f3522f89122a3088497a", "difficulty": "0x027f07", // 163591 "totalDifficulty": "0x027f07", // 163591 "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "size": "0x027f07", // 163591 "gasLimit": "0x9f759", // 653145 "gasUsed": "0x9f759", // 653145 "timestamp": "0x54e34e8e" // 1424182926 "transactions": [{...},{ ... }] "uncles": ["0x1606e5...", "0xd5145a9..."] 区块链对象

type BlockHeader

type BlockHeader struct {
	Hash          string `json:"hash"`              //区块头
	Confirmations uint64 `json:"confirmations"`     //确认数量
	MerkleRoot    string `json:"merkleroot"`        //Merkler 根
	PrevBlockHash string `json:"previousblockhash"` //上一个区块hash
	Height        uint64 `json:"height" storm:"id"` //区块高度
	Version       uint64 `json:"version"`           //版本
	Time          uint64 `json:"time"`              // 时间
	Fork          bool   `json:"fork"`              // 分叉
	Symbol        string `json:"symbol"`            //币种简称
}

BlockHeader 区块头

type EthError

type EthError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

EthError- ethrpc error 错误

func (EthError) Error

func (err EthError) Error() string

错误信息

type EthRPC

type EthRPC struct {
	Debug   bool   //调试
	Version string //版本
	// contains filtered or unexported fields
}

EthRPC - Ethereum rpc client 以太坊RPC客户端结构体

func NewEthRPC

func NewEthRPC(url string, options ...func(rpc *EthRPC)) *EthRPC

NewEthRPC create new rpc client with given url

func (*EthRPC) Call

func (rpc *EthRPC) Call(method string, params ...interface{}) (json.RawMessage, error)

Call returns raw response of method call

func (*EthRPC) ContractInfo added in v1.1.3

func (rpc *EthRPC) ContractInfo(from string, token string, code string) (interface{}, error)

获取合約信息

func (*EthRPC) ContractTraction added in v1.1.5

func (rpc *EthRPC) ContractTraction(from, to, token string, decimal int64, value float64) (string, error)

合约地址转帐 return 交易hash

func (*EthRPC) Eth1

func (rpc *EthRPC) Eth1() *big.Int

Eth1 returns 1 ethrpc value (10^18 wei) 返回 1个ETH的值

func (*EthRPC) EthAccounts

func (rpc *EthRPC) EthAccounts() ([]string, error)

* EthAccounts returns a list of addresses owned by client. 返回客户端拥有的地址列表。 参数: none 返回: Array of DATA, 20 Bytes - 该地址拥有的地址列表

func (*EthRPC) EthBlockNumber

func (rpc *EthRPC) EthBlockNumber() (int, error)

* EthBlockNumber returns the number of most recent block. 返回最近块的数量。 参数: none 返回: QUANTITY - 客户端所在当前块号的整数。

func (*EthRPC) EthCall

func (rpc *EthRPC) EthCall(transaction T, tag string) (string, error)

* EthCall executes a new message call immediately without creating a transaction on the block chain. 立即执行新的消息调用,而不在区块链上创建交易。

参数:

Object -交易调用的对象
from: DATA, 20 Bytes - (可选) 交易发送的地址。
to: DATA, 20 Bytes - 交易所针对的地址。
gas: QUANTITY - (可选) 交易执行提供的gas。 eth_call消耗0gas,但某些执行可能需要此参数。
gasPrice: QUANTITY - (可选) 为每个gas支付多少个gasPrice.
value: QUANTITY - (可选) 此交易发送的value(整型)
data: DATA - (可选) 合约的编译代码
QUANTITY|TAG - 区块号, 或"latest", "earliest", "pending"

返回:

DATA -已执行合约的返回价值.

func (*EthRPC) EthCoinbase

func (rpc *EthRPC) EthCoinbase() (string, error)

* EthCoinbase returns the client coinbase address 返回客户端的coinbase地址 参数: none 返回: DATA, 20 bytes - 当前coinbase的地址.

func (*EthRPC) EthEstimateGas

func (rpc *EthRPC) EthEstimateGas(transaction T) (int, error)

* EthEstimateGas makes a call or transaction, which won't be added to the blockchain and returns the used gas, which can be used for estimating the used gas. 估算call或交易要使用的gas(这些call或交易不会添加到区块链中)。 参数

所有eth_call的参数

返回

QUANTITY - 使用gas的总金额。

func (*EthRPC) EthGasPrice

func (rpc *EthRPC) EthGasPrice() (big.Int, error)

* EthGasPrice returns the current price per gas in wei. 每个gas的当前价格,单位wei。 参数: none 返回: QUANTITY - 当前gas的价格整数。

func (*EthRPC) EthGetBalance

func (rpc *EthRPC) EthGetBalance(address, block string) (big.Int, error)

*

	EthGetBalance returns the balance of the account of given address in wei.
	返回给定地址中的账户余额单位是wei。
	参数
	DATA, 20 Bytes - 通过地址来检索余额。

	QUANTITY|TAG - 区块号, 或使用 "latest", "earliest","pending"

	params: [
   '0x407d73d8a49eeb85d32cf465507dd71d507100c1',
   'latest']
	返回
	QUANTITY - 当前余额的整数,以wei(Ether = 10e18Wei)为单位。

func (*EthRPC) EthGetBlockByHash

func (rpc *EthRPC) EthGetBlockByHash(hash string, withTransactions bool) (*Block, error)

*

	 EthGetBlockByHash returns information about a block by hash.
	 通过hash,返回一个区块的信息。
	参数
		DATA, 32 Bytes - 区块hash。
		Boolean - 如果为true,则返回完整的交易对象,如果为false,则仅返回交易的散列。
		params: [
   			'0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
   			true
		]
	参考:http://cw.hubwiz.com/card/c/ethereum-json-rpc-api/1/3/21/

func (*EthRPC) EthGetBlockByNumber

func (rpc *EthRPC) EthGetBlockByNumber(number int, withTransactions bool) (*Block, error)

*

	EthGetBlockByNumber returns information about a block by block number.
	通过区块号返回有关块的信息。
	参数
	QUANTITY|TAG - 区块号, 或"earliest", "latest", "pending"
	Boolean - 如果为true,则返回完整的交易对象,如果为false,则仅返回事务的散列。
	params: [
  		 '0x1b4', // 436
 		  true
	]
	返回
	跟上面的eth_getBlockByHash一样

func (*EthRPC) EthGetBlockTransactionCountByHash

func (rpc *EthRPC) EthGetBlockTransactionCountByHash(hash string) (int, error)

* EthGetBlockTransactionCountByHash returns the number of transactions in a block from a block matching the given block hash. 从匹配给定块哈希的块中返回一个块中的事务数。 通过区块hash匹配区块中的交易数。 参数 DATA, 32 Bytes - 区块的hash params: [ '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238' ] 返回 QUANTITY - 在该区块的交易数

func (*EthRPC) EthGetBlockTransactionCountByNumber

func (rpc *EthRPC) EthGetBlockTransactionCountByNumber(number int) (int, error)

*

	EthGetBlockTransactionCountByNumber returns the number of transactions in a block from a block matching the given block
	通过区块号进行匹配,返回交易数。

	参数
	QUANTITY|TAG - 区块号, 或 "earliest", "latest" or "pending"

	params: [
   		'0xe8', // 232
	]
	返回
	QUANTITY - 在该区块中的交易数量。

func (*EthRPC) EthGetCode

func (rpc *EthRPC) EthGetCode(address, block string) (string, error)

*

	EthGetCode returns code at a given address.
	返回指定地址的code。
	参数
	DATA, 20 Bytes - 地址
	QUANTITY|TAG - 区块号, 或"latest", "earliest", "pending"
	params: [
   		'0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b',
   		'0x2'  // 2
	]
	返回
	DATA - 指定地址的code。

func (*EthRPC) EthGetCompileLLL

func (rpc *EthRPC) EthGetCompileLLL(codes string) (string, error)

*

	返回编译后的LLL代码。
	参数
		String - 源码
		params: [
  				 "(returnlll (suicide (caller)))",
		]
	返回:
		DATA - 已编译的代码.

func (*EthRPC) EthGetCompileSerpent

func (rpc *EthRPC) EthGetCompileSerpent(codes string) (string, error)

*

	返回编译后的LLL代码。
	参数
		String - 源码
		params: [
  				  " some serpent ",
		]
	返回:
		DATA - 已编译的代码.

func (*EthRPC) EthGetCompileSolidity

func (rpc *EthRPC) EthGetCompileSolidity(codes string) (string, error)

*

	返回编译后的solidity代码。
	参数
		String - 源码
		params: [
  			 "contract test { function multiply(uint a) returns(uint d) {   return a * 7;   } }",
		]
	返回:
		DATA - 编译后的代码。

func (*EthRPC) EthGetCompilers

func (rpc *EthRPC) EthGetCompilers() ([]string, error)

* EthGetCompilers returns a list of available compilers in the client. 返回客户端中可用编译器的列表。 参数

none

返回 Array - 可以编译的数组列表。

func (*EthRPC) EthGetFilterChanges

func (rpc *EthRPC) EthGetFilterChanges(filterID string) ([]Log, error)

* EthGetFilterChanges polling method for a filter, which returns an array of logs which occurred since last poll. 过滤器的poll方法,该方法返回自上次poll以来发生的日志数组。 参数

QUANTITY - 过滤id。
	params: [
	  "0x16" // 22
	]

返回

Array - 日志对象数组,或者如果自上次poll以来没有任何更改,则为空数组。
	对于用eth_newBlockFilter创建的过滤器,返回是块hahs(DATA,32字节),例如,[“0x3454645634534......”]。
	对于使用eth_newPendingTransactionFilter创建的过滤器,返回是事务hash(DATA,32字节),例如,[“0x6345343454645......”。
	对于使用eth_newFilter创建的过滤器,日志是具有以下参数:
	type: TAG - 等待日志处于待处理状态。如果日志已被开采,则开采。
	logIndex: QUANTITY - 块中日志索引位置。当状态为pending的日志时为null。
	transactionIndex: QUANTITY - 日志从交易index位置创建的整数。当其panding的日志时为null。
	transactionHash: DATA, 32 Bytes - 这个日志创建的交易的hash。 当其处于pending的日志时为null。
	blockHash: DATA, 32 Bytes - 该日志所在块的散列,当其处于pending,则为空。当其pending日志时也为null。
	blockNumber: QUANTITY - 此日志中的区块号,当它处于pending,则为null,当其日志处于pending,也为null。
	address: DATA, 20 Bytes - 该日志源的地址。
	data: DATA - 包含日志的一个或多个32字节未index的参数。
	topics: DATA的数组 - 索引日志参数的0到4 32字节数组数据。(在solidity中:第一个topic是事件签名的hash(例如Deposit(address,bytes32,uint256)),除非你使用匿名说明符声明该事件。)

func (*EthRPC) EthGetFilterLogs

func (rpc *EthRPC) EthGetFilterLogs(filterID string) ([]Log, error)

*

	EthGetFilterLogs returns an array of all logs matching filter with given id.
	指定id,返回匹配的所有日志数组。
	参数
		QUANTITY - 过滤器id。
		params: [
  			"0x16" // 22
		]
	返回
		参考 eth_getFilterChanges 返回

func (*EthRPC) EthGetLogs

func (rpc *EthRPC) EthGetLogs(params FilterParams) ([]Log, error)

*

	EthGetLogs returns an array of all logs matching a given filter object.
	通过过滤器对象,返回匹配的所有日志数组。
	参数
		Object - 过滤器对象, 参照 eth_newFilter参数.
		params: [{
  			"topics": ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]
		}]
	返回
		参考 eth_getFilterChanges 返回

func (*EthRPC) EthGetStorageAt

func (rpc *EthRPC) EthGetStorageAt(data string, position int, tag string) (string, error)

*

	EthGetStorageAt returns the value from a storage position at a given address.
	返回指定地址的存储位置的值。
	参数
	DATA, 20 Bytes - 存储地址.
	QUANTITY - 存储位置的整数.
	QUANTITY|TAG - 区块号, 或 "latest", "earliest", "pending"

	params: [
 	  '0x407d73d8a49eeb85d32cf465507dd71d507100c1',
      '0x0', // storage position at 0
  	  '0x2' // state at block number 2]
	返回
	DATA - 在这个存储位置的值。

func (*EthRPC) EthGetTransactionByBlockHashAndIndex

func (rpc *EthRPC) EthGetTransactionByBlockHashAndIndex(blockHash string, transactionIndex int) (*Transaction, error)

* EthGetTransactionByBlockHashAndIndex returns information about a transaction by block hash and transaction index position. 通过区块hash和交易index位置,获取交易信息。 参数

DATA, 32 Bytes - 区块的hash。
QUANTITY - 交易index位置(整型)

返回

跟eth_getBlockByHash一样。

参考:http://cw.hubwiz.com/card/c/ethereum-json-rpc-api/1/3/24/

func (*EthRPC) EthGetTransactionByBlockNumberAndIndex

func (rpc *EthRPC) EthGetTransactionByBlockNumberAndIndex(blockNumber, transactionIndex int) (*Transaction, error)

*

	EthGetTransactionByBlockNumberAndIndex returns information about a transaction by block number and transaction index position.
	通过区块号和交易index位置,获取交易信息。
	参数
		QUANTITY|TAG - 区块号,或"earliest", "latest", "pending"
		QUANTITY - 交易的index位置。
		params: [
  		 '0x29c', // 668
  		 '0x0' // 0
		]
	返回
		跟eth_getBlockByHash一样。

func (*EthRPC) EthGetTransactionByHash

func (rpc *EthRPC) EthGetTransactionByHash(hash string) (*Transaction, error)

*

	EthGetTransactionByHash returns the information about a transaction requested by transaction hash.
	通过交易hash,返回交易信息。
	参数
		DATA, 32 Bytes - 交易hash
		params: [
  			 "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
		]
	参考:http://cw.hubwiz.com/card/c/ethereum-json-rpc-api/1/3/23/

func (*EthRPC) EthGetTransactionCount

func (rpc *EthRPC) EthGetTransactionCount(address, block string) (int, error)

* EthGetTransactionCount returns the number of transactions sent from an address. 返回指定地址发生的交易数量。 参数: DATA, 20 Bytes - 地址. QUANTITY|TAG - 区块号, 或"latest", "earliest" , "pending"

params: [

'0x407d73d8a49eeb85d32cf465507dd71d507100c1',
'latest' // state at the latest block]

返回 QUANTITY - 返回从该地址发送的交易数量。

func (*EthRPC) EthGetTransactionReceipt

func (rpc *EthRPC) EthGetTransactionReceipt(hash string) (*TransactionReceipt, error)

*

	EthGetTransactionReceipt returns the receipt of a transaction by transaction hash.
	Note That the receipt is not available for pending transactions.
	通过交易hash,接收交易结果。返回指定交易的收据,使用哈希指定交易。
    需要指出的是,挂起的交易其收据无效。
	注意,当交易处于pending时,接收不可用。
	参数
		DATA, 32 Bytes - 交易hash
		params: [
   			'0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'
		]

	返回:
		Object - 交易接收对象, 当接收没找到则为null:

			transactionHash: DATA, 32 Bytes - 交易的hash.
			transactionIndex: QUANTITY - 区块中交易index的位置。
			blockHash: DATA, 32 Bytes - 此交易所处的区块hash。
			blockNumber: QUANTITY - 此交易所处的区块号
			cumulativeGasUsed: QUANTITY - 当这笔交易已经在区块中执行完成,所使用的gas总量。
			gasUsed: QUANTITY - 此特定交易所使用的单个gas金额。
			contractAddress: DATA, 20 Bytes - 创建的合同地址(如果该交易是创建合约,* 否则为空。
			logs: Array - 此交易生成的日志对象数组。

func (*EthRPC) EthGetUncleCountByBlockHash

func (rpc *EthRPC) EthGetUncleCountByBlockHash(hash string) (int, error)

*

	EthGetUncleCountByBlockHash returns the number of uncles in a block from a block matching the given block hash.
	通过指定的区块hash,返回uncle数量。
	参数
	DATA, 32 Bytes - 区块hash
	params: [
   '0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238'
	]
	返回
	QUANTITY - 该区块的uncle数量

func (*EthRPC) EthGetUncleCountByBlockNumber

func (rpc *EthRPC) EthGetUncleCountByBlockNumber(number int) (int, error)

* EthGetUncleCountByBlockNumber returns the number of uncles in a block from a block matching the given block number. 通过指定的区块号,返回uncle数量。 参数 QUANTITY - 区块号, 或 "latest", "earliest", "pending" params: [ '0xe8', // 232 ] 返回 QUANTITY - integer of the number of uncles in this block.

func (*EthRPC) EthHashrate

func (rpc *EthRPC) EthHashrate() (int, error)

* EthHashrate returns the number of hashes per second that the node is mining with. 返回节点正在挖掘的每秒散列数。 参数: none 返回: QUANTITY - 每秒的哈希数。

func (*EthRPC) EthMining

func (rpc *EthRPC) EthMining() (bool, error)

* EthMining returns true if client is actively mining new blocks. 如果客户端正在主动挖掘新块,则返回true。 参数: none 返回: Boolean - 客户端主动的挖矿返回true,否则为false。

func (*EthRPC) EthNewBlockFilter

func (rpc *EthRPC) EthNewBlockFilter() (string, error)

* EthNewBlockFilter creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call EthGetFilterChanges. 在节点中创建一个过滤器,以通知新块到达。要检查状态是否已更改,请调用eth_getFilterChanges。 参数

None

返回

QUANTITY - 过滤器id.

func (*EthRPC) EthNewFilter

func (rpc *EthRPC) EthNewFilter(params FilterParams) (string, error)

*

	EthNewFilter creates a new filter object.
 	根据过滤器选项创建过滤器对象,以通知状态何时更改(日志)。要检查状态是否已更改,请调用eth_getFilterChanges。
	参数
		Object - 过滤器选项:
			fromBlock: QUANTITY|TAG - (optional, default: "latest") Integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions.
				(可选,默认值:“latest”)区块号,或最近一次挖掘块的“latest”或“pending”,“earliest”用于还未挖矿的交易。
			toBlock: QUANTITY|TAG - (optional, default: "latest") 区块号,或最近一次挖掘块的“latest”或“pending”,“earliest”用于还未挖矿的交易。
			address: DATA|Array, 20 Bytes -(可选)合约地址或日志应从其发出的地址列表。
			topics: DATA数组, - (可选) 32字节数据topic数组。
		params: [{
			"fromBlock": "0x1",
			"toBlock": "0x2",
			"address": "0x8888f1f195afa192cfee860698584c030f4c9db1",
			"topics": ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"]
		返回
			QUANTITY - 过滤id.
}]

func (*EthRPC) EthNewPendingTransactionFilter

func (rpc *EthRPC) EthNewPendingTransactionFilter() (string, error)

* EthNewPendingTransactionFilter creates a filter in the node, to notify when new pending transactions arrive. To check if the state has changed, call EthGetFilterChanges. 在节点中创建过滤器,以通知新的待处理交易到达。要检查状态是否已更改,请调用eth_getFilterChanges。 参数

None

返回

QUANTITY - 过滤器id.

func (*EthRPC) EthPerListAccounts

func (rpc *EthRPC) EthPerListAccounts() ([]string, error)

personal_listAccounts 个人账户列表

func (*EthRPC) EthPerNewAccount

func (rpc *EthRPC) EthPerNewAccount(password string) (address string, err error)

EthGetBalance returns the balance of the account of given address in wei. 返回创建的地址

func (*EthRPC) EthPerSendTransaction

func (rpc *EthRPC) EthPerSendTransaction(transaction T, password string) (string, error)

*

	sendTransaction方法验证指定的密码并提交交易,该方法的交易参数 与eth_sendTransaction一样,同时包含from账户地址。
    如果密码可以成功解密交易中from地址对应的私钥,那么该方法将验证交易、 签名并广播到以太坊网络中。
    由于在sendTransaction方法调用时,from账户并未在节点中全局解锁 (仅在该调用内解锁),因此from账户不能用于其他RPC调用

func (*EthRPC) EthPerUnLockAccount

func (rpc *EthRPC) EthPerUnLockAccount(address, password string) (bool, error)

personal.unlockAccount 个人解锁账户

func (*EthRPC) EthProtocolVersion

func (rpc *EthRPC) EthProtocolVersion() (string, error)

* EthProtocolVersion returns the current ethrpc protocol version. 返回当前以太坊协议的版本 参数: none 返回: String - The current ethrpc protocol version

func (*EthRPC) EthSendRawTransaction

func (rpc *EthRPC) EthSendRawTransaction(data string) (string, error)

*

	 EthSendRawTransaction creates new message call transaction or a contract creation for signed transactions.
	 为已签名的交易创建新的消息调用交易或合约创建。
	参数
		Object - 交易对象
		data: DATA, 已签名的交易数据。
		params: [{
  			"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
		}]
	返回:
		DATA, 32 Bytes - 交易hash,或0(如果交易还不可用)。

		当你创建的是一个合约时,使用eth_getTransactionReceipt来获取指定的合约地址。

func (*EthRPC) EthSendTransaction

func (rpc *EthRPC) EthSendTransaction(transaction T) (string, error)

*

	EthSendTransaction creates new message call transaction or a contract creation, if the data field contains code.
	如果数据字段包含code,则创建新的消息调用交易或创建合约。
	params
	Object - 交易对象
	from: DATA, 20 Bytes - 交易的发送地址。
	to: DATA, 20 Bytes -(创建新合约时可选)交易指向的地址。
	gas: QUANTITY -(可选,默认值:90000)为交易执行提供	的gas。它会返回未使用的gas。
	gasPrice: QUANTITY -(可选,默认:待确认)GasPrice就是你愿意为一个单位的Gas出多少Eth,一般用Gwei作单位。所以Gas Price 越高, 就表示交易中每运算一步,会支付更多的Eth。
	value: QUANTITY - (可选) 此交易发送的value。
	data: DATA - (可选) 合约的编译后的代码
	nonce: QUANTITY -(可选)一个整数。允许你使用相同的nonce覆盖自己处于等待中交易。

    example
	params: [{
  		"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
		"to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
  		"gas": "0x76c0", // 30400,
  		"gasPrice": "0x9184e72a000", // 10000000000000
  		"value": "0x9184e72a", // 2441406250
  		"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
		}]

	返回:
	DATA, 32 Bytes - 交易hash或0hash(如果交易尚不可用)。
	当创建合约的时候,使用eth_getTransactionReceipt获取合约地址。

func (*EthRPC) EthSign

func (rpc *EthRPC) EthSign(address, data string) (string, error)

* EthSign signs data with a given address. Calculates an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))) 用指定地址签名数据。 注意,签名地址必须解锁。 参数 DATA, 20 Bytes - 地址 DATA, 签名的数据 返回 DATA: 签名后的数据

func (*EthRPC) EthSyncing

func (rpc *EthRPC) EthSyncing() (*Syncing, error)

* EthSyncing returns an object with data about the sync status or false. 返回同步状态,或返回FALSE。 参数: none 返回: Object|Boolean, 同步状态数据或FALSE的对象在不同步时:

startingBlock: QUANTITY - 导入开始的块(只有在同步达到它的头之后才会被重置) currentBlock: QUANTITY - 当前块,与eth_blockNumber相同 highestBlock: QUANTITY - 估算的最高区块

func (*EthRPC) EthTxContent

func (rpc *EthRPC) EthTxContent() (content interface{}, err error)

tx pool content 交易池查询

func (*EthRPC) EthUninstallFilter

func (rpc *EthRPC) EthUninstallFilter(filterID string) (bool, error)

*

	EthUninstallFilter uninstalls a filter with given id.
	在不再需要监控时,应停止调用,卸载指定ID的过滤器。 另外,过滤一段时间未使用eth_getFilterChanges请求的超时。
	参数
		QUANTITY - The filter id.
		params: [
  			"0xb" // 11
		]
	返回
		Boolean - 如果过滤器已成功卸载,则为true,否则为false。

func (*EthRPC) ListAccount added in v1.1.3

func (rpc *EthRPC) ListAccount() []string

列出本地钱包

func (*EthRPC) NetListening

func (rpc *EthRPC) NetListening() (bool, error)

* NetListening returns true if client is actively listening for network connections. 如果客户端正在主动监听网络连接,则返回true。 参数: none 返回: Boolean - 当监听时为true,否则为false。

func (*EthRPC) NetPeerCount

func (rpc *EthRPC) NetPeerCount() (int, error)

* NetPeerCount returns number of peers currently connected to the client. 返回当前连接到客户端的对等的数量。 参数: none 返回: QUANTITY - 已连接对等的数量的整数。

func (*EthRPC) NetVersion

func (rpc *EthRPC) NetVersion() (string, error)

* NetVersion returns the current network protocol version. 返回当前网络协议的版本。 参数: none 返回: String - 当前网络协议版本

func (*EthRPC) RawCall

func (rpc *EthRPC) RawCall(method string, params ...interface{}) (json.RawMessage, error)

RawCall returns raw response of method call (Deprecated) (弃用)

func (*EthRPC) SendTransaction

func (rpc *EthRPC) SendTransaction(transaction Transaction) (string, error)

func (*EthRPC) TokeBalance added in v1.1.3

func (rpc *EthRPC) TokeBalance(address string, token string) float64

获取合约余额

func (*EthRPC) Traction added in v1.1.3

func (rpc *EthRPC) Traction(toaddress string, value float64) (string, error)

Token 转帐

func (*EthRPC) URL

func (rpc *EthRPC) URL() string

URL returns client url

func (*EthRPC) Web3ClientVersion

func (rpc *EthRPC) Web3ClientVersion() (string, error)

* Web3ClientVersion returns the current client version. 返回当前客户端版本号 参数: none 返回: String - 当前客户端版本号

func (*EthRPC) Web3Sha3

func (rpc *EthRPC) Web3Sha3(data []byte) (string, error)

*

	Web3Sha3 returns Keccak-256 (not the standardized SHA3-256) of the given data.
	返回指定数据的Keccak-256(不是标准化的SHA3-256)哈希值。
	参数:
	String - 将数据转化为SHA3哈希
	params: [
	  '0x68656c6c6f20776f726c64'
    ]
	返回:
	DATA - 返回SHA3

type EthereumAPI added in v1.1.0

type EthereumAPI interface {
	Web3ClientVersion() (string, error)
	Web3Sha3(data []byte) (string, error)
	NetVersion() (string, error)
	NetListening() (bool, error)
	NetPeerCount() (int, error)
	EthProtocolVersion() (string, error)
	EthSyncing() (*Syncing, error)
	EthCoinbase() (string, error)
	EthMining() (bool, error)
	EthHashrate() (int, error)
	EthGasPrice() (big.Int, error)
	EthAccounts() ([]string, error)
	EthBlockNumber() (int, error)
	EthGetBalance(address, block string) (big.Int, error)
	EthGetStorageAt(data string, position int, tag string) (string, error)
	EthGetTransactionCount(address, block string) (int, error)
	EthGetBlockTransactionCountByHash(hash string) (int, error)
	EthGetBlockTransactionCountByNumber(number int) (int, error)
	EthGetUncleCountByBlockHash(hash string) (int, error)
	EthGetUncleCountByBlockNumber(number int) (int, error)
	EthGetCode(address, block string) (string, error)
	EthSign(address, data string) (string, error)
	EthSendTransaction(transaction T) (string, error)
	EthSendRawTransaction(data string) (string, error)
	EthCall(transaction T, tag string) (string, error)
	EthEstimateGas(transaction T) (int, error)
	EthGetBlockByHash(hash string, withTransactions bool) (*Block, error)
	EthGetBlockByNumber(number int, withTransactions bool) (*Block, error)
	EthGetTransactionByHash(hash string) (*Transaction, error)
	EthGetTransactionByBlockHashAndIndex(blockHash string, transactionIndex int) (*Transaction, error)
	EthGetTransactionByBlockNumberAndIndex(blockNumber, transactionIndex int) (*Transaction, error)
	EthGetTransactionReceipt(hash string) (*TransactionReceipt, error)
	EthGetCompilers() ([]string, error)
	EthNewFilter(params FilterParams) (string, error)
	EthNewBlockFilter() (string, error)
	EthNewPendingTransactionFilter() (string, error)
	EthUninstallFilter(filterID string) (bool, error)
	EthGetFilterChanges(filterID string) ([]Log, error)
	EthGetFilterLogs(filterID string) ([]Log, error)
	EthGetLogs(params FilterParams) ([]Log, error)
}

ETHAPI接口

type FilterParams

type FilterParams struct {
	FromBlock string     `json:"fromBlock,omitempty"`
	ToBlock   string     `json:"toBlock,omitempty"`
	Address   []string   `json:"address,omitempty"`
	Topics    [][]string `json:"topics,omitempty"`
}

FilterParams - Filter parameters object 过滤器对象

type Log

type Log struct {
	Removed          bool
	LogIndex         int
	TransactionIndex int
	TransactionHash  string
	BlockNumber      int
	BlockHash        string
	Address          string
	Data             string
	Topics           []string
}

Log - log object 日志对象

func (*Log) UnmarshalJSON

func (log *Log) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type OptionFun

type OptionFun func(rpc *EthRPC)

func WithVersion

func WithVersion(version string) OptionFun

版本

type Request

type Request struct {
	ID      int           `json:"id"`
	JSONRPC string        `json:"jsonrpc"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params"`
}

请求

type Response

type Response struct {
	ID      int             `json:"id"`
	JSONRPC string          `json:"jsonrpc"`
	Result  json.RawMessage `json:"result"`
	Error   *EthError       `json:"error"`
}

响应

type Syncing

type Syncing struct {
	IsSyncing     bool //同步状态 false  表示同步完成
	StartingBlock int  //开始同步区块
	CurrentBlock  int  //当前区块高度
	HighestBlock  int  //区块高度
}

Syncing - object with syncing data info 区块同步信息结构体

func (*Syncing) UnmarshalJSON

func (s *Syncing) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. JSON数据实现

type T

type T struct {
	From     string   `json:"from"`
	To       string   `json:"to"`
	Gas      int      `json:"gas"`
	GasPrice *big.Int `json:"gas_price"`
	Value    *big.Int `json:"value"`
	Data     string   `json:"data"`
	Nonce    int      `json:"nonce"`
}

T - input transaction object 输入交易事务结构体

func (T) MarshalJSON

func (t T) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Unmarshaler interface. 实现了交易的 json数据接口。

type Transaction

type Transaction struct {
	Hash             string  //DATA, 32字节 - 交易哈希
	Nonce            int     //QUANTITY - 本次交易之前发送方已经生成的交易数量
	BlockHash        string  // DATA, 32字节 - 交易所在块的哈希,对于挂起块,该值为null
	BlockNumber      *int    // QUANTITY - 交易所在块的编号,对于挂起块,该值为null
	TransactionIndex *int    //QUANTITY - 交易在块中的索引位置,挂起块该值为null
	From             string  // DATA, 20字节 - 交易发送方地址
	To               string  // DATA, 20字节 - 交易接收方地址,对于合约创建交易,该值为null
	Value            big.Int // QUANTITY - 发送的以太数量,单位:wei
	Gas              int     // QUANTITY - 发送方提供的gas可用量
	GasPrice         big.Int //: QUANTITY - 发送方提供的gas价格,单位:wei
	Data             string  //
	Input            string  //DATA - 随交易发送的数据
}

Transaction - transaction object "hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b", "nonce":"0x", "blockHash": "0xbeab0aa2411b7ab17f30a99d3cb9c6ef2fc5426d6ad6fd9e2a26a6aed1d1055b", "blockNumber": "0x15df", // 5599 "transactionIndex": "0x1", // 1 "from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1", "to":"0x85h43d8a49eeb85d32cf465507dd71d507100c1", "value":"0x7f110", // 520464 "gas": "0x7f110", // 520464 "gasPrice":"0x09184e72a000", "input":"0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360", 交易结构体

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type TransactionReceipt

type TransactionReceipt struct {
	TransactionHash   string
	TransactionIndex  int
	BlockHash         string
	BlockNumber       int
	CumulativeGasUsed int
	GasUsed           int
	ContractAddress   string
	Logs              []Log
	LogsBloom         string
	Root              string
	Status            string
}

transactionHash: DATA, 32 Bytes - 交易的hash. transactionIndex: QUANTITY - 区块中交易index的位置。 blockHash: DATA, 32 Bytes - 此交易所处的区块hash。 blockNumber: QUANTITY - 此交易所处的区块号 cumulativeGasUsed: QUANTITY - 当这笔交易已经在区块中执行完成,所使用的gas总量。 gasUsed: QUANTITY - 此特定交易所使用的单个gas金额。 contractAddress: DATA, 20 Bytes - 创建的合同地址(如果该交易是创建合约,* 否则为空。 logs: Array - 此交易生成的日志对象数组。 交易收据 TransactionReceipt - transaction receipt object

func (*TransactionReceipt) UnmarshalJSON

func (t *TransactionReceipt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL