I want to call DelegateCall(caller ContractRef, addr common.Address, input []byte, gas uint64) in geth, but it can only be triggered by the opcode. So I want to convert address of deployed contract to ContractRef type, as the first parameter of Delegatcall, but i don't know how to realize it. Since caller should be the address of contract object, and common.Address(caller) shouldn't be nil. Or is there any other way to realize it?

// ContractRef is a reference to the contract's backing object
type ContractRef interface {
    Address() common.Address

// AccountRef implements ContractRef.
// Account references are used during EVM initialisation and
// it's primary use is to fetch addresses. Removing this object
// proves difficult because of the cached jump destinations which
// are fetched from the parent contract (i.e. the caller), which
// is a ContractRef.
type AccountRef common.Address

// Address casts AccountRef to a Address
func (ar AccountRef) Address() common.Address { return (common.Address)(ar) }
// Contract represents an ethereum contract in the state database. It contains
// the contract code, calling arguments. Contract implements ContractRef
type Contract struct {
    // CallerAddress is the result of the caller which initialised this
    // contract. However when the "call method" is delegated this value
    // needs to be initialised to that of the caller's caller.
    CallerAddress common.Address
    caller        ContractRef
    self          ContractRef

    jumpdests map[common.Hash]bitvec // Aggregated result of JUMPDEST analysis.
    analysis  bitvec                 // Locally cached result of JUMPDEST analysis

    Code     []byte
    CodeHash common.Hash
    CodeAddr *common.Address
    Input    []byte

    Gas   uint64
    value *big.Int


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.