evmchain

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0, BSD-2-Clause Imports: 22 Imported by: 0

README

The evmchain smart contract

The evmchain smart contract emulates an Ethereum blockchain on top of the ISCP chain, allowing to run Ethereum smart contracts.

EVM support

The evmchain contract is implemented as a native contract, and as such it needs to be enabled at compile time. EVM support is enabled by default, so no special action is needed.

EVM support inflates the wasp and wasp-cli binaries by several MB. If this is a problem and you don't need EVM support, you can disable it at compile time by providing the -tags noevm flag to the Go compiler. For example:

go install -tags noevm ./...

Deploy

You can use wasp-cli to deploy the evmchain contract (given that you already have access to an ISCP chain and have deposited some funds into your on-chain account):

wasp-cli chain evm deploy --alloc 0x71562b71999873DB5b286dF957af199Ec94617F7:115792089237316195423570985008687907853269984665640564039457584007913129639927

The --alloc parameter specifies the genesis allocation for the EVM chain, with syntax address:wei [address:wei ...].

JSON-RPC

Once your EVM chain is deployed, you can use the wasp-cli chain evm jsonrpc command to start a JSON-RPC server. This will allow you to connect any standard Ethereum tool, like Metamask.

Complete example using wasp-cluster

In terminal #1, start a cluster:

wasp-cluster start -d

In terminal #2:

# initialize a private key and request some funds
wasp-cli init
wasp-cli request-funds

# deploy an ISCP chain, deposit some funds to be used for fees
wasp-cli chain deploy --chain=mychain --committee=0,1,2,3 --quorum 3
wasp-cli chain deposit IOTA:1000

# deploy an EVM chain
wasp-cli chain evm deploy --alloc 0x71562b71999873DB5b286dF957af199Ec94617F7:115792089237316195423570985008687907853269984665640564039457584007913129639927

Finally we start the JSON-RPC server:

wasp-cli chain evm jsonrpc

Documentation

Overview

package evmchain provides the `evmchain` contract, which allows to emulate an Ethereum blockchain on top of ISCP.

Index

Constants

View Source
const (
	FieldChainID                 = "chid"
	FieldGenesisAlloc            = "g"
	FieldAddress                 = "a"
	FieldKey                     = "k"
	FieldAgentID                 = "i"
	FieldTransaction             = "tx"
	FieldTransactionIndex        = "ti"
	FieldTransactionHash         = "h"
	FieldTransactionData         = "t"
	FieldTransactionDataBlobHash = "th"
	FieldCallArguments           = "c"
	FieldResult                  = "r"
	FieldBlockNumber             = "bn"
	FieldBlockHash               = "bh"
	FieldCallMsg                 = "c"
	FieldEvmOwner                = "o"
	FieldNextEvmOwner            = "n"
	FieldGasPerIota              = "w"
	FieldGasFee                  = "f"
	FieldGasUsed                 = "gu"
	FieldFilterQuery             = "fq"
)
View Source
const DefaultGasPerIota uint64 = 1000

Variables

View Source
var (
	// Ethereum blockchain
	FuncGetBalance                          = coreutil.ViewFunc("getBalance")
	FuncSendTransaction                     = coreutil.Func("sendTransaction")
	FuncCallContract                        = coreutil.ViewFunc("callContract")
	FuncEstimateGas                         = coreutil.ViewFunc("estimateGas")
	FuncGetNonce                            = coreutil.ViewFunc("getNonce")
	FuncGetReceipt                          = coreutil.ViewFunc("getReceipt")
	FuncGetCode                             = coreutil.ViewFunc("getCode")
	FuncGetBlockNumber                      = coreutil.ViewFunc("getBlockNumber")
	FuncGetBlockByNumber                    = coreutil.ViewFunc("getBlockByNumber")
	FuncGetBlockByHash                      = coreutil.ViewFunc("getBlockByHash")
	FuncGetTransactionByHash                = coreutil.ViewFunc("getTransactionByHash")
	FuncGetTransactionByBlockHashAndIndex   = coreutil.ViewFunc("getTransactionByBlockHashAndIndex")
	FuncGetTransactionByBlockNumberAndIndex = coreutil.ViewFunc("getTransactionByBlockNumberAndIndex")
	FuncGetBlockTransactionCountByHash      = coreutil.ViewFunc("getBlockTransactionCountByHash")
	FuncGetBlockTransactionCountByNumber    = coreutil.ViewFunc("getBlockTransactionCountByNumber")
	FuncGetStorage                          = coreutil.ViewFunc("getStorage")
	FuncGetLogs                             = coreutil.ViewFunc("getLogs")

	// EVMchain SC management
	FuncSetNextOwner    = coreutil.Func("setNextOwner")
	FuncClaimOwnership  = coreutil.Func("claimOwnership")
	FuncGetOwner        = coreutil.ViewFunc("getOwner")
	FuncSetGasPerIota   = coreutil.Func("setGasPerIota")
	FuncGetGasPerIota   = coreutil.ViewFunc("getGasPerIota")
	FuncWithdrawGasFees = coreutil.Func("withdrawGasFees")
)
View Source
var Contract = coreutil.NewContract("evmchain", "EVM chain smart contract")
View Source
var Processor = Contract.Processor(initialize,

	FuncSendTransaction.WithHandler(applyTransaction),
	FuncGetBalance.WithHandler(getBalance),
	FuncCallContract.WithHandler(callContract),
	FuncEstimateGas.WithHandler(estimateGas),
	FuncGetNonce.WithHandler(getNonce),
	FuncGetReceipt.WithHandler(getReceipt),
	FuncGetCode.WithHandler(getCode),
	FuncGetBlockNumber.WithHandler(getBlockNumber),
	FuncGetBlockByNumber.WithHandler(getBlockByNumber),
	FuncGetBlockByHash.WithHandler(getBlockByHash),
	FuncGetTransactionByHash.WithHandler(getTransactionByHash),
	FuncGetTransactionByBlockHashAndIndex.WithHandler(getTransactionByBlockHashAndIndex),
	FuncGetTransactionByBlockNumberAndIndex.WithHandler(getTransactionByBlockNumberAndIndex),
	FuncGetBlockTransactionCountByHash.WithHandler(getBlockTransactionCountByHash),
	FuncGetBlockTransactionCountByNumber.WithHandler(getBlockTransactionCountByNumber),
	FuncGetStorage.WithHandler(getStorage),
	FuncGetLogs.WithHandler(getLogs),

	FuncSetNextOwner.WithHandler(setNextOwner),
	FuncClaimOwnership.WithHandler(claimOwnership),
	FuncSetGasPerIota.WithHandler(setGasPerIota),
	FuncWithdrawGasFees.WithHandler(withdrawGasFees),
	FuncGetOwner.WithHandler(getOwner),
	FuncGetGasPerIota.WithHandler(getGasPerIota),
)

Functions

func DecodeBlock

func DecodeBlock(b []byte) (*types.Block, error)

func DecodeCallMsg

func DecodeCallMsg(callArgsBytes []byte) (ret ethereum.CallMsg, err error)

func DecodeFilterQuery

func DecodeFilterQuery(b []byte) (*ethereum.FilterQuery, error)

func DecodeGenesisAlloc

func DecodeGenesisAlloc(b []byte) (core.GenesisAlloc, error)

func DecodeLog

func DecodeLog(b []byte, includeDerivedFields bool) (*types.Log, error)

func DecodeLogs

func DecodeLogs(b []byte) ([]*types.Log, error)

func DecodeTransaction

func DecodeTransaction(b []byte) (*types.Transaction, error)

func EncodeBlock

func EncodeBlock(block *types.Block) []byte

func EncodeCallMsg

func EncodeCallMsg(c ethereum.CallMsg) []byte

func EncodeFilterQuery

func EncodeFilterQuery(q *ethereum.FilterQuery) []byte

func EncodeGenesisAlloc

func EncodeGenesisAlloc(alloc core.GenesisAlloc) []byte

func EncodeLog

func EncodeLog(log *types.Log, includeDerivedFields bool) []byte

func EncodeLogs

func EncodeLogs(logs []*types.Log) []byte

func EncodeTransaction

func EncodeTransaction(tx *types.Transaction) []byte

Types

type Receipt

type Receipt struct {
	TxHash            common.Hash
	TransactionIndex  uint32
	BlockHash         common.Hash
	BlockNumber       *big.Int
	From              common.Address
	To                *common.Address
	CumulativeGasUsed uint64
	GasUsed           uint64
	ContractAddress   *common.Address
	Logs              []*types.Log
	Bloom             types.Bloom
	Status            uint64
}

func DecodeReceipt

func DecodeReceipt(receiptBytes []byte) (*Receipt, error)

func NewReceipt

func NewReceipt(r *types.Receipt, tx *types.Transaction) *Receipt

func (*Receipt) Bytes

func (r *Receipt) Bytes() []byte

Jump to

Keyboard shortcuts

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