Skip to content

Instantly share code, notes, and snippets.

View 13x54n's full-sized avatar
🦝
I may be slow to respond.

Lexy 13x54n

🦝
I may be slow to respond.
View GitHub Profile
@13x54n
13x54n / lib.cairo
Created June 12, 2024 05:21
ERC20 Token from OpenZeppelin.
#[starknet::contract]
mod MingToken {
use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use starknet::ContractAddress;
component!(path: ERC20Component, storage: erc20, event: ERC20Event);
// ERC20 Mixin
#[abi(embed_v0)]
impl ERC20MixinImpl = ERC20Component::ERC20MixinImpl<ContractState>;
// Setup: npm install alchemy-sdk
import { Alchemy, Network } from "alchemy-sdk";
const config = {
apiKey: "<-- ALCHEMY APP API KEY -->",
network: Network.ETH_MAINNET,
};
const alchemy = new Alchemy(config);
//Feel free to switch this wallet address with another address
// Import necessary modules
const { Alchemy, Network } = require("alchemy-sdk");
require('dotenv').config();
const config = {
apiKey: "demo",
network: Network.ETH_MAINNET,
};
const alchemy = new Alchemy(config);
@13x54n
13x54n / GetERC20Tokens.md
Created May 8, 2024 01:32
Get all erc20 tokens of using Alchemy SDK.

How to fetch a Smart Account's ERC-20 tokens Alchemy provides several Enhanced APIs, which are especially useful for querying information about the smart accounts you create using Account Kit, such as the account's ERC-20 Token balances using the Token API.

For the purposes of our example, we will use the Token API to query our smart account's data by extending the Alchemy Smart Account Client with Enhanced APIs.

  1. Install the alchemy-sdk Alchemy has developed a Typescript SDK to make development with the Enhanced APIs simple. The SDK includes ways to leverage Alchemy's Simulation API, Token API, Transact API, NFT API, Webhooks and Websockets, and more across Alchemy's supported chains. Take a look at the code here.

We will use the Alchemy SDK Client to extend our Alchemy Smart Account Client using the client's alchemyEnhancedApiActions method. That way, our client will have direct access to the Enhanced APIs.

@13x54n
13x54n / GetUserNFT.md
Created May 8, 2024 01:29
Get all NFT's of user using address and alchemy sdk.

We provide several Enhanced APIs, which are especially useful for querying information about the smart accounts you create using Account Kit, such as the account's owned NFTs using the NFT API.

For the purposes of our example, we will use the NFT API to query our smart account's data by extending the Alchemy Smart Account Client with Enhanced APIs.

  1. Install the alchemy-sdk We have developed a Typescript SDK to make development with the Enhanced APIs simple. The SDK includes ways to leverage Alchemy's Simulation API, Token API, Transact API, NFT API, Webhooks and Websockets, and more across our supported chains. Take a look at the code here.

We will use the Alchemy SDK Client to extend our Alchemy Smart Account Client using the client's alchemyEnhancedApiActions method. That way, our client will have direct access to the Enhanced APIs.

To use the Alchemy SDK in our project directory, we will need to install the required package:

function toRadians(degrees) {
return degrees * (Math.PI / 180);
}
function haversine(lat1, lon1, lat2, lon2) {
// @dev Earth radius in KM, if you want the final distance in miles change into 3958.8
const R = 6371;
const dLat = toRadians(lat2 - lat1);
const dLon = toRadians(lon2 - lon1);
@13x54n
13x54n / Node-FileSystemServer.js
Created December 10, 2023 00:46 — forked from lex-world/Node-FileSystemServer.js
File Server in Node.js without DB installation.
const cluster = require("cluster");
// deepcode ignore HttpToHttps: https provided on production with NGINX
const http = require("http");
const numCPUs = require("os").cpus().length;
const process = require("process");
const statik = require("node-static");
/**
* @dev folder listener
@13x54n
13x54n / Countries.json
Created December 5, 2023 14:10
List of all countries.
[
{
"name": "Ascension Island",
"code": "AC",
"emoji": "🇦🇨",
"unicode": "U+1F1E6 U+1F1E8",
"image": "https://cdn.jsdelivr.net/npm/country-flag-emoji-json@2.0.0/dist/images/AC.svg"
},
{
"name": "Andorra",
@13x54n
13x54n / Reactnative.js
Created November 29, 2023 14:56
Image Picker and Uploader for Expo and React Native
import * as ImagePicker from "expo-image-picker";
const [image, setImage] = useState(null);
const pickImage = async () => {
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
@13x54n
13x54n / Menu.jsx
Created June 26, 2023 05:59
Solution for the task given by Chameleon.
/*
@dev Improvements:
1. Made the component more generalized by passing menuItems, name and sync props.
menuItems is an array of objects with value and label.
Name is used for backend syncing. Sync determines if selection should be synced with backend.
2. Added state to track selected value and dropdown open state.
3. Added syncing with backend using httpPatch() on selection change,
and httpGet() on initial load if sync is true.
4. Allowed selecting an option by clicking its link.
*/