Coder Social home page Coder Social logo

Comments (3)

ninjaahhh avatar ninjaahhh commented on July 2, 2024

can you try following the instructions here https://github.com/QuarkChain/quarkchain-web3.js#web3qkccontract ?

from quarkchain-web3.js.

jishankai avatar jishankai commented on July 2, 2024

I wish that this example could help. @kvyb

// include the quarkchain-web3.js and web3.js in your head file

(function () {
  web3 = new Web3();
  //web3.setProvider(new web3.providers.HttpProvider());
  web3.setProvider(new web3.providers.HttpProvider("http://jrpc.testnet.quarkchain.io:38391"));
  QuarkChain.injectWeb3(web3, "http://jrpc.testnet.quarkchain.io:38391");
  web3.qkc.setPrivateKey(YOUR_PRIVATE_KEY);

  // for Chrome MetaMask Use and don't need private key
  // if (typeof web3 === 'undefined') {
  //   const msg = "Couldn't detect web3. Make sure MetaMask is installed.";
  //   alert(msg);
  //   console.error(msg);
  //   return;
  // }
  // QuarkChain.injectWeb3(web3, "http://jrpc.testnet.quarkchain.io:38391");

})();


function deploy() {
  var abi = YOUR_CONTRACT_ABI;
  var bytecode = YOUR_CONTRACT_BYTECODE;
  var contractClass = web3.qkc.contract(abi);
  // for deploy, you need enough tqkc in your testnet account. Otherwise, you will get 0x00000000... txid in your console.
  var contractInstance = contractClass.new(form.body.param1, form.body.param2, ...., form.body.paramN, {data: bytecode, gasPrice: 1000000000, gas: 1000000}, function(err, contract) {
    if(!err) {
      // NOTE: The callback will fire twice!
      // Once the contract has the transactionId property set and once its deployed on an address.

      // e.g. check tx hash on the first call (transaction send)
      if(!contract.address) {
        console.log(contract.transactionId); // The id of the transaction, which deploys the contract
     
        var intervId = setInterval(function(){
          var transactionReceipt = web3.qkc.getTransactionReceipt(contract.transactionId);
          if(!transactionReceipt) {
            console.log(Date.now());
          }
          else {
            clearInterval(intervId);
            console.log(transactionReceipt.contractAddress);
          }
        }, 2000);

        // check address on the second call (contract deployed)
      } else {
        // i don't know why, it never get here in my try without metamask

        console.log(contract.address); // the contract address
        // Note that the returned "contractInstance" === "contract",
        // so the returned "contractInstance" object will also get the address set.
      }
    } else {
    }
  });
}

from quarkchain-web3.js.

ninjaahhh avatar ninjaahhh commented on July 2, 2024

close for inactivity

from quarkchain-web3.js.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.