nebulasio / wiki

This repository is out of date, please check the new wiki:
http://wiki.nebulas.io/en/latest/
GNU General Public License v3.0
421 stars 154 forks source link

{"error":"account is not found"} when deploying a smart contract #169

Closed hillelt closed 6 years ago

hillelt commented 6 years ago

I've followed the first 3 Nebulas tutorials: I started a local node and a miner, created a user and transferred NAS to it. I can see the new user's balance successfully:

>> curl -i -H Accept:application/json -X POST http://localhost:8685/v1/user/accountstate -d '{"address":"n1Jq9oeKNNhekzxEdQfWdAZDeG21HvkBfXb"}'
{"result":{"balance":"1000000000000000000","nonce":"0","type":87}}

However, when I try and deploy a smart contract per the instructions in the tutorial (just changing the from/to addresses to be the address of the new user), I'm getting the error in the title. The nonce seems right to me (1 above the user's current nonce), so I'm not sure what I'm missing.

>> curl -i -H 'Accept: application/json' -X POST http://localhost:8685/v1/admin/transactionWithPassphrase -H 'Content-Type: application/json' -d '{"transaction": {"from":"n1Jq9oeKNNhekzxEdQfWdAZDeG21HvkBfXb","to":"n1Jq9oeKNNhekzxEdQfWdAZDeG21HvkBfXb", "value":"0","nonce":1,"gasPrice":"1000000","gasLimit":"2000000","contract":{"source":"\"use strict\";var DepositeContent=function(text){if(text){var o=JSON.parse(text);this.balance=new BigNumber(o.balance);this.expiryHeight=new BigNumber(o.expiryHeight);}else{this.balance=new BigNumber(0);this.expiryHeight=new BigNumber(0);}};DepositeContent.prototype={toString:function(){return JSON.stringify(this);}};var BankVaultContract=function(){LocalContractStorage.defineMapProperty(this,\"bankVault\",{parse:function(text){return new DepositeContent(text);},stringify:function(o){return o.toString();}});};BankVaultContract.prototype={init:function(){},save:function(height){var from=Blockchain.transaction.from;var value=Blockchain.transaction.value;var bk_height=new BigNumber(Blockchain.block.height);var orig_deposit=this.bankVault.get(from);if(orig_deposit){value=value.plus(orig_deposit.balance);} var deposit=new DepositeContent();deposit.balance=value;deposit.expiryHeight=bk_height.plus(height);this.bankVault.put(from,deposit);},takeout:function(value){var from=Blockchain.transaction.from;var bk_height=new BigNumber(Blockchain.block.height);var amount=new BigNumber(value);var deposit=this.bankVault.get(from);if(!deposit){throw new Error(\"No deposit before.\");} if(bk_height.lt(deposit.expiryHeight)){throw new Error(\"Can not takeout before expiryHeight.\");} if(amount.gt(deposit.balance)){throw new Error(\"Insufficient balance.\");} var result=Blockchain.transfer(from,amount);if(!result){throw new Error(\"transfer failed.\");} Event.Trigger(\"BankVault\",{Transfer:{from:Blockchain.transaction.to,to:from,value:amount.toString()}});deposit.balance=deposit.balance.sub(amount);this.bankVault.put(from,deposit);},balanceOf:function(){var from=Blockchain.transaction.from;return this.bankVault.get(from);},verifyAddress:function(address){var result=Blockchain.verifyAddress(address);return{valid:result==0?false:true};}};module.exports=BankVaultContract;","sourceType":"js", "args":""}}, "passphrase": "passphrase"}'
{"error":"account is not found"}

Any idea what I'm doing wrong?

hillelt commented 6 years ago

I was able to overcome this issue. The problem was that while the new user I created was added to the chain and I could see its balance, the running node needs to be aware of its private key in keydir to be able to sign with it on new transactions. This seems to not be automatic. Restarting the node solved the problem and I could create the smart contract, send NAS, etc. I'm leaving the ticket open as this might need to be better indicated in the tutorial.