Skip to content

Instantly share code, notes, and snippets.

Sei EVM/Cosmos Network Debug Tools

Here is a small collection of scripts and shell aliases designed to perform some very basic but very common and useful functions. These quick simple tools are meant to relieve a bit of the tedious repetative tasks when debugging or exploring information or applications on the Sei network.


Setup Instructions

  1. Clone or Copy Scripts: Save the provided scripts into your preferred directory (e.g., $HOME/scripts/). Ensure each file is executable:
{
"height": "121100000",
"txs_results": [
{
"data": "CjsKOS9zZWlwcm90b2NvbC5zZWljaGFpbi5vcmFjbGUuTXNnQWdncmVnYXRlRXhjaGFuZ2VSYXRlVm90ZQ==",
"log": "[{\"events\":[{\"type\":\"aggregate_vote\",\"attributes\":[{\"key\":\"voter\",\"value\":\"seivaloper1eqgnd7ey0hnha8rrfukjrsawulhna0zagcg6a4\"},{\"key\":\"exchange_rates\",\"value\":\"8.845690216795218153uatom,107021.748879006658294837ubtc,4008.477046844315062544ueth,0.565628020247734634uosmo,0.563588821514982633usei,1.000048205457096475uusdc,0.999833844706186033uusdt\"}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"/seiprotocol.seichain.oracle.MsgAggregateExchangeRateVote\"},{\"key\":\"module\",\"value\":\"oracle\"},{\"key\":\"sender\",\"value\":\"sei1nurfe690mer9dmy8pp7resdsfx3pya7h9qw39l\"}]}]}]",
"events": [
{
"type": "tx",
"attributes": [
Transaction details: TransactionResponse {
provider: JsonRpcProvider {},
blockNumber: 137629212,
blockHash: '0x4b0e086270aa23e19bb2acf02fa6cb4551c277891e5341997bd6c82a8f4847b0',
index: 25,
hash: '0x8f4d9c63fa3b64b7d3d1b9292a0be9b2964c402b1d97ec42c8ecfe59c00337b0',
type: 0,
to: null,
from: '0x9cD0845fE5d261F3057d1a1d037b79414cA33C1A',
nonce: 2,
@cordt-sei
cordt-sei / index.js
Last active December 10, 2024 22:47
queryOwnersByPointer
import { ethers } from "ethers";
// Use your provided RPC and contract address
const provider = new ethers.JsonRpcProvider("https://evm-rpc.basementnodes.ca:8545");
const contractAddress = "0xdfa4ec4246f569d730edd9044965d3afeea980eb";
const abi = [
"function totalSupply() public view returns (uint256)",
"function ownerOf(uint256 tokenId) public view returns (address)"
];
const contract = new ethers.Contract(contractAddress, abi, provider);

Cosmos tx data structure as seen from Numia data tables

WITH 
-- Retrieve the block date for the specified height
block_info AS (
  SELECT 
    block_height,
    block_date
  FROM 
@cordt-sei
cordt-sei / index.js
Last active December 9, 2024 01:29
Find all tokens and owners for ERC721 collection [pointer]
// pipe output to file if your collection has a large number of tokens
// [node index.js > tokens.json]
import { ethers } from "ethers";
// Use your provided RPC and contract address
const provider = new ethers.JsonRpcProvider("http://localhost:8545");
const contractAddress = "0x[contract_address]";
const abi = [
"function totalSupply() public view returns (uint256)",

Quick dive into wasm contract queries

They are all fairly straightforward, since everything is human-readable and all the functions and methods are returned by simply sending an "invalid" payload in a query.

The REST API method is simple:

/cosmwasm/wasm/v1/contract/${contractAddress}/smart/${payLoad_base64}

Quick queries

import { ethers } from "ethers";
export class SeiLogsFetcher {
constructor(providerUrl, maxBatchSize = 2000, maxLogs = 10000) {
this.provider = new ethers.JsonRpcProvider(providerUrl);
this.maxBatchSize = maxBatchSize;
this.maxLogs = maxLogs;
}
async getLogs(filter, logLevel = "INFO") {
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": [
        {
            "txHash": "0x2a4fdac3dd8a3de29b12f0e9d62c4d6606e874183c3ccd84c2226843d9074811",
            "result": {
                "from": "0x3956f101e76810ccc59c340a61569d9f3f5b74a8",
                "gas": "0x1e8480",
@cordt-sei
cordt-sei / associate.ts
Last active December 12, 2024 14:22 — forked from besated/associate.ts
// Here are detailed **4** different methods with which a new account can be "associated" or "linked" on-chain
// In very clear terms, all this is doing is making the pubkey known to the chain.
// This is required because there is no way to determine either of the wallet addresses from the other.
import secp256k1 from "secp256k1";
import { createPublicClient, createWalletClient, hexToNumber, http, numberToHex, parseSignature, toHex } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { seiTestnet } from "viem/chains";
import { ADDRESS_PRECOMPILE_ABI, ADDRESS_PRECOMPILE_ADDRESS } from '@sei-js/evm';