Documentation ¶
Index ¶
- Constants
- func BuildContractInputData(contract abi.ABI, name string, args ...interface{}) ([]byte, error)
- func BuildPrivateKeyFromHex(privateKeyHex string) (*ecdsa.PrivateKey, error)
- func BuildPrivateKeyFromMnemonic(mnemonic string, accountId uint32) (*ecdsa.PrivateKey, error)
- func DecodeRawTxHex(rawTx string) (*types.Transaction, error)
- func GeneratePrivateKey() (*ecdsa.PrivateKey, error)
- func GetABI(abiStr string) (abi.ABI, error)
- func GetContractMethodId(method string) string
- func GetEventTopic(event string) string
- func GetHexPrivateKey(privateKey *ecdsa.PrivateKey) string
- func GetHexPublicKey(privateKey *ecdsa.PrivateKey) string
- func GetMaxUint256() *big.Int
- func IsValidAddress(iAddress interface{}) bool
- func NewTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, ...) (*types.Transaction, error)
- func NewTxWithHexData(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, ...) (*types.Transaction, error)
- func PrivateKeyToAddress(privateKey *ecdsa.PrivateKey) common.Address
- func PublicKeyBytesToAddress(publicKey []byte) common.Address
- func ToDecimal(iValue interface{}, decimals int) decimal.Decimal
- func ToWei(iAmount interface{}, decimals int) *big.Int
- func VerifySignature(address string, data, signature []byte) bool
- type EtherProvider
- type EtherSigner
- type EtherWallet
- type Provider
- func (p *Provider) Close()
- func (p *Provider) EstimateGas(from, to common.Address, nonce uint64, gasPrice, value *big.Int, data []byte) (uint64, error)
- func (p *Provider) GetBlockByHash(blkHash common.Hash) (*types.Block, error)
- func (p *Provider) GetBlockByNumber(number *big.Int) (*types.Block, error)
- func (p *Provider) GetBlockNumber() (uint64, error)
- func (p *Provider) GetChainID() (*big.Int, error)
- func (p *Provider) GetContractBytecode(address common.Address) (string, error)
- func (p *Provider) GetEthClient() *ethclient.Client
- func (p *Provider) GetFromAddress(tx *types.Transaction) (common.Address, error)
- func (p *Provider) GetNetworkID() (*big.Int, error)
- func (p *Provider) GetRpcClient() *rpc.Client
- func (p *Provider) GetSuggestGasPrice() (*big.Int, error)
- func (p *Provider) GetTransactionByHash(txHash common.Hash) (tx *types.Transaction, isPending bool, err error)
- func (p *Provider) GetTransactionReceipt(txHash common.Hash) (*types.Receipt, error)
- func (p *Provider) IsContractAddress(address common.Address) (bool, error)
- type Signer
- func NewSigner() (*Signer, error)
- func NewSignerFromHexPrivateKey(hexPk string) (*Signer, error)
- func NewSignerFromMnemonic(mnemonic string) (*Signer, error)
- func NewSignerFromMnemonicAndAccountId(mnemonic string, accountId uint32) (*Signer, error)
- func NewSignerFromPrivateKey(pk *ecdsa.PrivateKey) (*Signer, error)
- func NewSignerFromRawPrivateKey(rawPk []byte) (*Signer, error)
- type Wallet
- func (w *Wallet) BuildTxOpts(value, nonce, gasPrice *big.Int) (*bind.TransactOpts, error)
- func (w *Wallet) CallContract(contractAddress common.Address, contractAbi abi.ABI, functionName string, ...) ([]interface{}, error)
- func (w *Wallet) CloseWallet()
- func (w *Wallet) GetAddress() common.Address
- func (w *Wallet) GetBalance() (*big.Int, error)
- func (w *Wallet) GetClient() *ethclient.Client
- func (w *Wallet) GetEthProvider() EtherProvider
- func (w *Wallet) GetEthSigner() EtherSigner
- func (w *Wallet) GetNonce() (uint64, error)
- func (w *Wallet) NewTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, ...) (*types.Transaction, error)
- func (w *Wallet) NewTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, ...) (*types.Transaction, error)
- func (w *Wallet) SendSignedTx(signedTx *types.Transaction) (common.Hash, error)
- func (w *Wallet) SendTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, ...) (common.Hash, error)
- func (w *Wallet) SendTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, ...) (common.Hash, error)
- func (w *Wallet) SignTx(tx *types.Transaction) (*types.Transaction, error)
- func (w *Wallet) Signature(data []byte) ([]byte, error)
Constants ¶
const ( ZeroAddress = "0x0000000000000000000000000000000000000000" EAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" )
const ZeroHash = "0x0000000000000000000000000000000000000000000000000000000000000000"
Variables ¶
This section is empty.
Functions ¶
func BuildContractInputData ¶
BuildContractInputData 构建合约的input data
func BuildPrivateKeyFromHex ¶
func BuildPrivateKeyFromHex(privateKeyHex string) (*ecdsa.PrivateKey, error)
BuildPrivateKeyFromHex 从字符串私钥构建私钥对象
func BuildPrivateKeyFromMnemonic ¶
func BuildPrivateKeyFromMnemonic(mnemonic string, accountId uint32) (*ecdsa.PrivateKey, error)
BuildPrivateKeyFromMnemonic 从助记词获得私钥
func DecodeRawTxHex ¶
func DecodeRawTxHex(rawTx string) (*types.Transaction, error)
DecodeRawTxHex 解析rawTx
func GeneratePrivateKey ¶
func GeneratePrivateKey() (*ecdsa.PrivateKey, error)
GeneratePrivateKey 创建私钥
func GetContractMethodId ¶
GetContractMethodId 获得合约的methodId 参数method,如:transfer(address,uint256)
func GetEventTopic ¶
GetEventTopic 获得事件的topic。event字符串如:transfer(address,uint256)
func GetHexPrivateKey ¶
func GetHexPrivateKey(privateKey *ecdsa.PrivateKey) string
GetHexPrivateKey 创建十六进制的私钥(不以0x开头)
func GetHexPublicKey ¶
func GetHexPublicKey(privateKey *ecdsa.PrivateKey) string
GetHexPublicKey 从私钥中获得十六进制的公钥(不以0x和04开头)
func NewTx ¶
func NewTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (*types.Transaction, error)
NewTx 新建一个tx
func NewTxWithHexData ¶
func NewTxWithHexData(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, hexData string) (*types.Transaction, error)
NewTxWithHexData 基于hexData构建一个Tx
func PrivateKeyToAddress ¶
func PrivateKeyToAddress(privateKey *ecdsa.PrivateKey) common.Address
PrivateKeyToAddress 从私钥中获得地址
func PublicKeyBytesToAddress ¶
PublicKeyBytesToAddress 公钥到地址
func VerifySignature ¶
VerifySignature 验证签名 address: 用于签名的地址 digestHash: 用于验证的原始数据 signature: 需要进行验证的签名数据
Types ¶
type EtherProvider ¶ added in v0.0.6
type EtherProvider interface { GetEthClient() *ethclient.Client GetRpcClient() *rpc.Client Close() GetNetworkID() (*big.Int, error) GetChainID() (*big.Int, error) GetBlockByHash(hash common.Hash) (*types.Block, error) GetBlockByNumber(number *big.Int) (*types.Block, error) GetBlockNumber() (uint64, error) GetSuggestGasPrice() (*big.Int, error) GetTransactionByHash(hash common.Hash) (tx *types.Transaction, isPending bool, err error) GetTransactionReceipt(txHash common.Hash) (*types.Receipt, error) GetContractBytecode(address common.Address) (string, error) IsContractAddress(address common.Address) (bool, error) EstimateGas(from, to common.Address, nonce uint64, gasPrice, value *big.Int, data []byte) (uint64, error) GetFromAddress(tx *types.Transaction) (common.Address, error) }
EtherProvider 需要通过链上查询的,但是不需要账户的
type EtherSigner ¶ added in v0.0.6
type EtherSigner interface { GetAddress() common.Address GetPrivateKey() *ecdsa.PrivateKey }
EtherSigner ETH账户
type EtherWallet ¶ added in v0.0.5
type EtherWallet interface { GetEthSigner() EtherSigner GetEthProvider() EtherProvider GetClient() *ethclient.Client GetAddress() common.Address CloseWallet() GetNonce() (uint64, error) GetBalance() (*big.Int, error) NewTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (*types.Transaction, error) SendTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (common.Hash, error) NewTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, input string) (*types.Transaction, error) SendTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, input string) (common.Hash, error) BuildTxOpts(value, nonce, gasPrice *big.Int) (*bind.TransactOpts, error) SignTx(tx *types.Transaction) (*types.Transaction, error) SendSignedTx(signedTx *types.Transaction) (common.Hash, error) Signature(data []byte) ([]byte, error) CallContract(contractAddress common.Address, contractAbi abi.ABI, functionName string, params ...interface{}) ([]interface{}, error) }
EtherWallet 钱包信息
type Provider ¶ added in v0.0.6
type Provider struct {
// contains filtered or unexported fields
}
func NewProvider ¶ added in v0.0.8
func NewProviderWithChainId ¶ added in v0.0.8
func (*Provider) Close ¶ added in v0.0.6
func (p *Provider) Close()
Close 关闭ethClient客户端和rpcClient客户端
func (*Provider) EstimateGas ¶ added in v0.0.6
func (p *Provider) EstimateGas(from, to common.Address, nonce uint64, gasPrice, value *big.Int, data []byte) (uint64, error)
EstimateGas 预估手续费
func (*Provider) GetBlockByHash ¶ added in v0.0.6
GetBlockByHash 根据区块Hash获得区块信息
func (*Provider) GetBlockByNumber ¶ added in v0.0.6
GetBlockByNumber 根据区块号获得区块信息
func (*Provider) GetBlockNumber ¶ added in v0.0.6
GetBlockNumber 获得最新区块
func (*Provider) GetChainID ¶ added in v0.0.6
GetChainID 获得ChainId
func (*Provider) GetContractBytecode ¶ added in v0.0.6
GetContractBytecode 根据合约地址获得bytecode
func (*Provider) GetEthClient ¶ added in v0.0.6
GetEthClient 获得ethClient客户端
func (*Provider) GetFromAddress ¶ added in v0.0.6
GetFromAddress 获得交易的fromAddress
func (*Provider) GetNetworkID ¶ added in v0.0.6
GetNetworkID 获得NetworkId
func (*Provider) GetRpcClient ¶ added in v0.0.6
GetRpcClient 获得rpcClient客户端
func (*Provider) GetSuggestGasPrice ¶ added in v0.0.6
GetSuggestGasPrice 获得建议的Gas
func (*Provider) GetTransactionByHash ¶ added in v0.0.6
func (p *Provider) GetTransactionByHash(txHash common.Hash) (tx *types.Transaction, isPending bool, err error)
GetTransactionByHash 根据txHash获得交易信息
func (*Provider) GetTransactionReceipt ¶ added in v0.0.6
GetTransactionReceipt 根据txHash获得交易Receipt
type Signer ¶ added in v0.0.6
type Signer struct {
// contains filtered or unexported fields
}
func NewSignerFromHexPrivateKey ¶ added in v0.0.8
NewSignerFromHexPrivateKey 使用私钥创建一个账号信息
func NewSignerFromMnemonic ¶ added in v0.0.8
NewSignerFromMnemonic 使用助记词创建一个账号信息
func NewSignerFromMnemonicAndAccountId ¶ added in v0.0.8
NewSignerFromMnemonicAndAccountId 使用助记词创建一个账号信息
func NewSignerFromPrivateKey ¶ added in v0.0.8
func NewSignerFromPrivateKey(pk *ecdsa.PrivateKey) (*Signer, error)
NewSignerFromPrivateKey 使用私钥创建一个账号信息
func NewSignerFromRawPrivateKey ¶ added in v0.0.8
NewSignerFromRawPrivateKey 使用私钥创建一个账号信息
func (*Signer) GetAddress ¶ added in v0.0.6
GetAddress 获得地址
func (*Signer) GetPrivateKey ¶ added in v0.0.6
func (s *Signer) GetPrivateKey() *ecdsa.PrivateKey
GetPrivateKey 获得私钥
type Wallet ¶ added in v0.0.6
type Wallet struct {
// contains filtered or unexported fields
}
func NewWallet1 ¶ added in v0.0.8
func NewWallet1(es EtherSigner, ep EtherProvider) (*Wallet, error)
NewWallet1 新建Wallet
func (*Wallet) BuildTxOpts ¶ added in v0.0.6
BuildTxOpts 构建交易的选项
func (*Wallet) CallContract ¶ added in v0.0.6
func (w *Wallet) CallContract(contractAddress common.Address, contractAbi abi.ABI, functionName string, params ...interface{}) ([]interface{}, error)
CallContract 调用合约的方法,无需创建交易
func (*Wallet) GetAddress ¶ added in v0.0.6
GetAddress 获得地址
func (*Wallet) GetBalance ¶ added in v0.0.6
GetBalance 获得本位币的约
func (*Wallet) GetEthProvider ¶ added in v0.0.6
func (w *Wallet) GetEthProvider() EtherProvider
GetEthProvider 获得EthProvider
func (*Wallet) GetEthSigner ¶ added in v0.0.6
func (w *Wallet) GetEthSigner() EtherSigner
GetEthSigner 获得EthSinger
func (*Wallet) NewTx ¶ added in v0.0.6
func (w *Wallet) NewTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (*types.Transaction, error)
NewTx 构建一笔交易。nonce传0表示字段计算;gasLimit传0表示字段计算;gasPrice穿nil或者big.NewInt(0)表示gasPrice自动计算。
func (*Wallet) NewTxWithHexInput ¶ added in v0.0.6
func (w *Wallet) NewTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, input string) (*types.Transaction, error)
NewTxWithHexInput 构建一笔交易,使用0x开头的input。nonce传0表示字段计算;gasLimit传0表示字段计算;gasPrice穿nil或者big.NewInt(0)表示gasPrice自动计算。
func (*Wallet) SendSignedTx ¶ added in v0.0.6
SendSignedTx 发送签名后的Tx
func (*Wallet) SendTx ¶ added in v0.0.6
func (w *Wallet) SendTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (common.Hash, error)
SendTx 发送交易。nonce传0表示字段计算;gasLimit传0表示字段计算;gasPrice穿nil或者big.NewInt(0)表示gasPrice自动计算。
func (*Wallet) SendTxWithHexInput ¶ added in v0.0.6
func (w *Wallet) SendTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, input string) (common.Hash, error)
SendTxWithHexInput 发送一笔交易,使用0x开头的input。nonce传0表示字段计算;gasLimit传0表示字段计算;gasPrice穿nil或者big.NewInt(0)表示gasPrice自动计算。
func (*Wallet) SignTx ¶ added in v0.0.6
func (w *Wallet) SignTx(tx *types.Transaction) (*types.Transaction, error)
SignTx 对交易进行签名