0

How do I receive a revert message using go-ethereum?

receipt, err := bind.WaitMined(context.Background(), client, tx)
if err != nil {
    fmt.Errorf(err)
}
fmt.Println(receipt.Status)

Now I can only get status. I use abigen to call smart contract methods

0

I use something like that, it redo the transaction as a call and that way you get the failing message.

func GetFailingMessage(client ethclient.Client, hash common.Hash) (string, error) {
    tx, _, err := client.TransactionByHash(context.Background(), hash)
    if err != nil {
        return "", err
    }

    from, err := types.Sender(types.NewEIP155Signer(tx.ChainId()), tx)
    if err != nil {
        return "", err
    }

    msg := ethereum.CallMsg{
        From:     from,
        To:       tx.To(),
        Gas:      tx.Gas(),
        GasPrice: tx.GasPrice(),
        Value:    tx.Value(),
        Data:     tx.Data(),
    }

    res, err := client.CallContract(context.Background(), msg, nil)
    if err != nil {
        return "", err
    }

    return string(res), nil
}

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.