Skip to content

Instantly share code, notes, and snippets.

@thaarok
thaarok / programmatic_gateway.js
Created April 22, 2025 19:40
Sonic Gateway usage sample
#!/usr/bin/env node
const { ethers } = require("ethers");
const STATE_ORACLE_ABI = [
"function lastBlockNum() external view returns (uint256)",
"function lastState() external view returns (bytes32)"
];
const ERC20_ABI = [
"function approve(address spender, uint256 amount) external returns (bool)",
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
@thaarok
thaarok / foundry.toml
Last active April 1, 2025 17:45
Sonic and Sonic Blaze testnet configuration for Hardhat/Foundry
[rpc_endpoints]
mainnet = "https://rpc.soniclabs.com/"
testnet = "https://rpc.blaze.soniclabs.com"
[etherscan]
mainnet = { chain = 146, key = "...sonicscan key...", url = "https://api.sonicscan.org/api" }
testnet = { chain = 57054, key = "...sonicscan key...", url = "https://api-testnet.sonicscan.org/api" }
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
interface ContractsRegistrar {
function selfRegister(uint256) external;
}
contract MyContract {
@thaarok
thaarok / SFClibCode.md
Last active November 6, 2024 15:21
SFClib code checking

SFClib code checking

Using hardhat-tracer to get slot key, where is sfclib address in SFC during npx hardhat test --fulltrace:

[CALL] UnitTestSFC(0x5fbdb2315678afecb367f032d93f642f64180aa3).initialize(sealedEpoch: 12, _totalSupply: 0, nodeDriver: [NodeDriverAuth], lib: 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9, _c: [UnitTestConstantsManager], owner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266)
[SSTORE] 0x0000000000000000000000000000000000000000000000000000000000000080 ← 0x000000000000000000000000dc64a140aa3e981100a9beca4e685f962f0cf6c9

Read storage slot with sfclib address from SFC:

@thaarok
thaarok / pubkey2address.md
Created September 3, 2024 18:10
Ethereum pubkey to address

Example data: (Opera fakenet)

Pubkey: 0xc0048d505c351f4837cec72bce6f4254f5e4bc3f2c9a4816841db64319eee8b714ef9173fbf66d039b782624713791840846b2788d4b65a425adeba85a4b57efe0cd

Converts to address: 0x239fA7623354eC26520dE878B52f13Fe84b06971

Solidity:

    function pubkeyToAddress(bytes calldata pubkey) external pure returns(address) {
 require(pubkey.length == 66 &amp;&amp; pubkey[0] == 0xc0, "malformed pubkey");
package main
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
)
package genesis
// go-gzip, no hashing elapsed=49.274027963s
// pgzip.NewReaderN(reader, 1024, 100*1024) , no hashing, elapsed=1m13.959573387s
import (
"archive/tar"
"crypto/sha256"
"encoding/hex"
"fmt"
adb shell
pm list packages -f
# xiaomi calendar
pm disable-user --user 0 com.xiaomi.calendar
# aplikační trezor
pm disable-user --user 0 com.mi.android.globalminusscreen
# čistič
@thaarok
thaarok / ethereum-keystore-load.go
Last active April 25, 2023 18:35
Reading ethereum JSON keystore to obtain PrivateKey object.
package driver
import (
"crypto/ecdsa"
"github.com/gochain/gochain/v4/accounts/keystore"
"os"
"testing"
)
const PrivateKeyStore = "~/.opera/fakenet-1/keystore/UTC--2023-04-25T07-50-08.017708542Z--239fa"