lmittmann / w3

Enhanced Ethereum Integration for Go
http://w3.cool
MIT License
179 stars 32 forks source link

How do you use encoded args on more than one input? #193

Open bitcoinbrisbane opened 3 hours ago

bitcoinbrisbane commented 3 hours ago

Im trying to call the uniswap getPool function getPool(address,address,uint24), but im getting the error

Request failed: argument count mismatch: got 1 for 3

My sample code.

func GetPoolAddress(tokenIn, tokenOut common.Address) common.Address {

    client := w3.MustDial("https://eth-mainnet.g.alchemy.com/v2/")
    defer client.Close()

    factorAddress := "0x1F98431c8aD98523631AE4a59f267346ea31F984"
    fmt.Println(factorAddress)

    _factoryAddress := common.HexToAddress(factorAddress)

    // funcBalanceOf := w3.MustNewFunc("balanceOf(address)", "uint256")

    fee := &big.Int{}
    fee.SetInt64(3000)
    // fee := uint24(3000) // Fee tier of 0.3%

    getPool := w3.MustNewFunc("getPool(address,address,uint24)", "address")
    input, err := getPool.EncodeArgs(tokenIn, tokenOut, fee)
    fmt.Println(input)

    if err != nil {
        log.Fatalf("Failed to encode arguments: %v", err)
    }

    var poolAddress string

    if err := client.Call(
        eth.CallFunc(_factoryAddress, getPool, input).Returns(&poolAddress),
    ); err != nil {
        fmt.Printf("Request failed: %v\n", err)
    }

    return common.HexToAddress(poolAddress)
}
bitcoinbrisbane commented 2 hours ago

Oh, found this.. very helpful https://raw.githubusercontent.com/lmittmann/w3/refs/heads/main/examples/uniswap_quote/main.go