This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawnToken.py
51 lines (39 loc) · 1.83 KB
/
spawnToken.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
import json
import web3
from web3 import Web3, HTTPProvider
from solc import compile_source
from web3.contract import ConciseContract
cotract_path = './contracts/DAIMock.sol'
contract_name = 'DAIMock'
LOAN_ADDRESS = '0x668ed30aacc7c7c206aaf1327d733226416233e2'
with open(cotract_path) as contract_file:
w3 = Web3(Web3.HTTPProvider('http://localhost:8545'))
w3.eth.defaultAccount = w3.eth.accounts[0]
contract_source_code = contract_file.read()
compiled_sol = compile_source(contract_source_code,
import_remappings=['=./contracts/', '-'])
contract_interface = compiled_sol['<stdin>:'+contract_name]
Token = w3.eth.contract(abi=contract_interface['abi'],
bytecode=contract_interface['bin'])
# ============Top up borrower token balance in constructor=================
initialAddress = Web3.toChecksumAddress(w3.eth.accounts[1])
initialBalance = 1000000
name = 'DAI DENEG'
symbol = 'DAI'
decimals = 18
tx_hash = Token.constructor(initialAddress,
initialBalance,
name,
symbol,
decimals).transact()
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
token = w3.eth.contract(address=tx_receipt.contractAddress,
abi=contract_interface['abi'])
#===============================================================
#=================Invoke approve for `tranferFrom`==============
# Allow Loan contract to spend borrower tokens
spender = Web3.toChecksumAddress(LOAN_ADDRESS)
amount = 100
w3.eth.defaultAccount = w3.eth.accounts[1]
approve_hash = token.functions.approve(spender, amount).transact()
approve_receipt = w3.eth.waitForTransactionReceipt(approve_hash)