Pages:
Author

Topic: [Programmazione] Smart Contracts - page 2. (Read 20931 times)

full member
Activity: 1064
Merit: 166
October 04, 2018, 04:56:40 AM
#80
grazie makkara ...dai dei contributi davvero importanti. ma per caso sai come interfaccaire un token con un app android? vorrei creare un token rc20 e un semplice wallet app per scambiarlo

Non ne ho idea, su github potrebbe esserci qualcosa
newbie
Activity: 69
Merit: 0
October 01, 2018, 12:06:00 PM
#79
grazie makkara ...dai dei contributi davvero importanti. ma per caso sai come interfaccaire un token con un app android? vorrei creare un token rc20 e un semplice wallet app per scambiarlo
full member
Activity: 1064
Merit: 166
September 28, 2018, 07:52:38 AM
#78
Token ERC-721 o token non fungibili

A differenza dei token ERC-20, i quali non hanno differenze l’uno dall’altro, i token non fungibili hanno principalmente lo scopo di rappresentare il possesso di un un'entità con caratteristiche uniche.

Partendo da github ho trovato questa implementazione: https://github.com/m0t0k1ch1/ERC721-token-sample/tree/master/contracts che ho provveduto a modificare e semplificare per rendere più semplice la spiegazione e il funzionamento.
Avendo già illustrato in esempi precedenti come funzionano i token ERC-20 potrete notare come questi due standard condividono parte delle funzionalità.

Questa è l’interfaccia da implementare per usare lo standard ERC-721:

Code:

contract ERC721 {
    
    function totalSupply() public view returns (uint256 total);
    function balanceOf(address _owner) public view returns (uint256 balance);
    function ownerOf(uint256 _tokenId) external view returns (address owner);
    function approve(address _to, uint256 _tokenId) external;
    function transfer(address _to, uint256 _tokenId) external;
    function transferFrom(address _from, address _to, uint256 _tokenId) external;

    event Transfer(address from, address to, uint256 tokenId);
    event Approval(address owner, address approved, uint256 tokenId);
}



come potete vedere a prima vista è molto simile alla ERC-20 e, controllando in dettaglio noterete che tutte le operazioni che riguardano i token non “parlano” di quantità ma di un Id (_tokenId).



Definizione generale sulle informazioni che il token detiene e informazioni su chi li possiede:

Code:
string public constant name = "Tokenized Item";
  string public constant symbol = "NFTI";

  struct Token { // Definizione delle informazioni mantenute dal token
    address mintedBy;
    uint64 mintedAt;
    string description; /*Aggiunta allo scopo di rendere più comprensibile l’esempio, in realtà questo potrebbe essere un hash di un link IPFS o maggiori informazioni sul token senza incidere troppo sui costi derivanti dall’utilizzo delle informazioni all’interno dello smart contract*/
  }

  Token[] tokens; // Array dei token in esistenza

   //Mappature
  mapping (uint256 => address) public tokenIndexToOwner; //Token -> User
  mapping (address => uint256) ownershipTokenCount; //User -> Token
  mapping (uint256 => address) public tokenIndexToApproved; //Token -> User approvato a spendere il token

//Evento
  event Mint(address owner, uint256 tokenId, string description);

Funzioni interne sono per lo più simili a quelle di un ERC-20, gestiscono internamente le operazioni per tenere traccia di:
  • chi possiede un token
  • a chi appartiene un token
  • chi è autorizzato a spendere o muovere un token

tramite i mapping sopra citati.
Code:
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
    return tokenIndexToOwner[_tokenId] == _claimant;
  }

  function _approvedFor(address _claimant, uint256 _tokenId) internal view returns (bool) {
    return tokenIndexToApproved[_tokenId] == _claimant;
  }

  function _approve(address _to, uint256 _tokenId) internal {
    tokenIndexToApproved[_tokenId] = _to;

    Approval(tokenIndexToOwner[_tokenId], tokenIndexToApproved[_tokenId], _tokenId);
  }

  function _transfer(address _from, address _to, uint256 _tokenId) internal {
    ownershipTokenCount[_to]++;
    tokenIndexToOwner[_tokenId] = _to;

    if (_from != address(0)) {
      ownershipTokenCount[_from]--;
      delete tokenIndexToApproved[_tokenId];
    }

    Transfer(_from, _to, _tokenId);
  }


è presente una funzione _mint per creare un nuovo token e assegnarnlo all’indirizzo specificato, che in questo caso, osservando la funzione pubblica mint coincide con chi esegue il metodo mint.
Code:
 function _mint(address _owner, string description) internal returns (uint256 tokenId) {
    Token memory token = Token({
      mintedBy: _owner,
      mintedAt: uint64(now),
      description: description
    });
    tokenId = tokens.push(token) - 1;

    Mint(_owner, tokenId, description);

    _transfer(0, _owner, tokenId);
  }


Queste sono le funzioni principali per testare la creazione e visualizzare delle informazioni del token tramite Remix (https://remix.ethereum.org):
Code:
 function mint(string description) external returns (uint256) {
    return _mint(msg.sender,description);
  }

  function getToken(uint256 _tokenId) external view returns (address mintedBy, uint64 mintedAt,string description) {
    Token memory token = tokens[_tokenId];

    mintedBy = token.mintedBy;
    mintedAt = token.mintedAt;
    description = token.description;
  }


Codice completo per test su Remix:

Se avete domande o volete chiarimenti sono disponibile.

Code:
pragma solidity ^0.4.18;

contract ERC721 {
    
    function totalSupply() public view returns (uint256 total);
    function balanceOf(address _owner) public view returns (uint256 balance);
    function ownerOf(uint256 _tokenId) external view returns (address owner);
    function approve(address _to, uint256 _tokenId) external;
    function transfer(address _to, uint256 _tokenId) external;
    function transferFrom(address _from, address _to, uint256 _tokenId) external;

    event Transfer(address from, address to, uint256 tokenId);
    event Approval(address owner, address approved, uint256 tokenId);
}

contract NFTItem is ERC721 {
 
  string public constant name = "Tokenized Item";
  string public constant symbol = "NFTI";

  /*** DATA TYPES ***/

  struct Token {
    address mintedBy;
    uint64 mintedAt;
    string description;
  }

  Token[] tokens;

  mapping (uint256 => address) public tokenIndexToOwner;
  mapping (address => uint256) ownershipTokenCount;
  mapping (uint256 => address) public tokenIndexToApproved;

  event Mint(address owner, uint256 tokenId, string description);


  /*** INTERNAL FUNCTIONS ***/

  function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
    return tokenIndexToOwner[_tokenId] == _claimant;
  }

  function _approvedFor(address _claimant, uint256 _tokenId) internal view returns (bool) {
    return tokenIndexToApproved[_tokenId] == _claimant;
  }

  function _approve(address _to, uint256 _tokenId) internal {
    tokenIndexToApproved[_tokenId] = _to;

    Approval(tokenIndexToOwner[_tokenId], tokenIndexToApproved[_tokenId], _tokenId);
  }

  function _transfer(address _from, address _to, uint256 _tokenId) internal {
    ownershipTokenCount[_to]++;
    tokenIndexToOwner[_tokenId] = _to;

    if (_from != address(0)) {
      ownershipTokenCount[_from]--;
      delete tokenIndexToApproved[_tokenId];
    }

    Transfer(_from, _to, _tokenId);
  }

  function _mint(address _owner, string description) internal returns (uint256 tokenId) {
    Token memory token = Token({
      mintedBy: _owner,
      mintedAt: uint64(now),
      description: description
    });
    tokenId = tokens.push(token) - 1;

    Mint(_owner, tokenId, description);

    _transfer(0, _owner, tokenId);
  }


  /*** ERC721 IMPLEMENTATION ***/

  function totalSupply() public view returns (uint256) {
    return tokens.length;
  }

  function balanceOf(address _owner) public view returns (uint256) {
    return ownershipTokenCount[_owner];
  }

  function ownerOf(uint256 _tokenId) external view returns (address owner) {
    owner = tokenIndexToOwner[_tokenId];

    require(owner != address(0));
  }

  function approve(address _to, uint256 _tokenId) external {
    require(_owns(msg.sender, _tokenId));

    _approve(_to, _tokenId);
  }

  function transfer(address _to, uint256 _tokenId) external {
    require(_to != address(0));
    require(_to != address(this));
    require(_owns(msg.sender, _tokenId));

    _transfer(msg.sender, _to, _tokenId);
  }

  function transferFrom(address _from, address _to, uint256 _tokenId) external {
    require(_to != address(0));
    require(_to != address(this));
    require(_approvedFor(msg.sender, _tokenId));
    require(_owns(_from, _tokenId));

    _transfer(_from, _to, _tokenId);
  }

  function tokensOfOwner(address _owner) external view returns (uint256[]) {
    uint256 balance = balanceOf(_owner);

    if (balance == 0) {
      return new uint256[](0);
    } else {
      uint256[] memory result = new uint256[](balance);
      uint256 maxTokenId = totalSupply();
      uint256 idx = 0;

      uint256 tokenId;
      for (tokenId = 1; tokenId <= maxTokenId; tokenId++) {
        if (tokenIndexToOwner[tokenId] == _owner) {
          result[idx] = tokenId;
          idx++;
        }
      }
    }

    return result;
  }

  function mint(string description) external returns (uint256) {
    return _mint(msg.sender,description);
  }

  function getToken(uint256 _tokenId) external view returns (address mintedBy, uint64 mintedAt,string description) {
    Token memory token = tokens[_tokenId];

    mintedBy = token.mintedBy;
    mintedAt = token.mintedAt;
    description = token.description;
  }
}







full member
Activity: 1064
Merit: 166
September 27, 2018, 07:51:36 AM
#77
Tra qualche giorno, a grande richiesta,  arriva un nuovo e fantastico episodio sui token erc-721, completo di esempi e spiegazioni come al solito  Cool

newbie
Activity: 69
Merit: 0
July 21, 2018, 07:35:34 AM
#76
si ma se oggetto di speculazione possono scendere e salire ....quindi non soggetto a fluttuazioni
full member
Activity: 1064
Merit: 166
July 17, 2018, 12:19:02 PM
#75
Un altro soggetto che varrebbe la pena discutere o avere qualche esempio in questo thread, sarebbe qualcosa sui nuovi token non fungibili. Stavo giusto cominciando a leggere qualcosa a riguardo.

Concordo se vuoi scrivere qualche esempio, welcome  Wink io non li ho ancora guardati comunque mi interessa la cosa

sono incuriosito dai token stabili tipo eurt come fa a rimanere stabile ?


Semplicemente avranno un equivalente in € depositato da qualche parte a garanzia, tipo usdt, che poi sia vero o no non si sa. Angry
newbie
Activity: 69
Merit: 0
July 17, 2018, 04:57:46 AM
#74
sono incuriosito dai token stabili tipo eurt come fa a rimanere stabile ?
hero member
Activity: 784
Merit: 1416
July 15, 2018, 09:43:09 AM
#73
Un altro soggetto che varrebbe la pena discutere o avere qualche esempio in questo thread, sarebbe qualcosa sui nuovi token non fungibili. Stavo giusto cominciando a leggere qualcosa a riguardo.
hero member
Activity: 784
Merit: 1416
July 12, 2018, 05:46:38 AM
#72
Ottimo grazie, soluzione semplice e chiara, ora devo solo capire come è meglio impostare le cose, ma nel mio caso penso il gestore del servizio sblocca i token e l'utente li blocca.
full member
Activity: 1064
Merit: 166
July 12, 2018, 02:34:20 AM
#71
Gestire Lock & Unlock dei tokens

Partendo da qui: https://github.com/ConsenSys/Tokens/tree/master/contracts/eip20

Ho modificato il contratto per permettere di lockare i token, se noti ho messo dei commenti dove ho modificato il codice.

Ho creato una nuova variabile che contine la quantita dei token in lock:

Code:
mapping (address => uint256) public locked;

Aggiunto i controlli durante i trasferimenti per essere sicuri che ci siano abbastanza tokens disponibili per i trasferimenti, considerando l'ammontare in lock.

Aggiunti gli eventi nel momento in cui viene effettuato il lock e unlock:

Code:
   event Lock(address indexed _owner, uint256 _value);
    event Unlock(address indexed _owner, uint256 _value);

Aggiunto funzioni per effettuare lock/unlock e verificare quanti token si hanno in lock, il proprietario dei token in questo caso ha il potere di fare lock ed unlock ma è facilmente possibile cambiare il codice per permettere ad una terza parte di effettuare il solo unlock, lock o entrambi:

Code:
   function lock(uint256 _value) public returns (bool success){
        require(safeSub(balances[msg.sender], locked[msg.sender]) >= _value); // New check for token availability - Makkara
        locked[msg.sender] = _value;
        emit Lock(msg.sender, _value); // Raise event for locked tokens.
        return true;
    }
    
    function locked() public view returns (uint256 _value){
        return locked[msg.sender];
    }
    
    function unlock(uint256 _value) public returns (bool success){
        require(locked[msg.sender] >= _value);
        locked[msg.sender]-=_value;
        return true;
    }

Questo è il contratto completo pronto per l'uso. Ho fatto alcuni test e funziona, ma non posso garantire che sia esente da problemi, o possa soffrire in futuro per via di eventuali bug o exploit Smiley
Code:
// Abstract contract for the full ERC 20 Token standard
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
pragma solidity ^0.4.21;

contract SafeMath {
  function safeMul(uint256 a, uint256 b) internal returns (uint256) {
    uint256 c = a * b;
    assert(a == 0 || c / a == b);
    return c;
  }

  function safeSub(uint256 a, uint256 b) internal returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  function safeAdd(uint256 a, uint256 b) internal returns (uint256) {
    uint256 c = a + b;
    assert(c>=a && c>=b);
    return c;
  }

  function assert(bool assertion) internal {
    if (!assertion) throw;
  }
}

contract EIP20Interface {
    /* This is a slight change to the ERC20 base standard.
    function totalSupply() constant returns (uint256 supply);
    is replaced with:
    uint256 public totalSupply;
    This automatically creates a getter function for the totalSupply.
    This is moved to the base contract since public getter functions are not
    currently recognised as an implementation of the matching abstract
    function by the compiler.
    */
    /// total amount of tokens
    uint256 public totalSupply;

    /// @param _owner The address from which the balance will be retrieved
    /// @return The balance
    function balanceOf(address _owner) public view returns (uint256 balance);

    /// @notice send `_value` token to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return Whether the transfer was successful or not
    function transfer(address _to, uint256 _value) public returns (bool success);

    /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
    /// @param _from The address of the sender
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);

    /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _value The amount of tokens to be approved for transfer
    /// @return Whether the approval was successful or not
    function approve(address _spender, uint256 _value) public returns (bool success);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return Amount of remaining tokens allowed to spent
    function allowance(address _owner, address _spender) public view returns (uint256 remaining);

    /// @notice `msg.sender` locks the amount of `_value` tokens
    /// @param _value The amount of tokens to be locked
    /// @return Whether the lock was successful or not
    function lock(uint256 _value) public returns (bool success);
    
    /// @notice `msg.sender` check the amount of tokens locked
    /// @return The amount of tokens locked
    function locked() public view returns (uint256 _value);

    /// @notice `msg.sender` unlocks the amount of `_value` tokens
    /// @param _value The amount of tokens to be unlocked
    /// @return Whether the unlock was successful or not
    function unlock(uint256 _value) returns (bool success);

    // solhint-disable-next-line no-simple-event-func-name
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
    event Lock(address indexed _owner, uint256 _value);
    event Unlock(address indexed _owner, uint256 _value);
}


contract EIP20 is EIP20Interface, SafeMath {

    uint256 constant private MAX_UINT256 = 2**256 - 1;
    mapping (address => uint256) public balances;
    mapping (address => mapping (address => uint256)) public allowed;
    mapping (address => uint256) public locked;
    /*
    NOTE:
    The following variables are OPTIONAL vanities. One does not have to include them.
    They allow one to customise the token contract & in no way influences the core functionality.
    Some wallets/interfaces might not even bother to look at this information.
    */
    string public name;                   //fancy name: eg Simon Bucks
    uint8 public decimals;                //How many decimals to show.
    string public symbol;                 //An identifier: eg SBX

    function EIP20(
        uint256 _initialAmount,
        string _tokenName,
        uint8 _decimalUnits,
        string _tokenSymbol
    ) public {
        balances[msg.sender] = _initialAmount * 10 ** uint256(_decimalUnits);               // Give the creator all initial tokens
        totalSupply = _initialAmount * 10 ** uint256(_decimalUnits);                        // Update total supply
        name = _tokenName;                                   // Set the name for display purposes
        decimals = _decimalUnits;                            // Amount of decimals for display purposes
        symbol = _tokenSymbol;                               // Set the symbol for display purposes
        locked[msg.sender] = 0;  //Initialize locked tokens for the creator - Makkara
    }

    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(safeSub(balances[msg.sender], locked[msg.sender]) >= _value); // New check for token availability - Makkara
        balances[msg.sender] -= _value;
        balances[_to] += _value;
        emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        uint256 allowance = allowed[_from][msg.sender];
        require(safeSub(balances[_from], locked[_from]) >= _value && allowance >= _value);
        balances[_to] += _value;
        balances[_from] -= _value;
        if (allowance < MAX_UINT256) {
            allowed[_from][msg.sender] -= _value;
        }
        emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function balanceOf(address _owner) public view returns (uint256 balance) {
        return balances[_owner];
    }

    function approve(address _spender, uint256 _value) public returns (bool success) {
        require(safeSub(balances[msg.sender], locked[msg.sender]) >= _value); // New check for token availability - Makkara
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
        return allowed[_owner][_spender];
    }
    
    function lock(uint256 _value) public returns (bool success){
        require(safeSub(balances[msg.sender], locked[msg.sender]) >= _value); // New check for token availability - Makkara
        locked[msg.sender] = _value;
        emit Lock(msg.sender, _value); // Raise event for locked tokens.
        return true;
    }
    
    function locked() public view returns (uint256 _value){
        return locked[msg.sender];
    }
    
    function unlock(uint256 _value) public returns (bool success){
        require(locked[msg.sender] >= _value);
        locked[msg.sender]-=_value;
        emit Unlock(msg.sender, _value); // Raise event for unlocked tokens.
        return true;
    }
    
}
full member
Activity: 1064
Merit: 166
July 10, 2018, 01:29:52 AM
#70
Chiedo qui se qualcuno ha qualche idea:

Come si potrebbe sviluppare un sistema che blocca una certa quantità di token?

Mi spiego meglio: imagginiamo che per accedere ad un servizio al posto di pagare con dei token, mi venga richiesto di avere una certa quantità di token e l'obbligo di tenerli bloccati fino a che il servizio non termina. Qualche idea su come impostare gli smart contract a grandi linee?

problema interessante  Cool proverò a guardarci un pò appena ho tempo
hero member
Activity: 784
Merit: 1416
July 09, 2018, 05:25:30 PM
#69
Chiedo qui se qualcuno ha qualche idea:

Come si potrebbe sviluppare un sistema che blocca una certa quantità di token?

Mi spiego meglio: imagginiamo che per accedere ad un servizio al posto di pagare con dei token, mi venga richiesto di avere una certa quantità di token e l'obbligo di tenerli bloccati fino a che il servizio non termina. Qualche idea su come impostare gli smart contract a grandi linee?
newbie
Activity: 15
Merit: 0
June 23, 2018, 09:40:30 PM
#68
Benvenuto a bordo  Cool, se hai appena cominciato e non vuoi preoccuparti troppo dell interfaccia ti consiglio di usare semplicemente metamask e remix sulla rete ropsten, trovi i link nel primo post

Grazie!

Diciamo che mi piacciono le cose difficili, quindi ho settato tutto offline, quindi ganache, truffle, solc, web3 e ovvimente metamask per la gestione delle tx su web. Devo dire che ci è voluto un pò, però poi capito il meccanismo è relativamente semplice.
Ho fatto anche qualche test e funziona tutto, ora devo metterci le mani seriamente per un progettino un po più complesso.

Poi una volta testato "offline" devo passarlo per forza su ropsten e a quel punto è probabile che vi dia fastidio qui  Cheesy
full member
Activity: 1064
Merit: 166
June 22, 2018, 12:54:46 PM
#67
Benvenuto a bordo  Cool, se hai appena cominciato e non vuoi preoccuparti troppo dell interfaccia ti consiglio di usare semplicemente metamask e remix sulla rete ropsten, trovi i link nel primo post
newbie
Activity: 15
Merit: 0
June 21, 2018, 04:45:02 PM
#66
Ciao a tutti.

Felice di aver trovato questo topic!

Ho iniziato da poco a smanettare con gli smart contract anche io.

L'approccio è un po particolare, ma credo che basti cominciare ad entrare nell'ottica del sistema.
Ho trovato molto utili dei link trovati sotto un video di youtube.
https://www.youtube.com/watch?v=gSQXq2_j-mw

Sotto ci sono diversi link anche al repository github con tutto il materiale del video.

Comunque grazie a tutti, ho trovato in 2 minuti milioni di info utili in un unico post!
full member
Activity: 1064
Merit: 166
June 19, 2018, 07:26:13 AM
#65
devi aggiungere al tuo contratto questa funzione:

Code:
   function () payable{

        // Qui dentro poi usi msg.sender per sapere chi e' il destinatario dei token e msg.value per calcolare quanti token spedirgli


        LogReceivedFunds(msg.sender, msg.value);


    }

Una volta che dichiari questa funzione e' possibile mandare direttamente gli ETH allo smart contract (come succede per le ICO), senza il bisogno per l'utente di chiamare una funzione specifica dello smart contract.

Se invece vuoi avere una funzione chiamabile che accetta ETH devi usare:

Code:
function pay() payable
        public
        returns(bool success)
    {
        //Operazioni ...

        LogReceivedFunds(msg.sender, msg.value);
        return true;
    }

Questa e' un po' piu complicata da usare lato utente
newbie
Activity: 69
Merit: 0
June 18, 2018, 03:49:41 PM
#64
ecco perche uso la rete testnet
io non capisco come far comunicare due contratti tipo uin token e uno che redistribuisce i token automaticamente


Ti basta inserire una funzione del genere nello smart contract del tuo token, tipo nell'esempio che avevo fatto qualche posto fa per la distribuzione automatica:

Eseguibile solo dal creatore del contratto e passa i token specificati (_value) ai proprietari degli indirizzi in ingresso
Code:
function distributeToken(address[] addresses, uint256 _value) onlyOwner {
     for (uint i = 0; i < addresses.length; i++) {
         balances[owner] -= _value;
         balances[addresses[i]] += _value;
         Transfer(owner, addresses[i], _value);
     }
}

Per testarla da remix passa gli indirizzi in questo formato:

Code:
["0xindirizzo_1", "0xindirizzo_2", "0xindirizzo_3"]




se tengo un contratto già in test genero altro contratto che redistribuisce il n 100 tokenA a tutti gli indirizzi che inviano a questo contratto tpo 0.01 eth quale funzione uso?
full member
Activity: 1064
Merit: 166
June 17, 2018, 07:18:47 AM
#63
Si parla molto degli smart contract di EOS ma sembra che anche Ripple ha tirato su un bel sistema:



Qui trovate degli articoli che spiegano un po il funzionamento:

https://xrpcommunity.blog/codius-smart-contracts-done-right/

https://medium.com/coil/codius-smart-contracts-made-from-containers-b3b16c3e3890


Alcuni punti chiave:

Quote
Codius works differently than smart contracts in Bitcoin or Ethereum. The contracts run on independent hosts without an underlying blockchain, similar to traditional hosting. This allows them to interact with any service or API, scale infinitely, and read from or write to any blockchain

Quote
Another biggest difference, perhaps one of the most important, is that Codius can keep secrets while Ethereum can't. That means Codius can, for example, control a bitcoin wallet while an Ethereum smart contract can't
full member
Activity: 1064
Merit: 166
June 12, 2018, 03:18:53 PM
#62
Buongiorno,
giusto per cazzeggio volevo provare a inviare dei token B a tutti gli indirizzi che possiedono il token A. Avete spunti?  Grin
Grazie

In pratica non c'è un modo semplice per farlo, una volta che hai deciso a che blocco prendere lo snapshot, dovresti andare a vederti gli eventi Transfer lanciati dal contratto del token A.

Quindi:

Ti passi tutti gli eventi Transfer che vanno dal blocco di creazione del token al blocco dello snapshot, a mano a mano dovresti tenere il conto dei bilanci fino ad arrivare ad avere una lista completa con indirizzo - quantità di tokens.

Altrimenti passi tutti gli eventi e salvi tutti gli indirizzi che incontri, poi con web3js dovrebbe essere possibile passare come parametro il numero del blocco del tuo snapshot e verificare in quel momento il saldo token.

Buona fortuna  Wink

EDIT: Piggy aveva postato un esempio e li leggeva gli eventi:

Code:
function checkOwnershipEvents() {
                  document.getElementById("response3").innerHTML = ""
                 
                  var pf = web3.eth.contract(scAbi).at(scAddress);
                  // watch for an event with {some: 'args'}
                  var myEvent = pf.ProofOfOwnership({ some: 'args' }, { fromBlock: 0, toBlock: 'latest' });
                  // would get all past logs again.
                  var myResults = myEvent.get(function (error, logs) {
                      console.log(logs);
                      var event1;
                      for (var i = 0; i < logs.length ; i++) {
                          event1 = JSON.stringify(logs[i].args);
                          document.getElementById("response3").innerHTML += 'Proof of ownership received: ' + JSON.stringify(event1) + '
'
                      }
                  });
              }

sr. member
Activity: 292
Merit: 250
June 12, 2018, 12:19:24 PM
#61
Buongiorno,
giusto per cazzeggio volevo provare a inviare dei token B a tutti gli indirizzi che possiedono il token A. Avete spunti?  Grin
Grazie
Pages:
Jump to: