Skip to content

Instantly share code, notes, and snippets.

View elmariachi111's full-sized avatar
🦜
meow

Stefan Adolf elmariachi111

🦜
meow
View GitHub Profile
@elmariachi111
elmariachi111 / traits.js
Created February 25, 2022 11:37
create NFT traits with given probability
function generateTrait(trait_type, distributions, values) {
const sum = distributions.reduce((prv,cur) => (cur + prv), 0);
if (sum !== 10000) throw ("probabilites don't add up to 100%");
const traitRandomness = 10000 * p5.random();
let probability = 10000;
for (const i in distributions) {
probability -= distributions[i]
if (traitRandomness > probability) {
return { trait_type, value: values[i] }
}
@elmariachi111
elmariachi111 / splice_subgraph.ts
Created December 13, 2021 11:17
subgraph mapping for Splice mints
import { ERC721 as ERC721Contract } from '../generated/Splice/ERC721';
import { Bytes, ByteArray, ethereum } from '@graphprotocol/graph-ts';
import { Splice, Style } from '../generated/schema';
import { Minted, Splice as SpliceContract } from '../generated/Splice/Splice';
export function handleMinted(event: Minted): void {
const tokenId = event.params.token_id.toString();
const splice = new Splice(tokenId);
const spliceContract = SpliceContract.bind(event.address);
@elmariachi111
elmariachi111 / interactWithStroage.js
Last active October 21, 2021 14:58
Storage Interaction
const { ethers } = require("ethers");
const abi = require("./storage.abi.json");
const INFURA_KEY = "..."; //get at https://infura.io/product/ethereum
const CONTRACT_ADDRESS = "0x7DA77f8a834369dDc5e9e47407C9746Ed55C3b72";
const provider = new ethers.providers.InfuraProvider(42, INFURA_KEY);
const contract = new ethers.Contract(CONTRACT_ADDRESS, abi, provider);
(async function main() {
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8;
import '@openzeppelin/contracts/access/Ownable.sol';
contract Storage is Ownable {
uint256 number;
constructor() Ownable() {}
@elmariachi111
elmariachi111 / README.md
Created August 10, 2021 16:58
Generate a new NFT out of origin NFTs

we need a catchy name for this.

Summary

@elmariachi111
elmariachi111 / idx_ceramic.ts
Last active July 28, 2021 09:48
IPFS Samples
import CeramicClient from "@ceramicnetwork/http-client";
import { IDX } from "@ceramicstudio/idx";
import { Ed25519Provider } from "key-did-provider-ed25519";
import KeyResolver from "key-did-resolver";
import { DID } from "dids";
const seed = Buffer.from("c7943d32...d6edfcd","hex"); //32 random bytes
const did = new DID({
provider: new Ed25519Provider(seed),
resolver: KeyResolver.getResolver(),
@elmariachi111
elmariachi111 / CeMail.md
Created May 29, 2021 00:07
Web3Weekend idea: decentralized "email" on top of Ceramic Protocol / IPFS, ENS & maybe SMTP

CeMail

An SMTP compat "mail" client that uses Ceramic documents to sync & relay mail-like messages between identities. Roughly related to did-comm.

some fundamentals

The fundamental idea of a self sovereign identity is the "DID", a decentralized identifier, looking like did:key:zkmanycharacters. DIDs are uniquely identified by key material of an user, derived by some random seed only the user knows. DIDs can be resolved / expanded to DID documents that contain information about the public keys a user uses for communication and authentication purposes.

At its core, the Ceramic protocol uses DIDs to represent identities that are interacting with documents, atm did:3 and did:key are supported: https://developers.ceramic.network/learn/overview/#authentication. On top of Ceramic, IDX is adding a layer of well formed documents that contain additional information about the user, e.g. an user "profile".

@elmariachi111
elmariachi111 / Cargo.toml
Created May 21, 2021 21:20
Rust hyper http client sample
[package]
name = "testssl"
version = "0.1.0"
authors = ["Stefan Adolf <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11.3", features = ["json"] }
const inp = 'b44861ea32a51020';
console.log(inp);
const square0 = Square.fromBytes(Buffer.from(inp, 'hex'));
Square.print(square0);
const bits = Square.toBinArray(square0);
console.log(bits);
const bytes = Square.bitsToBytes(bits);
console.log(bytes.toString("hex"));
//const square1 = Square.fromBytes(randBuffer(8));