Skip to content

Instantly share code, notes, and snippets.

View cgcardona's full-sized avatar
💭
🤖

Gabriel Cardona cgcardona

💭
🤖
View GitHub Profile
@cgcardona
cgcardona / stringify-cchain-atomic-tx.ts
Last active October 13, 2022 14:43
This script first fetches the hex of a C-Chain atomic transaction. From that hex it creates a `Buffer` & then it creates an empty C-Chain `Tx` & populates it via passing in the `Buffer` to `tx.fromBuffer`. Next it calls `JSON.stringify` on the `Tx` to encode it as a JSON string. Lastly it takes the JSON string & convert it to an actual JSON object.
import { Avalanche, Buffer } from "avalanche"
import { EVMAPI, Tx } from "avalanche/dist/apis/evm"
const ip: string = "api.avax.network"
const port: number = 443
const protocol: string = "https"
const networkID: number = 1
const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID)
const cchain: EVMAPI = avalanche.CChain()

Introduction To Avalanche

Introduction

We're going to go ahead and get started. My name is Gabriel Cardona. I'm Developer Evangelist at Ava Labs. Today's presentation is going to be a high level introduction to the Avalanche Network followed by demo. We're going to talk about a few of the unique attributes of the Avalanche network which are Avalanche Consensus, Subnets and Virtual Machines and then I'll show how to deploy a local test network for development.

What is Avalanche?

Ok, that's out of the way. Now let's dig in and talk about what is Avalanche? Avalanche is a global financial network for the issuing and trading of all digital goods. We enable potentially millions of validators to process thousands of transactions per second with near instant finality using a protocol which is completely green and quiescent. We've paired this high throughput and fast finality protocol w/ an architecture that can meet the needs of unique financial services and decentralized apps.

cd /path/to/avalanche/network/runner
go run examples/local/fivenodenetwork/main.go
[08-17|16:41:43.413] INFO local/network.go:381 creating network with 5 nodes
[08-17|16:41:43.420] INFO local/network.go:503 adding node "node1" with tmp dir at /var/folders/3_/w0k88x3139g0gdxsrnp497zr0000gn/T/network-runner-root-data_20220817_164143/node1, logs at /var/folders/3_/w0k88x3139g0gdxsrnp497zr0000gn/T/network-runner-root-data_20220817_164143/node1/logs, DB at /var/folders/3_/w0k88x3139g0gdxsrnp497zr0000gn/T/network-runner-root-data_20220817_164143/node1/db, P2P port 45133, API port 9650
[08-17|16:41:43.423] INFO local/network.go:503 adding node "node2" with tmp dir at /var/folders/3_/w0k88x3139g0gdxsrnp497zr0000gn/T/network-runner-root-data_20220817_164143/node2, logs at /var/folders/3_/w0k88x3139g0gdxsrnp497zr0000gn/T/network-runner-root-data_20220817_164143/node2/logs, DB at /var/folders/3_/w0k88x3139g0gdxsrnp497zr0000gn/T/network-runner-root-data_20220817_164143/node2/db, P2P port 65002, API port 9652
[08-1
{
"img": "https://i.imgur.com/r0G3SQq.png",
"name": "Web3 Tech Stack"
}
@cgcardona
cgcardona / import.ts
Created August 3, 2022 21:59
Import AVAX to the X-Chain from the C-Chain
import { Avalanche, BN, Buffer } from "../../src"
import {
AVMAPI,
KeyChain,
UTXOSet,
UnsignedTx,
Tx
} from "../../src/apis/avm"
import { GetUTXOsResponse } from "../../src/apis/avm/interfaces"
import {
@cgcardona
cgcardona / import.go
Created August 3, 2022 21:55
Import AVAX to the X-Chain from the C-Chain
package main
import (
"encoding/hex"
"errors"
"fmt"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/cb58"
"github.com/ava-labs/avalanchego/utils/crypto"
@cgcardona
cgcardona / export.ts
Created August 3, 2022 21:54
Export AVAX from C-Chain to X-Chain
import { Avalanche, BN } from "../../src"
import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm"
import {
EVMAPI,
KeyChain as EVMKeyChain,
UnsignedTx,
Tx
} from "../../src/apis/evm"
import {
PrivateKeyPrefix,

Introduction To Avalanche

Introduction

We're going to go ahead and get started. My name is Gabriel Cardona. I'm Developer Evangelist at Ava Labs. You'll have to forgive my absense. I was scheduled to give this presentation in person but early this week I had to have an emergency root canal and it prevented me from traveling to Austin. The moral of the story is to take care of your teeth my friends.

Today's presentation is going to be a high level introduction to the Avalanche Network. We're going to talk about who we are at Ava Labs and what we've been building over the last couple of years. We're going to dig into a few of the unique attributes of the Avalanche network which are Avalanche Consensus, Subnets and Virtual Machines.

Who is Ava Labs?

@cgcardona
cgcardona / addressFromBuffer.ts
Created May 21, 2022 04:10
Example encoding an address Buffer into Bech32
import { Avalanche, Buffer } from "../../src"
import { AVMAPI } from "../../src/apis/avm"
import {
UTXOSet,
UTXO
} from "../../src/apis/platformvm"
import { Output } from "../../src/common"
const ip: string = "localhost"
const port: number = 9650
const protocol: string = "http"
@cgcardona
cgcardona / step3.ts
Last active May 7, 2022 21:53
This script correctly consumes and signs the 1-of-2 output from step1. It also creates an AVAX UTXO which is a 1-of-2 multisig with keypairs A and B. Lastly it instantiates a virtual machine as a blockchain on a subnet by correctly signing the 2-of-3 Subnet Auth.
import {
Avalanche,
BinTools,
BN,
Buffer,
GenesisAsset,
GenesisData
} from "avalanche"
import { InitialStates } from "avalanche/dist/apis/avm"
import {