Skip to content

Instantly share code, notes, and snippets.

View vgrichina's full-sized avatar

Vladimir Grichina vgrichina

View GitHub Profile
async function deploy(options) {
const configPath = process.cwd() + '/src/config';
const config = require(configPath)(process.env.NODE_ENV || 'development');
const near = await nearlib.connect({...config, deps: { keyStore: new UnencryptedFileSystemKeyStore('./neardev') } });
const contractData = [...fs.readFileSync(options.wasmFile)];
const account = await near.account(options.accountId);
await account.signAndSendTransaction(options.accountId, [
deployContract(contractData),
// TODO: Use whatever actual params need to be for functionCall or include any other actions as well
[I] ➜ yarn start
yarn run v1.21.1
warning package.json: No license field
$ npm run build && near deploy --wasmFile ./contract/res/status_message.wasm
npm WARN lifecycle The node binary used for scripts is /var/folders/3c/zjk2krns25s75x_z2_wdvgg80000gn/T/yarn--1580160108615-0.8711654915114355/node but npm is using /Users/vg/n/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> [email protected] build /Users/vg/Documents/create-near-app/blank-rust-proj-vg
> cd contract && ./build.sh
Updating crates.io index
@vgrichina
vgrichina / explorer-sqlite.js
Last active December 3, 2021 17:29
NEAR Explorer SQLite cheatsheet
sqlite3 = require('sqlite3')
db = new sqlite3.Database('db/testnet-database.sqlite')
db.all(`select name from sqlite_master where type='table'`, console.log)
db.all(`select * from transactions where actions like '%deploy%' limit 10`, console.log)
db.all(`select count(*) from transactions where actions like '%deploy%' limit 10`, console.log)
@vgrichina
vgrichina / load-test.js
Last active September 13, 2019 23:12
load testing nearcore payments
const nearlib = require('nearlib');
const { signTransaction, transfer } = nearlib.transactions;
const { base_decode } = nearlib.utils.serialize;
const sleep = (ms) => new Promise((resolved) => setTimeout(resolved, ms));
(async () => {
const [,, accountId, txCount] = process.argv;
const near = await nearlib.connect({...require('near-shell/get-config')(), deps: { keyStore: new nearlib.keyStores.UnencryptedFileSystemKeyStore('./neardev') } });
@vgrichina
vgrichina / callback.js
Last active July 12, 2019 00:31
Spin up temporary webserver to handle callback from browser
const http = require('http');
const url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
try {
@vgrichina
vgrichina / generated_bindings.ts
Last active October 16, 2023 13:24
Sample generated AssemblyScript BSON bindings
import "allocator/arena";
// TODO: Why cannot import from index?
// import { BSONEncoder, BSONDecoder } from "../../../assemblyscript-bson/assembly";
import { BSONEncoder } from "../../../assemblyscript-bson/assembly/encoder";
import { BSONDecoder } from "../../../assemblyscript-bson/assembly/decoder";
declare function sayHello(): void;
export class FooBar {
foo: i32 = 0;
@vgrichina
vgrichina / booking.ts
Last active November 28, 2018 23:40
Booking train and hotel
book_train_and_hotel() : void { // Needs 6 MANA.
// 3 for train and callback and 3 for hotel and callback.
// E.g. book_train and book_hotel doesn't need additional mana, so only 1 MANA for a call.
// Callback may need 1 additional to cancel train or hotel booking if one of them failed.
assert_has_mana(6);
let hotelBooking = bookHotel.withMana(3).withCoins(1000).book(sender());
let trainBooking = bookTrain.withMana(3).withCoins(1000).book(sender());
data Rope = Empty | Concat Int Rope Rope | Leaf String deriving (Show, Eq)
rope :: String -> Rope
rope "" = Empty
rope s = Leaf s
len :: Rope -> Int
len Empty = 0
len (Leaf s) = length s
len (Concat length _ _) = length
/**
* CSV Parser. Takes a string as input and returns
* an array of arrays (for each row).
*
* @param input String, CSV input
* @param separator String, single character used to separate fields.
* Defaults to ","
* @param quote String, single character used to quote non-simple fields.
* Defaults to "\"".
*/
import string
class Solution:
# @param start, a string
# @param end, a string
# @param dict, a set of string
# @return an integer
def ladderLength(self, start, end, dict):
dict += [end]