Skip to content

Instantly share code, notes, and snippets.

View asbjornenge's full-sized avatar
Swinging madly across the sun.

Asbjorn Enge asbjornenge

Swinging madly across the sun.
View GitHub Profile
@asbjornenge
asbjornenge / index.js
Created August 3, 2022 09:46
ChainBorn Index Example
import { TzKTAPI, TzKTEvents } from '@asbjornenge/tzkt-api'
import ohash from 'object-hash'
import {
TZKT_API,
CHAINBORN_DATASTORE
} from './config.js'
import { getClient } from './utils.js'
import './sentry.js'
const api = new TzKTAPI({ BASE: TZKT_API })
@asbjornenge
asbjornenge / summon_hero.js
Created August 3, 2022 09:19
ChainBorn Summon Hero
export async function summonHero({ dappAddress, walletAddress, tokenAddress, tokenId, name, cost }) {
const tokenContract = await Tezos.wallet.at(tokenAddress)
const dappContract = await Tezos.wallet.at(dappAddress)
const batchOp = await Tezos.wallet.batch([
{
kind: OpKind.TRANSACTION,
...tokenContract.methods.update_operators([
{
add_operator: {
@asbjornenge
asbjornenge / wallet.js
Last active August 3, 2022 09:09
ChainBorn Wallet Connection
import { TezosToolkit } from '@taquito/taquito'
import { BeaconWallet } from '@taquito/beacon-wallet'
const Tezos = new TezosToolkit()
const wallet = new BeaconWallet({ name: "ChainBorn" })
Tezos.setWalletProvider(wallet)
export async function setProvider(rpc) {
Tezos.setProvider({ rpc: rpc})
}
@asbjornenge
asbjornenge / compile.py
Created August 3, 2022 07:58
ChainBorn Compilation file
import smartpy as sp
import json
import os
from datetime import datetime, timezone
env = os.environ
cwd = os.getcwd()
Data = sp.io.import_script_from_url("file://%s/datastore.py" % cwd)
Game = sp.io.import_script_from_url("file://%s/controller.py" % cwd)
@asbjornenge
asbjornenge / test.py
Created August 3, 2022 07:26
ChainBorn Tests
import smartpy as sp
import os
cwd = os.getcwd()
Game = sp.io.import_script_from_url("file://%s/controller.py" % cwd)
Data = sp.io.import_script_from_url("file://%s/datastore.py" % cwd)
Types = sp.io.import_script_from_url("file://%s/types.py" % cwd)
Tokens = sp.io.import_script_from_url("file://%s/tokens.py" % cwd)
Randomizer = sp.io.import_script_from_url("https://ipfs.infura.io/ipfs/QmPNkabMCpDmFE6GynfS9UAoQDLE6PyCLpRJQmceEp2oTv")
@asbjornenge
asbjornenge / controller.py
Created August 2, 2022 19:06
ChainBorn Game Controller
import smartpy as sp
import os
cwd = os.getcwd()
Types = sp.io.import_script_from_url("file://%s/types.py" % cwd)
class ChainBornGame(sp.Contract):
def __init__(
self,
admins,
@asbjornenge
asbjornenge / datastore.py
Last active August 2, 2022 15:55
ChainBorn Datastore
import smartpy as sp
import os
cwd = os.getcwd()
Types = sp.io.import_script_from_url("file://%s/types.py" % cwd)
class ChainBornDatastore(sp.Contract):
def __init__(
self,
admins,
@asbjornenge
asbjornenge / types.py
Created August 2, 2022 12:31
ChainBorn Types Example
import smartpy as sp
## Config
#
TGameConfig = sp.TRecord(
paused=sp.TBool,
summon_cost=sp.TMutez,
minimum_loot=sp.TMutez,
hero_health_initial=sp.TNat,
@asbjornenge
asbjornenge / init-env.sh
Created August 2, 2022 12:18
Init SmartPy virtualenv
#!/bin/bash
rm -Rf bin pyvenv.cfg
wget https://smartpy.io/cli/install.sh
chmod +x install.sh
./install.sh --prefix bin
rm install.sh
virtualenv .
cd bin && ln -sf SmartPy.sh spy && cd ..
Parameter Weight
1x Unverified proof 1
1x Verified proof 4
👆 prior to announcement +2