Les + populaires

BTC ETH SOL XRP BNB USDC USDT

Suivez-nous

Lancer des pièces sur Algorand

IAavec
Titres Titres
Photo de ZSun Fu sur Unsplash
  • Comment puis-je me connecter à un nœud blockchain ?
  • Comment puis-je signer et envoyer des transactions ?
  • Quels outils et bibliothèques sont disponibles ?
Regles du jeu
  • Pour jouer, vous devez payer une certaine quantité d’Algos.
  • Ensuite, vous devez choisir entre la tête ou la queue.
  • La pièce est retournée.
  • Si vous gagnez, vous recevrez des Algos, si vous perdez, nous sommes amis comme avant.
  1. Comprendre le fonctionnement d’une transaction de paiement sur Algorand.
  2. Quelle source fiable de hasard utiliser.

Paiements avec Algorand SDK

  1. un compte Algorand avec une phrase de départ mnémonique et, bien sûr, quelques Algos
  2. un moyen de connecter une application cliente au réseau Algorand.
import algosdk from "algosdk";
const myaccount = algosdk.generateAccount();
console.log("Account Address = " + myaccount.addr);
let account_mnemonic = algosdk.secretKeyToMnemonic(myaccount.sk);
console.log("Account Mnemonic = " + account_mnemonic);
const myAccount = algosdk.mnemonicToSecretKey(“MNEMONIC HERE”);

Client d’Algod

const algodClient = new algosdk.Algodv2(
{
'X-API-Key': “API KEY HERE”
},
“API ENDPOINT HERE”,
""
);

Envoyer une opération de paiement

let params = await algodClient.getTransactionParams().do();
const enc = new TextEncoder();
let note = enc.encode("Win Flip Coin Game");
let txn = algosdk.makePaymentTxnWithSuggestedParams(myAccount.addr, “RECEIVER ADDRESS HERE”, 200000, undefined, note, params);
let signedTxn = txn.signTxn(myAccount.sk);
let txIdResult = txn.txID().toString();
console.log("Signed transaction with txID: %s", txIdResult);
let tx = await algodClient.sendRawTransaction(signedTxn).do();

Intégration de portefeuille : comment signer des transactions

import MyAlgoConnect from '@randlabs/myalgo-connect'
private myAlgoConnect = new MyAlgoConnect();
let accounts = await this.myAlgoConnect.connect({
shouldSelectOneAccount: true,
openManager: false
}
);
const txn = … //make a transaction as seen before with algosdk
…
const sigTxn = await this.myAlgoConnect.signTransaction(txn.toByte());
…
// send the transaction as seen before with an Algod client
  • Paiement du jeu
  • Tirage au sort
  • Vérification des gains
Déroulement du jeu

Paiement du jeu

Coin Flip

function flip(hash) {
var a = 1, c = 0, h, o;
if (hash) {
a = 0;
for (h = hash.length - 1; h >= 0; h--) {
o = hash.charCodeAt(h);
a = (a << 6 & 268435455) + o + (o << 14);
c = a & 266338304;
a = c !== 0 ? a ^ c >> 21 : a;
}
}
var result = a % 2;
return result;
}

Vérification des gains

Source https://medium.com/coinmonks/flipping-coins-on-algorand-fa3d17e0664f?source=rss—-721b17443fd5—4

Investissez pour votre avenir
Linxea
50€ offerts à l'inscription

Donnez votre avis

Soyez le 1er à noter cet article


Partagez cet article maintenant !

Envoyez simplement nos contenus crypto et finance à vos proches.