evm

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 8 Imported by: 0

README

EVM module

Usage

(Tx) Send coin
sendCoinMsg := types.SendCoinMsg{
    Amount: "10000",
    FromAddress: "0x6577385b5d959644ae31263208a88E921273C774",
    ToAddress: "0xF9AC4736D8034F2CB3BFF22A977CD8759934F090",
}

txbytes, err := xplac.EvmSendCoin(sendCoinMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Deploy solidity contract
// Select input type of ABI and bytecode.
// It is also possible to input the entire abi and bytecode as a string type, but you can also enter a file path.
// ABI type must be json and bytecode file must be compiled file on Remix IDE.

// Constructor input arguments
var args []interface{}
owner := []common.Address{
    common.HexToAddress("0xC9F0A2b814d389088a508E31fBa483E8C4372CC2"),
    common.HexToAddress("0x41776240700C033A75A2872EF0AD32b4911e13B1"),
    common.HexToAddress("0xaaC4758A943B2692F2daE0DE8d402aD7045A8DfB"),
}
required := big.NewInt(2)

args = append(args, owner)
args = append(args, required)

deploySolContractMsg := types.DeploySolContractMsg{
    //ABI: `{ ABI json string type }`
    ABIJsonFilePath: "./abi.json",
    // Bytecode: "60806040523480156100......",
    BytecodeJsonFilePath: "./bytecode.json",
    Args: args,
}

txbytes, err := xplac.DeploySolidityContract(deploySolContractMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Invoke(execute) solidity contract
// When invoked, the arguments to be entered into the solidity contract are listed as []interface{}.
var args []interface{}
args = append(a, big.NewInt(2))

// Need contract address and invoke function name.
// Also, same as deployment, need ABI and bytecode.
invokeSolContractMsg := types.InvokeSolContractMsg{
    ContractAddress: "0xBe0AE9A424771C0D68D942A04994a97f928b0821",
    ContractFuncCallName: "store",
    Args: args,
    ABIJsonFilePath: "./abi.json",
    BytecodeJsonFilePath: "./bytecode.json",
}

txbytes, err := xplac.InvokeSolidityContract(invokeSolContractMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Query) Call solidity contract
callSolContractMsg := types.CallSolContractMsg{
    ContractAddress: "0x80E123317190cAf36292A04776b0De020136526F",
    ContractFuncCallName: "retrieve",
    // Args: nil, // input params if needed to call
    ABIJsonFilePath: "./abi.json",
    BytecodeJsonFilePath: "./bytecode.json",
}

res, err := xplac.CallSolidityContract(callSolContractMsg).Query()
(Query) Get transaction by hash
getTransactionByHashMsg := types.GetTransactionByHashMsg {
    TxHash: "556c60576f9af3e4ae7d7fb28f8376e96803c4d9ff02eda6aacb86925f170d09",
}

res, err := xplac.GetTransactionByHash(getTransactionByHashMsg).Query()
(Query) Get Block by hash or height
// Query block by hash
getBlockByHashHeightMsg := types.GetBlockByHashHeightMsg {
    BlockHash: "0xe083b9b3a8b5df69394f55d34cfdfa46e70743a812d7433aba0adf3b7fcecd21",
}

// Query block by height
getBlockByHashHeightMsg := types.GetBlockByHashHeightMsg {
    BlockHeight: "8",
}

res, err := xplac.GetBlockByHashOrHeight(getBlockByHashHeightMsg).Query()
(Query) Account info
// Query account info of user account or contract
// Response of query includes account address(Hex and Bech32), balances and etc. 
// Including Info list
//   - "account" : account address
//   - "bech32_account" : account address of Bech32
//   - "balance" : balances of the account (eth_getBalance)
//   - "nonce" : account nonce as sequence of tendermint based blockchain (eth_getTransactionCount)
//   - "storage" : the storage address for a given account (eth_getStorageAt)
//   - "code" : the contract code of the given account (eth_getCode)
//   - "pending_balance" : the axpla balance of the given account in the pending state (eth_getBalance of the pending state)
//   - "pending_nonce" : the account nonce of the given account in the pending state (eth_getTransactionCount of the pending state)
//   - "pending_storage" : the value of key in the contract storage of the given account in the pending state (eth_getStorageAt of the pending state)
//   - "pending_code" : the contract code of the given account in the pending state (eth_getCode of the pending state)
//   - "pending_transaction_count" : the total number of transactions in the pending state (eth_getBlockTransactionCountByNumber of the pending state)

// so, the xpriv.go would not support some RPC APIs as "eth_getBalance", "eth_getTransactionCount", "eth_getStorageAt" and "eth_getCode" because the function is AccountInfo includes these.

accountInfoMsg := types.AccountInfoMsg{
    Account: "0xCa8582862B82867C4Bb9E926682dD75820dE6013",
}

res, err := xplac.AccountInfo(accountInfoMsg).Query()
(Query) Suggest gas price
res, err := xplac.SuggestGasPrice().Query()
(Query) ETH chain ID
res, err := xplac.EthChainID().Query()
(Query) Latest block number
res, err := xplac.EthBlockNumber().Query()
(Query) Web3 client version
res, err = xplac.Web3ClientVersion().Query()
(Query) Web3 SHA3 (return Keccak-256)
web3Sha3Msg := types.Web3Sha3Msg{
    InputParam: "web3-sha3-test",
}

res, err = xplac.Web3Sha3(web3Sha3Msg).Query()
(Query) Network ID
res, err = xplac.NetVersion().Query()
(Query) Network peer count
res, err = xplac.NetPeerCount().Query()
(Query) Network listening
res, err = xplac.NetListening().Query()
(Query) Ethereum protocol version
res, err = xplac.EthProtocolVersion().Query()
(Query) Ethereum syncing
res, err = xplac.EthSyncing().Query()
(Query) Eth accounts
res, err = xplac.EthAccounts().Query()
(Query) The number of transactions in a given block
// using block height(=number)
e := types.EthGetBlockTransactionCountMsg{
    BlockHeight: "5440",
}

// using block hash
e := types.EthGetBlockTransactionCountMsg{
    BlockHeight: "0x46b3031b22f065f933331dc032ccd34404282ccf7e4fcd54e02d1f808abc112c"
}

res, err = xplac.EthGetBlockTransactionCount(e).Query()
(Query) Estimate gas to contract
var args []interface{}
args = append(args, big.NewInt(6151212))

// invoke message to estimate
invokeSolContractMsg := types.InvokeSolContractMsg{
    ContractAddress:      c.ContractAddress,
    ContractFuncCallName: "store",
    Args:                 args,
    ABIJsonFilePath:      "./testfiles/abi.json",
    BytecodeJsonFilePath: "./testfiles/bytecode.json",
}

res, err = xplac.EstimateGas(invokeSolContractMsg).Query()
(Query) Get transaction by block hash and index
getTransactionByBlockHashAndIndexMsg := types.GetTransactionByBlockHashAndIndexMsg{
    BlockHash: "0x7f562573c1b0ca6fc3a83246372a5d57f917a4c654c91b65ebd756dec4989d0f",
    Index:     "0",
}

res, err = xplac.EthGetTransactionByBlockHashAndIndex(getTransactionByBlockHashAndIndexMsg).Query()
(Query) Get transaction receipt
getTransactionReceiptMsg := types.GetTransactionReceiptMsg{
    TransactionHash: "0x20ec56d16231c4d7f761c2533885619489fface85cf6c478868ef1d531b93177",
}

res, err = xplac.EthGetTransactionReceipt(getTransactionReceiptMsg).Query()
(Query) New filter
ethNewFilterMsg := types.EthNewFilterMsg{
    Topics:    []string{"0x20ec56d16231c4d7f761c2533885619489fface85cf6c478868ef1d531b93177"},
    Address:   []string{"0xf7777b36a51fb0b33dd0c5118361AfC94ff7f967"},
    ToBlock:   "latest",
    FromBlock: "earliest",
}

res, err = xplac.EthNewFilter(ethNewFilterMsg).Query()
(Query) New block filter
res, err = xplac.EthNewBlockFilter().Query()
(Query) New pending transaction filter
res, err = xplac.EthNewPendingTransactionFilter().Query()
(Query) Uninstall filter
ethUninsatllFilterMsg := types.EthUninsatllFilterMsg{
    FilterId: "0x168b9d421ecbffa1ac706926c2203454",
}

res, err = xplac.EthUninstallFilter(ethUninsatllFilterMsg).Query()
(Query) Get filter changes
ethGetFilterChangesMsg := types.EthGetFilterChangesMsg{
    FilterId: "0x9852d91813fb44da471436722e02965e",
}

res, err = xplac.EthGetFilterChanges(ethGetFilterChangesMsg).Query()
(Query) Get logs
ethGetLogsMsg := types.EthGetLogsMsg{
    Topics:  []string{"0x20ec56d16231c4d7f761c2533885619489fface85cf6c478868ef1d531b93177"},
    Address: []string{"0xf7777b36a51fb0b33dd0c5118361AfC94ff7f967"},
    ToBlock: "latest",
    FromBlock: "latest",
    // BlockHash: "0x46b3031b22f065f933331dc032ccd34404282ccf7e4fcd54e02d1f808abc112c",
}

res, err = xplac.EthGetLogs(ethGetLogsMsg).Query()
(Query) Coinbase
res, err = xplac.EthCoinbase().Query()

Documentation

Index

Constants

View Source
const (
	EvmModule                                   = "evm"
	EvmSendCoinMsgType                          = "evm-send-coin"
	EvmDeploySolContractMsgType                 = "deploy-sol-contract"
	EvmInvokeSolContractMsgType                 = "invoke-sol-contract"
	EvmCallSolContractMsgType                   = "call-sol-contract"
	EvmGetTransactionByHashMsgType              = "evm-get-transaction-by-hash"
	EvmGetBlockByHashHeightMsgType              = "evm-get-block"
	EvmQueryAccountInfoMsgType                  = "evm-query-account-info"
	EvmSuggestGasPriceMsgType                   = "suggest-gas-price"
	EvmQueryChainIdMsgType                      = "evm-chain-id"
	EvmQueryCurrentBlockNumberMsgType           = "current-block-number"
	EvmWeb3ClientVersionMsgType                 = "web3-client-version"
	EvmWeb3Sha3MsgType                          = "web3-sha"
	EvmNetVersionMsgType                        = "net-version"
	EvmNetPeerCountMsgType                      = "net-peer-count"
	EvmNetListeningMsgType                      = "net-listening"
	EvmEthProtocolVersionMsgType                = "eth-protocol-version"
	EvmEthSyncingMsgType                        = "eth-syncing"
	EvmEthAccountsMsgType                       = "eth-accounts"
	EvmEthGetBlockTransactionCountMsgType       = "eth-get-block-transaction-count"
	EvmEthEstimateGasMsgType                    = "eth-estimate-gas"
	EvmGetTransactionByBlockHashAndIndexMsgType = "eth-get-transaction-by-block-hash-and-index"
	EvmGetTransactionReceiptMsgType             = "eth-get-transaction-receipt"
	EvmEthNewFilterMsgType                      = "eth-new-filter"
	EvmEthNewBlockFilterMsgType                 = "eth-new-block-filter"
	EvmEthNewPendingTransactionFilterMsgType    = "eth-new-pending-transaction-filter"
	EvmEthUninstallFilterMsgType                = "eth-uninstall-filter"
	EvmEthGetFilterChangesMsgType               = "eth-get-filter-changes"
	EvmEthGetFilterLogsMsgType                  = "eth-get-filter-logs"
	EvmEthGetLogsMsgType                        = "eth-get-logs"
	EvmEthCoinbaseMsgType                       = "eth-coinbase"
)

Variables

View Source
var Args []interface{}

Functions

func MakeEthGetBlockTransactionCountMsg

func MakeEthGetBlockTransactionCountMsg(ethGetBlockTransactionCountMsg types.EthGetBlockTransactionCountMsg) (types.EthGetBlockTransactionCountMsg, error)

(Query) make msg - get transaction count of the block number

func MakeEthGetFilterChangesMsg

func MakeEthGetFilterChangesMsg(ethGetFilterChangesMsg types.EthGetFilterChangesMsg) (types.EthGetFilterChangesMsg, error)

(Query) make msg - eth get filter changes

func MakeEthGetFilterLogsMsg

func MakeEthGetFilterLogsMsg(ethGetFilterLogsMsg types.EthGetFilterLogsMsg) (types.EthGetFilterLogsMsg, error)

(Query) make msg - eth get filter logs

func MakeEthUninstallFilterMsg

func MakeEthUninstallFilterMsg(ethUninstallFilter types.EthUninstallFilterMsg) (types.EthUninstallFilterMsg, error)

(Query) make msg - eth uninstall filter

func MakeGetBlockByHashHeightMsg

func MakeGetBlockByHashHeightMsg(getBlockByHashHeightMsg types.GetBlockByHashHeightMsg) (types.GetBlockByHashHeightMsg, error)

(Query) make msg - block by hash or height

func MakeGetTransactionByBlockHashAndIndexMsg

func MakeGetTransactionByBlockHashAndIndexMsg(getTransactionByBlockHashAndIndexMsg types.GetTransactionByBlockHashAndIndexMsg) (types.GetTransactionByBlockHashAndIndexMsg, error)

(Query) make msg - get transaction by block hash and index

func MakeGetTransactionByHashMsg

func MakeGetTransactionByHashMsg(getTransactionByHashMsg types.GetTransactionByHashMsg) (types.GetTransactionByHashMsg, error)

(Query) make msg - transaction by hash

func MakeGetTransactionReceiptMsg

func MakeGetTransactionReceiptMsg(getTransactionReceiptMsg types.GetTransactionReceiptMsg) (types.GetTransactionReceiptMsg, error)

(Query) make msg - get transaction receipt

func MakeInvokeSolContractMsg

func MakeInvokeSolContractMsg(InvokeSolContractMsg types.InvokeSolContractMsg) (types.InvokeSolContractMsg, error)

(Tx) make msg - invoke solidity contract

func MakeQueryAccountInfoMsg

func MakeQueryAccountInfoMsg(accountInfoMsg types.AccountInfoMsg) (types.AccountInfoMsg, error)

(Query) make msg - account info

func MakeSendCoinMsg

func MakeSendCoinMsg(sendCoinMsg types.SendCoinMsg, privKey key.PrivateKey) (types.SendCoinMsg, error)

(Tx) make msg - send coin

func MakeWeb3Sha3Msg

func MakeWeb3Sha3Msg(web3Sha3Msg types.Web3Sha3Msg) (types.Web3Sha3Msg, error)

(Query) make msg - web3 sha3

Types

type CallSolContractParseMsg

type CallSolContractParseMsg struct {
	CallMsg  ethereum.CallMsg
	CallName string
	ABI      string
	Bytecode string
}

func MakeCallSolContractMsg

func MakeCallSolContractMsg(callSolContractMsg types.CallSolContractMsg, byteAddress string) (CallSolContractParseMsg, error)

(Query) make msg - call solidity contract

func MakeEstimateGasSolMsg

func MakeEstimateGasSolMsg(invokeSolContractMsg types.InvokeSolContractMsg, byteAddress string) (CallSolContractParseMsg, error)

(Query) make msg - sol contract estimate gas

type ContractInfo

type ContractInfo struct {
	Abi      string
	Bytecode string
}

func MakeDeploySolContractMsg

func MakeDeploySolContractMsg(deploySolContractMsg types.DeploySolContractMsg) (ContractInfo, error)

(Tx) make msg - deploy solidity contract

type DeploySolTx

type DeploySolTx struct {
	ChainId  *big.Int
	Nonce    *big.Int
	Value    *big.Int
	GasLimit uint64
	GasPrice *big.Int
	ABI      string
	Bytecode string
}

type EthNewFilterParseMsg

type EthNewFilterParseMsg struct {
	BlockHash *common.Hash     `json:"blockHash,omitempty"`
	FromBlock *rpc.BlockNumber `json:"fromBlock"`
	ToBlock   *rpc.BlockNumber `json:"toBlock"`
	Addresses interface{}      `json:"address"`
	Topics    []interface{}    `json:"topics"`
}

func MakeEthGetLogsMsg

func MakeEthGetLogsMsg(ethGetLogsMsg types.EthGetLogsMsg) (EthNewFilterParseMsg, error)

(Query) make msg - eth get logs

func MakeEthNewFilterMsg

func MakeEthNewFilterMsg(ethNewFilterMsg types.EthNewFilterMsg) (EthNewFilterParseMsg, error)

(Query) make msg - eth new filter

Jump to

Keyboard shortcuts

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