Skip to content

Instantly share code, notes, and snippets.

View vlzhr's full-sized avatar

Vladimir vlzhr

View GitHub Profile
@vlzhr
vlzhr / signer-example.html
Last active December 25, 2019 23:31
Waves Signer Example Interface
<main>
<button class="js-login">Authorization</button><br><br>
<button class="js-invoke">Invoke Script</button><br>
<button class="js-data">Send Data</button>
<button class="js-transfer">Send Transfer</button>
</main>
<script src="../dist/dapp.js"></script>
document.querySelector(".js-login").addEventListener("click", async function(event) {
try {
const userData = await waves.login(); // calling Waves Signer
event.target.classList.add("clicked");
event.target.innerHTML = `
authorized as <br>
${userData.address}`; // getting account address
} catch (e) {
console.error('login rejected') // handling user auth reject
}
// calling a "faucet" script wavesexplorer.com/tesnet/address/3MuN7D8r19zdvSpAd1L91Gs88bcgwUFy2mn/script
// this will top up the account balance, but only once
document.querySelector(".js-invoke").addEventListener("click", function() {
waves.invoke({
dApp: "3MuN7D8r19zdvSpAd1L91Gs88bcgwUFy2mn",
call: {
function: "faucet"
}
}).broadcast().then(console.log)
});
@vlzhr
vlzhr / dapp.js
Last active December 26, 2019 14:31
Signer Init
import Waves from "@waves/signer";
import Provider from "@waves.exchange/provider-web";
// setting the TestNet Signer
const waves = new Waves({NODE_URL: 'https://pool.testnet.wavesnodes.com'});
// setting the Waves.Exchange provider
const provider = new Provider('https://testnet.waves.exchange/signer/');
waves.setProvider(provider);
@vlzhr
vlzhr / index.js
Last active December 26, 2019 14:32
// just putting some data into account storage
document.querySelector(".js-data").addEventListener("click", function() {
waves.data({
data: [
{key: "lastCall", value: String(new Date()), type: 'string'}
]
}).broadcast().then(console.log)
});
@vlzhr
vlzhr / index.js
Last active December 26, 2019 14:32
// just transferring some WAVES token to Alice
document.querySelector(".js-transfer").addEventListener("click", function() {
waves.transfer({
recipient: "3MuN7D8r19zdvSpAd1L91Gs88bcgwUFy2mn",
amount: 1,
attachment: base58("Happy New Year!")
}).broadcast().then(console.log)
});
import Signer from '@waves/signer';
import { ProviderSeed } from '@waves/provider-seed';
import { libs } from '@waves/waves-transactions';
const seed = libs.crypto.randomSeed(15);
const waves = new Signer({
// Specify URL of the node on Testnet
NODE_URL: 'https://pool.testnet.wavesnodes.com'
});
waves.setProvider(new ProviderSeed(seed));
@vlzhr
vlzhr / check.html
Created February 10, 2020 11:53
certificado example
<div class="main">
<h1>verify <strong>certificado</strong><br>using blockchain</h1><br>
<textarea class="data" name="data" id="" cols="30" rows="3">1 Sasha Ivanov</textarea><br>
<button style="font-size: 18px" onclick="console.log(checkData());">check certificado!</button>
<br>
<div class="result">is the certificado real?</div>
<div>check it in blockchain: <a target="_blank" style="color: blue; text-decoration: none" href="https://wavesexplorer.com/testnet/address/3N6EmqqQ1pZderX8sNMrfVuEo85ocPoqs2M/data">
https://wavesexplorer.com/testnet/address/<br>
3N6EmqqQ1pZderX8sNMrfVuEo85ocPoqs2M/data
</a></div>
@vlzhr
vlzhr / read-blockchain.js
Created February 10, 2020 12:19
Waves Keeper example
WavesKeeper.signAndPublishTransaction({
type: 12,
data: {
data: [
{ key: "string", value: "testVdfgdgf dfgdfgdfg dfg dfg al", type: "string" },
{ key: "binary", value: "base64:AbCdAbCdAbCdAbCdAbCdAbCdAbCdAbCdAbCdAbCdAbCd", type: "binary" },
{ key: "integer", value: 20, type: "integer" },
{ key: "boolean", value: false, type: "boolean" },
],
fee: {
@vlzhr
vlzhr / invoke-tx-example.js
Created March 12, 2020 21:15
Smart Contracts usage tutorial
function q(arg) { return document.querySelector(arg); }
function sendData() {
const text = q(".data").value;
let data = text.split("\n")[0];
const tx = {
type: 16, // invoke transaction
data: {
fee: {
"tokens": "0.005",