-
Notifications
You must be signed in to change notification settings - Fork 3
/
ERC20.gd
49 lines (32 loc) · 968 Bytes
/
ERC20.gd
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
extends Control
export var contract_address = ""
var symbol = ""
var balance = 0
var erc20_abi
var contract
var wallet
onready var balance_updated = JavaScript.create_callback(self, "_balance_updated")
onready var symbol_updated = JavaScript.create_callback(self, "_symbol_updated")
var web3
var web3_utils
func _symbol_updated(p):
web3_utils.debug(p[0])
symbol = p[0]
get_node("name").set_text(symbol)
func _balance_updated(p):
web3_utils.debug(p[0])
balance = p[0]
get_node("balance").set_text(p[0])
func init_web3(p_web3, abi):
web3_utils = JavaScript.get_interface("web3_utils")
web3 = p_web3
erc20_abi = abi
wallet = get_node("/root/wallet")
contract = web3_utils.new_contract(erc20_abi, contract_address)
contract.options.from = wallet.get_account()
update()
func update():
contract.methods.balanceOf(wallet.get_account()).call().then(balance_updated)
contract.methods.symbol().call().then(symbol_updated)
func _ready():
pass