-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnep17-transfer.py
65 lines (54 loc) · 2.57 KB
/
nep17-transfer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
This files has 2 examples that show how to transfer NEP-17 tokens for a contract that
has an existing wrapper (like NEO) and how to transfer for any arbitrary contract that
implements the NEP-17 standard
"""
import asyncio
from neo3.api.wrappers import ChainFacade, NeoToken, NEP17Contract
from neo3.api.helpers.signing import sign_insecure_with_account
from neo3.network.payloads.verification import Signer
from neo3.core import types
from examples import shared
async def example_transfer_neo(neoxp: shared.NeoExpress):
# This example shows how to transfer NEO tokens, a contract that has a dedicated wrapper
wallet = shared.user_wallet
account = wallet.account_default
# This is your interface for talking to the blockchain
facade = ChainFacade(rpc_host=neoxp.rpc_host)
facade.add_signer(
sign_insecure_with_account(account, password="123"),
Signer(account.script_hash), # default scope is CALLED_BY_ENTRY
)
source = account.address
destination = "XyPUJMm6PhmtvGM7D1NsYagEfyNbVT1NGB"
# Dedicated Neo native contract wrapper
neo = NeoToken()
print("Calling transfer and waiting for receipt...")
print(await facade.invoke(neo.transfer(source, destination, 10)))
async def example_transfer_other(neoxp: shared.NeoExpress):
# This example shows how to transfer NEP-17 tokens for a contract that does not
# have a dedicated wrapper like Neo and Gas have.
# Most of the setup is the same as the first example
wallet = shared.user_wallet
account = wallet.account_default
# This is your interface for talking to the blockchain
facade = ChainFacade(rpc_host=neoxp.rpc_host)
facade.add_signer(
sign_insecure_with_account(account, password="123"),
Signer(account.script_hash), # default scope is CALLED_BY_ENTRY
)
source = account.address
destination = "XyPUJMm6PhmtvGM7D1NsYagEfyNbVT1NGB"
# Use the generic NEP17 class to wrap the token and create a similar interface as before
# The contract hash is that of our sample Nep17 token which is deployed in our neoxpress setup
contract_hash = types.UInt160.from_string(
"0x41ee5befd936c90f15893261abbd681f20ed0429"
)
token = NEP17Contract(contract_hash)
# Now call it in the same fashion as before with the NEoToken
print("Calling transfer and waiting for receipt...")
print(await facade.invoke(token.transfer(source, destination, 10)))
if __name__ == "__main__":
with shared.NeoExpress() as neoxp:
asyncio.run(example_transfer_neo(neoxp))
asyncio.run(example_transfer_other(neoxp))