itering / scale.rb

Ruby SCALE Codec Library & Substrate Client
MIT License
19 stars 10 forks source link

How to query transaction use scale.rb #33

Open gith-u-b opened 2 years ago

gith-u-b commented 2 years ago
  // http "localhost:8080/worker/transferHash" hash=0xe538bc7a849674eee8a80e13e7d3ef16848884378860d1e15fa7bd5f26fc09e0
  server.post<{ Body: { pay: string, hash: string } }>("/worker/transferHash", async (request, reply) => {
    let { pay, hash } = request.body

    let wsProvider = new WsProvider('wss://rpc.polkadot.io');

    if(pay == 'dot') {
      wsProvider = new WsProvider('wss://rpc.polkadot.io');
    }

    if(pay == 'ksm') {
      wsProvider = new WsProvider('wss://kusama-rpc.polkadot.io');
    }

    const api = await ApiPromise.create({ provider: wsProvider });

    const apiAt = await api.at(hash);

    const res = await apiAt.query.system.events();

    return { hash: res }
  });

params:

{
    "pay": "ksm",
    "hash": "0x644ca2c9d51ebac88642575ef2683298030f150b1961d68ce866ae871f2c0bea"
}

can get datas:

...
"event": {
                "index": "0x0402",
                "data": [
                    "HhZPpZPBprLxZxabTiCGuASaPPthsd856kdPhAtCBafd8Sk",
                    "DkfU3g34NVrxEt4L4NK8uqez2ARLT7W4QGC98PCkjTdsPoV",
                    100000000000
                ]
            },
            "topics": []
...
gith-u-b commented 2 years ago

I want to use scale.rb,how can I implement this function, thanks.

gith-u-b commented 2 years ago

@freehere107 🙏

wuminzhe commented 2 years ago

@sai1024 I will look into your issue. It is not recommended to use it in the product. Use https://github.com/polkadot-js instead.