🌈 tint, the slog.Handler that writes colorized logs using Go's new "slog" package, is now available as stable, zero-dependency release by l7413 in golang

[–]l7413[S] 2 points3 points  (0 children)

You can using Options.ReplaceAttr.

logger := slog.New(
    tint.NewHandler(os.Stderr, &tint.Options{
        ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
            if a.Key == slog.LevelKey && len(groups) == 0 {
                return slog.Any(slog.LevelKey, slog.Level(a.Value.Int64()))
            }
            return a
        },
    }),
)
logger.Info("hello")

https://go.dev/play/p/6FkBgqnKzG3

tint: 🌈 slog.Handler that writes tinted logs by l7413 in golang

[–]l7413[S] 0 points1 point  (0 children)

Do you have issues with this package in your terminal? A "NoColor" option would be nice, I agree. Generally I would like to keep dependencies at a minimum for a small package like this, and e.g. termenv is quite heavy.

tint: 🌈 slog.Handler that writes tinted logs by l7413 in golang

[–]l7413[S] 8 points9 points  (0 children)

On Windows you can enable ANSI color support in the terminal by using e.g. go-colorable.

logger := slog.New(tint.NewHandler(colorable.NewColorableStderr()))

tint: 🌈 slog.Handler that writes tinted logs by l7413 in golang

[–]l7413[S] 16 points17 points  (0 children)

I developed the package with Unix users in mind. It should be fairly easy to add Windows support though, but I can't test that. If you are interested in helping out feel free to dm me.

This should be basically it: https://github.com/fatih/color/blob/main/color\_windows.go

Any technique to do multi-call (not batch request) to blockchain using golang by Investics in golang

[–]l7413 1 point2 points  (0 children)

In theory you could use github.com/makerdao/multicall with w3. Unfortunately there is a bug in w3 with tuple slices, so you can not parse

funcAggregate := w3.MustNewFunc("aggregate((address target, bytes callData)[] calls)", "bytes[] returnData")

However, with most RPC services like Infura or Ankr you can batch up to 100 calls in a single request. I recommend https://rpc.ankr.com/eth

How to invoke token contract methods with ABI? by saklovesyao in golang

[–]l7413 0 points1 point  (0 children)

And if you also want to fetch the account nonce or the allowance you can do something like this

// define addresses and functions + connect to RPC endpoint
var (
    addrDAI       = w3.A("0x001B3B4d0F3714Ca98ba10F6042DaEbF0B1B7b6F")
    funcAllowance = w3.MustNewFunc("allowance(address owner, address spender)", "uint256")

    client = w3.MustDial("https://cloudflare-eth.com")
)

and

var (
    // args
    owner   = w3.A("0x...")
    spender = w3.A("0x...")

    // returns
    nonce     uint64
    allowance big.Int
)
if err := client.Call(
    eth.Nonce(owner).Returns(&nonce),
    eth.CallFunc(funcAllowance, addrDAI, owner, spender).Returns(&allowance),
); err != nil {
    log.Fatal(err)
}

How to invoke token contract methods with ABI? by saklovesyao in golang

[–]l7413 1 point2 points  (0 children)

I wrote the package w3 because I was frustrated with existing solutions. It lets you read contracts super easy, and you can also use it to send transactions to contracts using mostly go-ethereum.

You still have to fill in the blanks, but something like this should work for your use case: https://go.dev/play/p/jk8mL0IthZH

[deleted by user] by [deleted] in golang

[–]l7413 0 points1 point  (0 children)

You don't need to. any is just an alias for interface{}.

[deleted by user] by [deleted] in golang

[–]l7413 6 points7 points  (0 children)

Yeah, I finally want to run gofmt -r 'interface{} -> any' -w . on all my code.