Skip to content

Instantly share code, notes, and snippets.

View vlzhr's full-sized avatar

Vladimir vlzhr

View GitHub Profile
@vlzhr
vlzhr / certificado.ride
Created March 14, 2020 22:05
simple Certificado Smart Contract on RIDE (Waves)
{-# STDLIB_VERSION 3 #-}
{-# SCRIPT_TYPE ACCOUNT #-}
{-# CONTENT_TYPE DAPP #-}
@Callable(i)
func request (name: String) = {
# verify the certificate is not in data state yet
let wasRequested = match getInteger(this, name) {
case a: Int => true
case _ => false
["a","b","c","d"].indexOf("a")
# >> 0
["a","b","c","d"].contains("a")
# >> true
[1, 2, 3, 4].min()
# >> 1
[1, 2, 3, 4].max()
@vlzhr
vlzhr / assetInfo.ride
Created May 20, 2020 15:34
Ride assetInfo example
let bitcoinId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
let x = match assetInfo(bitcoinId) {
case asset:Asset =>
asset.name # bitcoin
case _ => throw("Can't find asset")
}
dApp.widget.initWidget("<recipient>", "WAVES");
dApp.widget.initPurchase(TOTALAMOUNT);
@vlzhr
vlzhr / check.js
Created February 10, 2020 12:09
certificado example
document.addEventListener("DOMContentLoaded", function() {
document.querySelector(".data").value = location.href.split("?")[1]
.replace("%20", " ")
.replace("%20", " ");
});
@vlzhr
vlzhr / dapp-to-dapp.scala
Created May 14, 2021 09:13
Snippet for RIDE code
strict z = invoke(dapp, func, args,[AttachedPayment(unit,100000000)])
// invoke(dApp: Address|Alias, function: String, arguments: List[Any], payments: List[AttachedPayments]): Any
@vlzhr
vlzhr / stricts-variables.scala
Created May 14, 2021 09:17
RIDE code snippet
func foo() = {
...
strict balanceBefore = wavesBalance(this).regular
strict z = invoke(dapp2,bar,args,[AttachedPayment(unit,100000000)])
strict balanceAfter = wavesBalance(this).regular
if(balanceAfter < balanceBefore) then ... else...
}
@vlzhr
vlzhr / index.js
Created February 10, 2020 12:21
certificado example
function sendData() {
const text = document.querySelector(".data").value;
let data = text.split("\n");
data = data.map(function(x) { return {"key": x.split(" ")[0], "value": x, "type": "string"}} );
const tx = {
type: 12, // data transaction
data: {
data: data,
fee: {
"tokens": "0.001",
# use this JSON to swap EGGs with ledger
# replace "amount": 100, with your amount of EGGlets (1 EGG = 100, 1.01 EGG = 101)
{
"type": 16,
"version": 2,
"dApp": "3PJQUUiJdvz9etUKED9ju7o7VrcNMtnkXBU",
"call": {
"args": [],
"function": "swapEgg"
// to invoke puzzle swap you will need to broadcast this transaction
// TODO: replace poolAddress (for example "3PPRHHF9JKvDLkAc3aHD3Kd5tRZp1CoqAJa")
// TODO: replace assetInId and assetOutId (for example "4kwKSf4Bx2Wq8YxKnVZBhcEHyXzEtJ2pw7ixfJgirwf2" and "54UszKAj3MtYmkdRCqSXAcaQLaVALBy7CCrVkfmfzhxR")
// TODO: set minToReceive if you want to avoid slippage risk
.invoke({
dApp: "poolAddress",
fee: 500000,
payment: {
assetId: "assetInId",