Interact with Contract
Initialize web3 instance
Trước tiên bạn cần khởi tạo web3
let web3 = Web3.InfuraRinkebyWeb3()
let data = wallet.data
let keystoreManager: KeystoreManager
if wallet.isHD {
let keystore = BIP32Keystore(data)!
keystoreManager = KeystoreManager([keystore])
} else {
let keystore = EthereumKeystoreV3(data)!
keystoreManager = KeystoreManager([keystore])
}
web3.addKeystoreManager(keystoreManager)Create Contract
Lưu ý: Khi tạo contract file contract phải có payable. Nếu không có thì tự thêm vào.
let contractABI = "..." // Contract ABI
let contractAddress = EthereumAddress(contractAddressString)!
let abiVersion = 2 // Contract ABI version
let contract = web3.contract(contractABI, at: contractAddress, abiVersion: abiVersion)!Send Read Transaction
Chỉ định func, dùng contract để tạo transaction và tiến hành gửi.
Send Write Transaction
Chỉ định func, dùng contract tạo Transaction, thiết lập Gas Price, Gas Limit, truyền vào password tiến gửi transaction.
Last updated
Was this helpful?