-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deploy contract with quarkchain-web3.js in browser without metamask #10
Comments
I tried out the code (there is a typo which I fixed) in my browser and it seems to work fine: I can see the |
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 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.
}
}); |
oh, the fact that using a interval works probably means the server won't have the contract address ready until some time has passed :-) |
I forked qcgg/quarkchain-web3-contract-example.js and used it in browser. With MetaMask it woked fine. However, for supporting more browsers and more friendly to noob, I need use it without MetaMask. If I don't have a server, what should I do?
Here is my code.
I run the code in Safari and Chrome. All had the error as follows:
![image](https://user-images.githubusercontent.com/2420990/48262589-1084d680-e45e-11e8-8d0f-d66831b15e21.png)
![image](https://user-images.githubusercontent.com/2420990/48262607-25fa0080-e45e-11e8-8cf6-a2b98179162c.png)
I would appreciate any suggestion!
Above all, when I used the sample code in server, I can only get the transactionId and no second callback for address but I can see the success of the deploy in testnet explorer, I need the contract address when I deploy it and tell the customers.
![image](https://user-images.githubusercontent.com/2420990/48262792-c819e880-e45e-11e8-8ee5-f95d75d382f2.png)
You can see I only get the txid back and then timeout. It's exactly same code besides I used require instead of import.
The text was updated successfully, but these errors were encountered: