-
-
Save the-frey/2e0ccba7a51ffed515fd6a1366c81a50 to your computer and use it in GitHub Desktop.
Listen cw20 transactions (Cosmwasm v1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"time" | |
rpchttp "github.com/tendermint/tendermint/rpc/client/http" | |
) | |
func main() { | |
client, err := rpchttp.New("tcp://127.0.0.1:26657", "/websocket") | |
cw20Contract := "juno1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrsf8smqw" | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = client.Start() | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer client.Stop() | |
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | |
defer cancel() | |
query := fmt.Sprintf("message.module='wasm' AND wasm._contract_address='%s' AND wasm.action='transfer'", cw20Contract) | |
txs, err := client.Subscribe(ctx, "wasm-client", query) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for e := range txs { | |
from := e.Events["wasm.from"][0] | |
to := e.Events["wasm.to"][0] | |
amount := e.Events["wasm.amount"][0] | |
fmt.Println("Tx: " + e.Events["tx.hash"][0]) | |
fmt.Printf("Sender: %s \nRecipient: %s \nAmount: %s \n", from, to, amount) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment