Skip to content

Instantly share code, notes, and snippets.

@caike
caike / script.tsx
Last active May 31, 2023 12:40
Lucid and CIP-68
View script.tsx
import type { NextPage } from 'next'
import Head from 'next/head'
import WalletConnect from '../components/WalletConnect'
import { useStoreActions, useStoreState } from "../utils/store"
import Link from 'next/link'
import { useState, useEffect } from 'react'
import { getAssets } from "../utils/cardano";
import NftGrid from "../components/NftGrid";
import initLucid from '../utils/lucid'
import { Lucid, Credential, TxHash, Lovelace, Constr, SpendingValidator, Data, fromText, Unit, MintingPolicy, PolicyId, Address, UTxO, applyParamsToScript, Assets, ScriptHash, Redeemer, paymentCredentialOf, KeyHash, generatePrivateKey, getAddressDetails, toUnit } from 'lucid-cardano'
View seed-to-keys.md

From seed phrase to keys:

cat recovery_phrase.txt | cardano-wallet key from-recovery-phrase Shelley > root.prv

cat root.prv | cardano-address key inspect

cardano-wallet key child 1852H/1815H/0H/0/0 < root.prv > payment.prv

cardano-cli key convert-cardano-address-key --shelley-payment-key
@caike
caike / calculate.sh
Created April 15, 2023 14:13
Script for calculating time left for current Cardano epoch
View calculate.sh
#!/bin/bash
getEpoch(){
CCLI=$(which cardano-cli)
"$CCLI" query tip --mainnet | sed -n '3 p'| sed 's/[^0-9]*//g'
}
# Description : Calculation of days, hours, minutes and seconds from time in seconds
timeLeft() {
local T=$1
@caike
caike / run.exs
Created March 29, 2023 13:28
Elixir Protocols in Practice
View run.exs
##########################################
# Example of using Protocols in Elixir
#
# cat .tool-versions
# elixir 1.14.3
# erlang 24.3.4
#
# Run via: elixir run.exs
#
############################
@caike
caike / validator.hs
Created December 16, 2022 20:12
Plutus Pioneers Week03 Homework
View validator.hs
{-# INLINABLE mkValidator #-}
-- This should validate if either beneficiary1 has signed the transaction and the current slot is before or at the deadline
-- or if beneficiary2 has signed the transaction and the deadline has passed.
mkValidator :: VestingDatum -> () -> ScriptContext -> Bool
mkValidator datum _ sc = traceIfFalse "cannot grab" (beneficiary1Grab || beneficiary2Grab)
where
info :: TxInfo
info = scriptContextTxInfo sc
beneficiary1Grab :: Bool
@caike
caike / file.sh
Last active November 30, 2022 23:52
Addresses and Keys for Smart Contract demo
View file.sh
cardano-cli address key-gen --verification-key-file 02.vkey --signing-key-file 02.skey
cardano-cli address build \
--payment-verification-key-file 02.vkey \
--out-file 02.addr --testnet-magic 2
# Optional for debugging
## generates key files for staking address
cardano-cli stake-address key-gen \
--verification-key-file 01-stake.vkey \
--signing-key-file 01-stake.skey
@caike
caike / m1.md
Created November 10, 2022 19:19
asdf erlang elixir m1
View m1.md
export KERL_CONFIGURE_OPTIONS="--disable-hipe --with-ssl=$(brew --prefix openssl@1.1)"
asdf install erlang 22.3.4.26
@caike
caike / 01.Dockerfile
Last active August 10, 2021 14:38
Learn the differences between ENVs and ARGs in Docker
View 01.Dockerfile
FROM alpine:latest
# 01- ENV set directly in Dockerfile.
# Available during BUILDTIME and RUNTIME.
ENV LOCAL_ENV="hi I am LOCAL_ENV"
RUN echo $LOCAL_ENV
# 02 - ARG sent via command (docker or docker-compose)
# Available during BUILDTIME only.
ARG BUILDTIME_ENV
@caike
caike / migration.exs
Last active July 5, 2021 15:57
snippets para o blog post sobre mix task
View migration.exs
defmodule GuitarStore.Repo.Migrations.AddIsCustomShopToGuitars do
use Ecto.Migration
def change do
alter table("guitars") do
add :is_custom_shop, :boolean, default: false
end
create index("guitars", ["is_custom_shop"])
end
@caike
caike / agent.config.json
Created June 1, 2021 12:05
AWS CloudWatch agent simple config for CPU and memory monitoring
View agent.config.json
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"append_dimensions": {
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"