Pages:
Author

Topic: [Programmazione] Smart Contracts (Read 20933 times)

sr. member
Activity: 1337
Merit: 288
0xbt
November 05, 2019, 04:10:15 PM
Grazie makkara, ma questa è comunque una soluzione leggermente diversa.
Voglio provare a finire:
https://bitcointalksearch.org/topic/how-to-make-a-crypto-testament-5052754
Smart contract per il calcolo dell'indirizzo del contratto:
Code:
pragma solidity 0.4.18;
contract Balls {
    function addressFrom(address _origin, uint _nonce) public pure returns (address) {
        if(_nonce == 0x00)     return address(keccak256(byte(0xd6), byte(0x94), _origin, byte(0x80)));
        if(_nonce <= 0x7f)     return address(keccak256(byte(0xd6), byte(0x94), _origin, byte(_nonce)));
        if(_nonce <= 0xff)     return address(keccak256(byte(0xd7), byte(0x94), _origin, byte(0x81), uint8(_nonce)));
        if(_nonce <= 0xffff)   return address(keccak256(byte(0xd8), byte(0x94), _origin, byte(0x82), uint16(_nonce)));
        if(_nonce <= 0xffffff) return address(keccak256(byte(0xd9), byte(0x94), _origin, byte(0x83), uint24(_nonce)));
        return address(keccak256(byte(0xda), byte(0x94), _origin, byte(0x84), uint32(_nonce))); // more than 2^32 nonces not realistic
    }    
}
;-)))
https://rinkeby.etherscan.io/address/0x156e6451d6d1cf1a3cb3be03b229b71e58ce2774#readContract
full member
Activity: 1064
Merit: 166
October 28, 2019, 04:43:10 AM
#99
Ciao.
Come scrivere un semplice contratto intelligente come 'Hello World', ma in modo che possa essere creato solo da un indirizzo specifico?
Cioè, sarà impossibile distribuirlo da un altro indirizzo.
Dovrei in qualche modo scrivere l'indirizzo nel smart contract?
Grazie.

Dovresti creare uno smart contract "padre" in grado di fare il deploy di smart contract "figli", non ho provato ma a quanto pare si può fare.

Code:
function newPurchase()
public
payable
returns(address newContract)
{
Purchase c = (new Purchase).value(msg.value)(address(msg.sender));
contracts.push(c);
lastContractAddress = address(c);
emit newPurchaseContract(c);
return c;
}

https://github.com/jacksonng77/StartEscrow/blob/master/Solidity/StartEscrow.sol

Il tuo SC padre sarà customizzabile e potrai decidere a quale indirizzo permettere di fare il deploy di un certo SC figlio

Qui c'è un esempio per qualcosa di simile
https://medium.com/coinmonks/creating-smart-contracts-with-smart-contract-d54e21d26e00
sr. member
Activity: 1337
Merit: 288
0xbt
October 25, 2019, 01:23:23 PM
#98
Ciao.
Come scrivere un semplice contratto intelligente come 'Hello World', ma in modo che possa essere creato solo da un indirizzo specifico?
Cioè, sarà impossibile distribuirlo da un altro indirizzo.
Dovrei in qualche modo scrivere l'indirizzo nel smart contract?
Grazie.
full member
Activity: 1064
Merit: 166
June 05, 2019, 03:26:27 PM
#97
Ciao.
Trovato un argomento interessante:

"Vyper"

"Vyper" è un linguaggio di sviluppo smart contract.
Documentazione:
https://vyper.readthedocs.io/en/v0.1.0-beta.10/index.html
GitHub:
https://github.com/ethereum/vyper
Online compiler:
https://vyper.online
https://etherscan.io/vyper
https://rinkeby.etherscan.io/vyper
Vasto link GitHub alle risorse Vyper:
https://github.com/ethereum/vyper/wiki/Vyper-tools-and-resources

Ad esempio, su Smart Contracts vyper, lo scambio di Uniswap funziona.

Qualcuno ha studiato questa zona?


Non lo conosco, è da un pò che non metto mano agli smart contract. A prima vista sembra una figata. Magari faccio qualche prova per vedere come funziona.
sr. member
Activity: 1337
Merit: 288
0xbt
June 03, 2019, 06:40:51 PM
#96
Ciao.
Trovato un argomento interessante:

"Vyper"

"Vyper" è un linguaggio di sviluppo smart contract.
Documentazione:
https://vyper.readthedocs.io/en/v0.1.0-beta.10/index.html
GitHub:
https://github.com/ethereum/vyper
Online compiler:
https://vyper.online
https://etherscan.io/vyper
https://rinkeby.etherscan.io/vyper
Vasto link GitHub alle risorse Vyper:
https://github.com/ethereum/vyper/wiki/Vyper-tools-and-resources

Ad esempio, su Smart Contracts vyper, lo scambio di Uniswap funziona.

Qualcuno ha studiato questa zona?
sr. member
Activity: 1337
Merit: 288
0xbt
January 26, 2019, 11:35:22 AM
#95
Da tempo desideravo aggiungere una funzione interessante a un contratto di token. Ho cercato di capire funzioni simili nei contratti ED e TS. Grazie, Google ha trovato questo argomento. Grazie a Makkara per avermi aiutato a capire queste funzioni, grazie alle quali sono riuscito a creare la funzione utile desiderata.
full member
Activity: 1064
Merit: 166
January 25, 2019, 09:29:10 AM
#94
Code:
function withdrawToken_to(address token, address _to, uint amount) public payable{
    if (token==0) throw;
    if (tokens[token][msg.sender] < amount) throw;
    tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount);
    if (!Token(token).transfer(_to, amount)) throw;
    Withdraw(token, _to, amount, tokens[token][msg.sender]);
  }

Tutto è andato, grazie.

Ma non riesco a capire cosa sia e cosa fare al riguardo?
Che cosa fa questa funzione e come usarla?



quello serve per tenere conto dei token presenti nel contratto e chi è il proprietario, gli passi l'indirizzo token e indirizzo personale e ti ritorna il totale.

Code:
mapping (address => mapping (address => uint)) public tokens; //questo mappa un indirizzo di un token con un la mappatura di un indirizzo di un proprietario e la quantità di quei tokens
sr. member
Activity: 1337
Merit: 288
0xbt
January 24, 2019, 07:19:50 PM
#93
Code:
function withdrawToken_to(address token, address _to, uint amount) public payable{
    if (token==0) throw;
    if (tokens[token][msg.sender] < amount) throw;
    tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount);
    if (!Token(token).transfer(_to, amount)) throw;
    Withdraw(token, _to, amount, tokens[token][msg.sender]);
  }

Tutto è andato, grazie.

Ma non riesco a capire cosa sia e cosa fare al riguardo?
Che cosa fa questa funzione e come usarla?

sr. member
Activity: 1337
Merit: 288
0xbt
January 23, 2019, 06:48:51 PM
#92
Code:
if (!Token(token).transfer(_to, amount)) throw;
Code:
function withdrawToken_to(address token, address _to, uint amount) public payable{
    if (token==0) throw;
    if (tokens[token][msg.sender] < amount) throw;
    tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount);
    if (!Token(token).transfer(_to, amount)) throw;
    Withdraw(token, _to, amount, tokens[token][msg.sender]);
  }

Ieri ho provato a fare qualcosa di simile.

Comunque è importante ricordarsi di aver dato l'approvazione allo smart contract di spendere i token, chiamando il metodo approve direttamente dal contratto del token.

Apparentemente me ne sono dimenticato. Domani farò dei test.
Grazie.
Mi scuso per la traduzione scadente.
full member
Activity: 1064
Merit: 166
January 23, 2019, 06:17:08 PM
#91
Non l'ho provato ma dovrebbe funzionare. Basta semplicemente sostituire il proprio indirizzo in questa parte sotto

Code:
if (!Token(token).transfer(msg.sender, amount)) throw;

con l'indirizzo a cui vogiamo mandare i token:

Code:
if (!Token(token).transfer(_to, amount)) throw;

Code:
function withdrawToken_to(address token, address _to, uint amount) public payable{
    if (token==0) throw;
    if (tokens[token][msg.sender] < amount) throw;
    tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount);
    if (!Token(token).transfer(_to, amount)) throw;
    Withdraw(token, _to, amount, tokens[token][msg.sender]);
  }


Appena ho un pò di tempo verifico se è corretto. Comunque è importante ricordarsi di aver dato l'approvazione allo smart contract di spendere i token, chiamando il metodo approve direttamente dal contratto del token.
sr. member
Activity: 1337
Merit: 288
0xbt
January 23, 2019, 03:00:59 PM
#90
Come gestire token in uno smart contract:

Code:
function prelievoToken(address token, uint amount) public payable{
    if (token==0) throw;
    if (tokens[token][msg.sender] < amount) throw;
    tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount);
    if (!Token(token).transfer(msg.sender, amount)) throw;
    Withdraw(token, msg.sender, amount, tokens[token][msg.sender]);
  }

Ciao, come aggiungere la seguente funzione a questo smart contract:

Code:
function withdrawToken_to(address _token, address _to, uint _amount)

full member
Activity: 1064
Merit: 166
November 12, 2018, 01:23:33 AM
#89
Se hai qualche informazione base o link che spiegano qualcisa in generale e come pubblicarli e interagire. Potrebbe essere utile come alternativa.
Se parli di waves ho riportato i link che ho trovato utili. Sono molto lento ad approfondire e alla fine mi perdo. ....

Penso di aver bevuto un pò troppo ieri, pensavo fosse un esempio  8. Poi riporto nel primo post i link.

È uscito cryptozombie season 2

https://medium.com/loom-network/cryptozombies-season-2-is-here-and-introducing-zombie-battleground-custom-game-modes-f1f09efa24f4
legendary
Activity: 2506
Merit: 1120
November 11, 2018, 07:21:29 AM
#88
Se hai qualche informazione base o link che spiegano qualcisa in generale e come pubblicarli e interagire. Potrebbe essere utile come alternativa.
Se parli di waves ho riportato i link che ho trovato utili. Sono molto lento ad approfondire e alla fine mi perdo. ....
full member
Activity: 1064
Merit: 166
November 11, 2018, 02:11:56 AM
#87
Se hai qualche informazione base o link che spiegano qualcisa in generale e come pubblicarli e interagire. Potrebbe essere utile come alternativa.
legendary
Activity: 2506
Merit: 1120
November 10, 2018, 07:12:29 PM
#86
Cercano un programmatore smart contract waves,
https://bitcointalksearch.org/topic/in-cerca-di-persone-in-grado-di-sviluppare-soluzioni-smart-contract-su-waves-5066539
non sapevo esistessero e ho iniziato a guardare ...
Vi copio/incollo gli appunti che ho preso ...

Code:
Smart contract (waves - appunti sparsi)
    white paper
    video esempio
    documentazione
        Associ uno scrip ad un account
        Le transazioni sono valide se lo script approva
            Firme e altri dati
            proofs
                ?
            Numero blocchi della catena
            dati presenti nella catena, oracoli
                Inseriti con DataTransaction
            Gli script possono essere sostituiti o annullati associandone uno nuovo
                A meno che lo script precedente non lo vieti
            Default script di un account
                sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPk)
           
        Costo script
            Dipendono dalla complessità
            max 8kByte
            minimo: 0.004 WAVES
            Costi minimi (non script)
        Esempi
            Vedi documentazione
                Account scambia solo BTC
                    let cooperPubKey = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'
                    let BTCId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
                    match tx {
                        case o: Order =>
                            sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey ) && (o.assetPair.priceAsset == BTCId || o.assetPair.amountAsset == BTCId)
                        case _ => sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey )
                    }
                Buy back ad uno specifico prezzo in WAVES
                    let myAssetId = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6B9'
                    let cooperPubKey = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'
                    match tx {
                        case o: Order =>
                            o.assetPair.priceAsset == base58'' && o.assetPair.amountAsset == myAssetId && o.price == 500000 && o.amount == 1000 && o.orderType == Buy
                        case _ => sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey )
                    }
        come associare uno script ad un account
            ...
        DataTransaction
            Da capire
Sembrano interessanti, l'impressione è che, forse, sono relativamente semplici da capire e implementare.
full member
Activity: 1064
Merit: 166
October 29, 2018, 03:32:59 AM
#85
Segnalo questo thread in inglese dove si tratta di testamenti ed è saltato fuori qualcosa di interessante di cui non ero a conoscenza https://bitcointalksearch.org/topic/how-to-make-a-crypto-testament-5052754

Il succo è: creando con un nuovo indirizzo ethereum un certo numero di smart contract in una rete di test e poi nella main net ethereum, questi avranno gli stessi indirizzi.

https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed/761#761

Quote
The address for an Ethereum contract is deterministically computed from the address of its creator (sender) and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then hashed with Keccak-256.

Non la sapevo questa cosa degli indirizzi, ed è vero che potrebbe tornare utile  Cool

Per l'utilizzo che ne fà nel suo caso, forse avrebbe potuto bloccare il testamento usando il numero del blocco corrente ( 10 - 20 o 30 anni nel futuro contando un tempo di creazione per blocco di 10 minuti) e ritardando la scandenza nel caso fosse ancora in vita. Ci sono un sacco di modi magari piu semplici per fare un testamento.
newbie
Activity: 69
Merit: 0
October 28, 2018, 12:38:21 PM
#84
a dirla ll' inglese OMG
legendary
Activity: 2506
Merit: 1120
October 28, 2018, 06:16:03 AM
#83
Segnalo questo thread in inglese dove si tratta di testamenti ed è saltato fuori qualcosa di interessante di cui non ero a conoscenza https://bitcointalksearch.org/topic/how-to-make-a-crypto-testament-5052754

Il succo è: creando con un nuovo indirizzo ethereum un certo numero di smart contract in una rete di test e poi nella main net ethereum, questi avranno gli stessi indirizzi.

https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed/761#761

Quote
The address for an Ethereum contract is deterministically computed from the address of its creator (sender) and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then hashed with Keccak-256.
E' per queste cose che adoro il modo crypto-blockchain.
E' come quando qualcuno scopre l'acqua calda Smiley (*)
EDIT: bisogna però osservare che ethereum ha già dato segni di non immutabilità delle regole.
EDIT2: (*) e scopre un utilizzo interessante dell'acqua calda ...
hero member
Activity: 784
Merit: 1416
October 28, 2018, 04:46:28 AM
#82
Segnalo questo thread in inglese dove si tratta di testamenti ed è saltato fuori qualcosa di interessante di cui non ero a conoscenza https://bitcointalksearch.org/topic/how-to-make-a-crypto-testament-5052754

Il succo è: creando con un nuovo indirizzo ethereum un certo numero di smart contract in una rete di test e poi nella main net ethereum, questi avranno gli stessi indirizzi.

https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed/761#761

Quote
The address for an Ethereum contract is deterministically computed from the address of its creator (sender) and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then hashed with Keccak-256.
newbie
Activity: 69
Merit: 0
October 05, 2018, 03:47:39 AM
#81
grazie
Pages:
Jump to: