Skip to content

Instantly share code, notes, and snippets.

View alextcn's full-sized avatar
⛩️
focused

Alex Tkachenko alextcn

⛩️
focused
View GitHub Profile
@alextcn
alextcn / ens-setfields-multicall.ts
Created January 25, 2023 18:36
Set multiple resolver records in a single transaction
import { ethers } from 'ethers'
import { namehash } from 'ethers/lib/utils.js'
const ENS_RESOLVER_ADDRESS = '0x2800Ec5BAB9CE9226d19E0ad5BC607e3cfC4347E' // goerli
const ENS_RESOLVER_ABI = [
'function addr(bytes32 node) external view returns (address)',
'function setAddr(bytes32 node, address a) external',
'function text(bytes32 node, string calldata key) external view returns (string memory)',
'function setText(bytes32 node, string calldata key, string calldata value) external',
'function multicall(bytes[] calldata data) external returns(bytes[] memory results)'
@alextcn
alextcn / Step.tsx
Created January 19, 2023 20:07
Dynamically computed step based on Registartion status in Storage
import { MIN_COMMIT_TIME_S } from 'lib/constants'
import { useRegistration } from 'lib/hooks/storage'
import { RegistrationStatus } from 'lib/types'
import { useSigner, useFeeData, useAccount } from 'wagmi'
import { CommitmentForm } from './CommitmentForm'
import { RegisterStep } from './RegisterStep'
import { Success } from './Success'
import { WaitMinute } from './WaitMinute'
export const Step = ({
@alextcn
alextcn / storage.ts
Created January 19, 2023 16:12
Proposal for typed local storage service
import { useLocalStorage } from "usehooks-ts"
import { RegistrationStep } from "../types"
// Registrations map example
// const registrations = {
// 'xdomain1.eth': {
// domain: 'xdomain1.eth',
// name: 'xdomain1',
// owner: '0x9C51161bA2FB02Cc0a403332B607117685f34831',
@alextcn
alextcn / ens-commit-register.ts
Created January 18, 2023 19:06
Commit and regsiter ENS domain on Goerli network
import { ethers, Wallet } from 'ethers'
// const ALCHEMY_URL = `https://eth-goerli.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_API_KEY!}`
const ETH_REGISTRAR_ADDRESS = '0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5' // goerli
const ETH_REGISTRAR_ABI = [
'function available(string) view returns (bool)',
'function makeCommitment(string,address,bytes32) pure returns (bytes32)',
'function commit(bytes32)',
'function register(string,address,uint256,bytes32) payable',
@alextcn
alextcn / SocketTcpClient.kt
Last active July 5, 2023 21:09
Main-safe Kotlin coroutine implementation of TCP client based on Okio
import android.util.Log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.withContext
import net.monetizemyapp.toolbox.extentions.toHexString
import okio.*
import java.net.Socket
import javax.net.ssl.SSLSocketFactory
@alextcn
alextcn / EnterActionListener.kt
Created January 9, 2019 20:16
Listener for enter key input for EditText
/**
* Simple [TextView.OnEditorActionListener] implementation for handling IME action
* @param onAction called when IME action selected or Enter is clicked
*/
class EnterActionListener(private val onAction: () -> Unit) : TextView.OnEditorActionListener {
override fun onEditorAction(v: TextView?, actionId: Int, event: KeyEvent?): Boolean {
// If triggered by an enter key, this is the event; otherwise, this is null.
// if shift key is down, then we want to insert the '\n' char in the TextView;
if (event == null || event.isShiftPressed) return false
package io.jackqack.hodler.utils
import android.content.Context
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
object Vibrator {
private const val VIBRATE_LENGTH_LONG_TOUCH = 50L
@alextcn
alextcn / my-preferences.kt
Created December 13, 2017 08:52
Example of wrapping OnSharedPreferenceChangeListener in RxJava2 observable
// package and imports
@Singleton
class MyPreferences
@Inject constructor(val context: Context) {
companion object {
private const val PREF_FILE_NAME = "pg_cfg"