-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnep17-airdrop.py
70 lines (60 loc) · 2.33 KB
/
nep17-airdrop.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
66
67
68
69
70
"""
This example shows how to send tokens to multiple accounts in one go.
It will mint the "COZ Token"
"""
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 examples import shared
async def example_airdrop(neoxp: shared.NeoExpress):
# This example shows how to airdrop NEP-17 tokens
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
)
# Use the generic NEP17 class to wrap the token
token = NEP17Contract(shared.coz_token_hash)
balance = await facade.test_invoke(token.balance_of(account.address))
print(f"Current token balance: {balance}")
# First we have to mint the tokens to our own wallet
# We do this by sending EpicChain to the contract
# We increase the retry delay to match our local chain block production time
neo = NeoToken()
print("Minting once...", end="")
receipt = await facade.invoke(
neo.transfer(
source=account.address, destination=shared.coz_token_hash, amount=100
)
)
print(receipt.result)
print("Minting twice...", end="")
receipt = await facade.invoke(
neo.transfer(
source=account.address, destination=shared.coz_token_hash, amount=100
)
)
print(receipt.result)
balance = await facade.test_invoke(token.balance_of(account.address))
print(f"New token balance: {balance}")
# Now let's airdrop the tokens
destination_addresses = [
"XtxcQeNhLuNDucqAVynTwYBh2QHdDUyPzN",
"XciXUD25yEsuMcxpq1eGoEZyLbstM3N1KE",
"XsokdeQ3kXqsryRycSVd1cJ86tHJ8kn8uP",
"XxBHmJuzGu8vnUnbB7ZWXWrS37hypTPwtB",
"XkqcLP2QnBsHZnVnFxZ97fbsiEDAcB3bkZ",
]
print("Airdropping 10 tokens and waiting for receipt")
print(
await facade.invoke(
token.transfer_multi(account.address, destination_addresses, 10),
)
)
if __name__ == "__main__":
with shared.NeoExpress() as neoxp:
asyncio.run(example_airdrop(neoxp))