github.com/shyftnetwork/go-empyrean@v1.8.3-0.20191127201940-fbfca9338f04/shyft-config/shyft-cli/web3/testContract.js (about)

     1  var testContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"live","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_bool","type":"bool"}],"name":"Live","type":"event"}]);
     2  var test = testContract.new(
     3      {
     4          from: web3.eth.accounts[0],
     5          data: '0x6060604052341561000f57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506101698061005e6000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680638da5cb5b14610051578063957aa58c146100a6575b600080fd5b341561005c57600080fd5b6100646100d3565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156100b157600080fd5b6100b96100f8565b604051808215151515815260200191505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60007f63f89985c88a92552c6e2ce4d4e46e9fbb7a06168c4536e662261decae02f9e76001604051808215151515815260200191505060405180910390a160019050905600a165627a7a7230582091089d445770c1c9bb2f0f86f6c0b8552ef59af41930e1f7ecfac34326b20e590029',
     6          gas: '4700000'
     7      }, function (e, contract){
     8          if (e) {
     9              console.log("Error: ", e)
    10          }
    11          console.log("TX Hash:", contract.transactionHash)
    12          if (typeof contract.address !== 'undefined') {
    13              console.log('Contract address: ' + contract.address)
    14              console.log('TransactionHash: ' + contract.transactionHash);
    15              interact(contract.address);
    16          }
    17      });
    18  
    19  function waitBlock(callback) {
    20      function innerWaitBlock() {
    21  
    22          var receipt = web3.eth.getTransactionReceipt(test.transactionHash);
    23          if (receipt && receipt.contractAddress) {
    24              callback(receipt);
    25          } else {
    26              // console.log("Waiting a mined block to include your contract... currently in block " + web3.eth.blockNumber);
    27              setTimeout(innerWaitBlock(), 4000);
    28          }
    29      }
    30      innerWaitBlock();
    31  }
    32  
    33  waitBlock(function (receipt) {
    34      // do stuff here now that the contract has been deployed
    35      console.log("[Receipt] Contract Address: ", receipt.contract.address)
    36  });
    37  
    38  function interact(addr) {
    39      var contract = testContract.at(addr);
    40      contract.live({
    41          from: web3.eth.accounts[0],
    42          gas: '4700000'
    43      }, function (e, res) {
    44          if (e) {
    45              console.log(e)
    46          }
    47          console.log('Live TxHash: ', res)
    48      });
    49      contract.live.call({
    50          from: web3.eth.accounts[0],
    51          gas: '4700000'
    52      }, function (e, res) {
    53          if (e) {
    54              console.log(e)
    55          }
    56          console.log('Live Response: ', res)
    57      })
    58  }