2

In have downloaded go-ethereum package and made the private network. I am able to make changes in the code as per my requirement and it is also working fine. However, ethereum_js.go file has the following lines

    var getTransaction = new Method({
    name: 'getTransaction',
    call: 'eth_getTransactionByHash',
    params: 1,
    outputFormatter: formatters.outputTransactionFormatter
    });

Above says whenever we use getTransaction, it call eth_getTransactionByHash.

But there is no function avaialable with name getTransactionByHash.

Also the following line is not clear

         outputFormatter: formatters.outputTransactionFormatter
0

Here's a full example of using the TransactionByHash method from the go-ethereum client package.

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethclient"
)

func main() {
    client, err := ethclient.Dial("https://mainnet.infura.io")
    if err != nil {
        log.Fatal(err)
    }

    txHash := common.HexToHash("0x5d49fcaa394c97ec8a9c3e7bd9e8388d420fb050a52083ca52ff24b3b65bc9c2")
    tx, isPending, err := client.TransactionByHash(context.Background(), txHash)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(tx.Hash().Hex())     // 0x5d49fcaa394c97ec8a9c3e7bd9e8388d420fb050a52083ca52ff24b3b65bc9c2
    fmt.Println(tx.Value().String()) // 10000000000000000 (in wei)
    fmt.Println(isPending)           // false
}

Check out the Ethereum Development with Go guide book for more examples.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.