Skip to content
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

#86dtu8yuk - Include how to use NEP17Contract to Calling contracts do… #1266

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/source/calling-smart-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ def calling_other_contract() -> str:
return neo_symbol
```

### Calling NEP-17 Contracts
In addition, Neo3-Boa has an interface for contracts that adhere to the NEP-17 standard.
```python
# calling_nep17_contract.py
from boa3.sc.compiletime import public
from boa3.sc.contracts import ContractManagement
from boa3.sc.types import Nep17Contract


@public
def calling_other_contract(my_contract_hash: str) -> str:
nep_17_contract: Nep17Contract = ContractManagement.get_contract(my_contract_hash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going to throw compilation errors. get_contract argument should me UInt160 shouldn't it?
If this is the case, change the variable type

Suggested change
from boa3.sc.types import Nep17Contract
@public
def calling_other_contract(my_contract_hash: str) -> str:
nep_17_contract: Nep17Contract = ContractManagement.get_contract(my_contract_hash)
from boa3.sc.types import Nep17Contract, UInt160
@public
def calling_other_contract(my_contract_hash: UInt160) -> str:
nep_17_contract: Nep17Contract = ContractManagement.get_contract(my_contract_hash)

return nep_17_contract.symbol()
```
> Note: The compiler cannot validate if the provided contract hash corresponds to a NEP-17 contract. If the corresponding smart contract does not implement a required NEP-17 method and such method is called, it will cause a runtime error.

### Automate with CPM
Instead of manually writing the smart contract interface, you can use [CPM](https://github.com/CityOfZion/cpm/tree/master#readme)
to generate it automatically. After installing Neo3-Boa, you can install CPM by typing `install_cpm` on CLI (without the
Expand Down
Loading