Skip to content

Instantly share code, notes, and snippets.

Last active June 24, 2022 08:50
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Listen cw20 transactions (Cosmwasm v1)
package main
import (
rpchttp ""
func main() {
client, err := rpchttp.New("tcp://", "/websocket")
cw20Contract := "juno1suhgf5svhu4usrurvxzlgn54ksxmn8gljarjtxqnapv8kjnp4nrsf8smqw"
if err != nil {
err = client.Start()
if err != nil {
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 {
for e := range txs {
from := e.Events["wasm.from"][0]
to := e.Events[""][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