Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

About NEP-5 Smart Contracts #1032

Open
WAELKASSEM opened this issue Mar 30, 2020 · 8 comments
Open

About NEP-5 Smart Contracts #1032

WAELKASSEM opened this issue Mar 30, 2020 · 8 comments

Comments

@WAELKASSEM
Copy link

I am using the template provided below :
https://github.com/CityOfZion/neo-boa/blob/master/boa_test/example/demo/NEP5.py
And neo-local , to create and deploy locally an NEP-5 token.
The process of build and deploy using the related commands runs successfully .

However the INVOKE command doesn't !
The command 'show contracts all' doesn't list this smart contract , but it shows my other non NEP-5 smart contracts.
I cannot find my contract using its hash.
The command 'show assets all' doesn't show my token either.

I can only test its functionality using build_run command, and it works.

Any help would be appreciated.

@ixje
Copy link
Member

ixje commented Apr 8, 2020

please describe the exact commands you used to build and deploy and to which network (private net, testnet?). It sounds like you're either doing a test invoke without actually permanently deploying the contract to a chain, or your local chain is out of sync.

@WAELKASSEM
Copy link
Author

1- sc build
2 - sc deploy True False False etc....
I get no errors.
Everything happens the same as deploying another smart contract but not NEP-5 .

using private_net.

@ixje
Copy link
Member

ixje commented Apr 13, 2020

which exact neo-python version are you using? You can type np-prompt --version assuming you followed the default installation instructions. Otherwise try cat neo/__init__.py

@WAELKASSEM
Copy link
Author

I'm using neo-local , it always pulls the latest neo-python.
And I've imported neo-boa v 0.6.0 to my python project .

@someone-somenet-org
Copy link

someone-somenet-org commented Feb 6, 2021

Same issue here, today. It seems everything is fine, but the contract just wont get deployed.

I am using the docker image: docker run --rm -d --name neo-privatenet -v /home/.../mynep5/:/neo-python/sc -p 20333-20336:20333-20336/tcp -p 30333-30336:30333-30336/tcp cityofzion/neo-privatenet

I can run things with sc build_run .... like:

  • sc build_run sc/mynep5.py True True False 0710 07 name [] --owners=["myPrivTestnetAddr"]
  • sc build_run sc/mynep5.py True True False 0710 01 noop [] --owners=["myPrivTestnetAddr"]
  • sc build_run sc/mynep5.py True True False 0710 01 noopowner [] --owners=["myPrivTestnetAddr"]

(noop and noopowner just return True, noopowner does a checkwitness check before)

But I cannot make neopy deploy that contract to privtestnet. I can transfer neo and gas from the "generic coz-privkey" to my myPrivTestnetAddr.
One weird thing: I have 32k gas in the privtestnet, but once I deploy twice, any third attempt will fail with "insufficient funds", but checking wallet there was nothing deducted. Wiping and restarting the container "fixes" it by granting me another 2 deploys.

Unsure how to debug.

Also out of frustration I tried to get my nep5token deployed on public testnet with neo-cli. That worked without any confirmation and I can call unprivileged functions on testnet.
Another issue is: I cant manage to use neo-cli to call functions that use checkWitness. There is one single example that feeds some scripthashes and some address to a transfer function, but reproducing that with what I think it means (yay docs! -.-) doesnt work.

  • invoke 0x... noop [] works.
  • invoke 0x... noopowner [] fails and I have not seen any way to turn any debugging features up.

This all needs not more examples - there are examples everywhere - but a good written one that explains the non-obvious constraints and assumptions and how to turn on debugging everywhere.

@ixje
Copy link
Member

ixje commented Feb 6, 2021

  • Have you tried attaching extra gas on the deploy transaction? Shouldn't be required but worth a try.

  • For your checkwitness problem you'll have to add a transaction attribute. See

    # often times smart contract developers use the function ``CheckWitness`` to determine if the transaction is signed by somebody eligible of calling a certain method
    # in order to pass that check you want to add the corresponding script_hash as a transaction attribute (this is generally the script_hash of the public key you use for signing)
    # Note that for public functions like the NEP-5 'getBalance' and alike this would not be needed, but it doesn't hurt either
    invocation_tx.Attributes.append(TransactionAttribute(usage=TransactionAttributeUsage.Script, data=source_script_hash))

  • As for the double/triple deploy. I've not heard of that before, but you could try running the wallet rebuild command

  • For turning on debugging from the neo-python side type config help. It can turn on network logging, results from the virtual machine processing etc. Now this will not help you if the transaction is rejected by the consensus nodes in your private net. Honestly the only way to debug why it is rejected by consensus nodes is to debug the consensus node itself. My personal way of doing that would be setup a single consensus node (solo mode) from source and debug from there. There just isn't a friendly way of doing it.

@someone-somenet-org
Copy link

  • Have you tried attaching extra gas on the deploy transaction? Shouldn't be required but worth a try.

no. how would I do that with neopy or neo-cli?

  • For your checkwitness problem you'll have to add a transaction attribute. See
    # often times smart contract developers use the function ``CheckWitness`` to determine if the transaction is signed by somebody eligible of calling a certain method
    # in order to pass that check you want to add the corresponding script_hash as a transaction attribute (this is generally the script_hash of the public key you use for signing)
    # Note that for public functions like the NEP-5 'getBalance' and alike this would not be needed, but it doesn't hurt either
    invocation_tx.Attributes.append(TransactionAttribute(usage=TransactionAttributeUsage.Script, data=source_script_hash))

I later managed to do that with neoline on pubtestnet, but I failed to do that with neopy and neo-cli. how would I do that with those?

  • As for the double/triple deploy. I've not heard of that before, but you could try running the wallet rebuild command

created container, opened wallet, waited 15 min, ran wallet rebuild, waited 15 min.

still only 2 deploys, that wont actually deploy, the 3. one will fail with insufficient funds.

@ixje
Copy link
Member

ixje commented Feb 19, 2021

  • Have you tried attaching extra gas on the deploy transaction? Shouldn't be required but worth a try.

no. how would I do that with neopy or neo-cli?

For neo-cli ask on the neo-cli repo. I don't know. For neo-python, use --attach-gas when invoking (see sc invoke help).

  • For your checkwitness problem you'll have to add a transaction attribute. See
    # often times smart contract developers use the function ``CheckWitness`` to determine if the transaction is signed by somebody eligible of calling a certain method
    # in order to pass that check you want to add the corresponding script_hash as a transaction attribute (this is generally the script_hash of the public key you use for signing)
    # Note that for public functions like the NEP-5 'getBalance' and alike this would not be needed, but it doesn't hurt either
    invocation_tx.Attributes.append(TransactionAttribute(usage=TransactionAttributeUsage.Script, data=source_script_hash))

I later managed to do that with neoline on pubtestnet, but I failed to do that with neopy and neo-cli. how would I do that with those?

use --tx-attr when invoking. Again see sc invoke help it has an example in the help description. the "usage" value should be 0x20 and the "data" has to be 20 bytes long because it expects to convert it to a UInt160

if attr.Usage == TransactionAttributeUsage.Script:
if type(attr.Data) is UInt160:
hashes.add(attr.Data)
else:
hashes.add(UInt160(data=attr.Data))

The conversion part is called by this
result = self.CheckWitnessHash(engine, UInt160(data=hashOrPubkey))

  • As for the double/triple deploy. I've not heard of that before, but you could try running the wallet rebuild command

created container, opened wallet, waited 15 min, ran wallet rebuild, waited 15 min.

still only 2 deploys, that wont actually deploy, the 3. one will fail with insufficient funds.

Sorry, no idea what is going on there then.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants