Coder Social home page Coder Social logo

Comments (3)

qcdll avatar qcdll commented on June 21, 2024

I tried out the code (there is a typo which I fixed) in my browser and it seems to work fine:
no need to set up server or html, just go to http://testnet.quarkchain.io/ (NOTE https won't work) and paste the js code, all works fine and the contract was created successfully http://testnet.quarkchain.io/tx/0xeb7c3f469a424a9e003466f8ba212314b8fdaa5fd2eda362fc39902f85e2203b00872619

I can see the POST http://jrpc.testnet.quarkchain.io:38391/ 404 (Not Found) error as well, but if you go to network tab and see what it is about, the method is eth_newBlockFilter, I don't think it really matters, we can just kill it later

from quarkchain-web3.js.

jishankai avatar jishankai commented on June 21, 2024

Thanks so much for your reply.

I'm sorry for the typo made when I write the issue...However, I can deploy the contract but I still can't get the contract address for the second callback never happened.

I change the workflow. Use the func getTransactionRceipt with setInterval to get the contractAddress in first callback func. It can work now.

code as follows:

  var tokenContractReturned = TokenContract.new(parseInt(req.body.totalSupply), req.body.tokenName, req.body.symbol, parseInt(req.body.decimals), req.body.ownerAddress, parseInt(req.body.buyRate), Date.parse(req.body.endDate),
  {
    data: bytecode,
    gasPrice: 1000000000,
    gas: 1000000,
    fromFullShardId: finalFullShardId,
  },function(err, tokenContract){
      if(!err) {
    //fromFullShardId: getTargetFullShardId(req.app.get('shard'))},
        // 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(!tokenContract.address) {
          console.log("/////////////////////txid////////////////////");
          console.log(tokenContract.transactionId); // The id of the transaction, which deploys the contract

          var transactionId = tokenContract.transactionId;
          var transactionReceipt;
          var intervId = setInterval(function(){
            transactionReceipt = web3.qkc.getTransactionReceipt(transactionId);
            if(!transactionReceipt) {
              console.log(Date.now());
            }
            else {
              clearInterval(intervId);
              console.log(transactionReceipt);

              req.app.set('shard', (req.app.get('shard')+1)%32);
              res.json({address: `${transactionReceipt.contractAddress}${finalFullShardId.slice(2)}`});
            }
          }, 2000);
          // check address on the second call (contract deployed)
        } else {
          console.log("/////////////////////address/////////////////");
          console.log(tokenContract.address); // the contract address
        }

        // Note that the returned "myContractReturned" === "myContract",
        // so the returned "myContractReturned" object will also get the address set.
      }
  });

from quarkchain-web3.js.

qcdll avatar qcdll commented on June 21, 2024

oh, the fact that using a interval works probably means the server won't have the contract address ready until some time has passed :-)

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.