Open zhaobinglong opened 4 years ago
调用下面的函数完成授权,每个钱包在进行第一次买入和卖出时,需要对当前买入和卖出的token做一次授权,第二次开始就不需要授权了
static Future approve(String token) async { String value = BigInt.from(10).pow(27) .toString(); String postData = func['approve()'] + formatParam(proxy) + formatParam(value); print('approve proxy => ${formatParam(proxy)}'); print('approve value => ${formatParam(value)}'); print('approve postData=> ${postData}'); String rpcUrl = "https://ropsten.infura.io/"; String privateKey = await getPrivateKey(''); final client = Web3Client(rpcUrl, Client()); var credentials = await client.credentialsFromPrivateKey(privateKey); try { var rsp = await client.sendTransaction( credentials, Transaction( to: EthereumAddress.fromHex(token), gasPrice: EtherAmount.inWei(BigInt.from(20000000000)), maxGas: 7000000, value: EtherAmount.fromUnitAndValue(EtherUnit.ether, 0), data: hexToBytes(postData) ), chainId: 3 ); print("approve rsp => ${rsp}"); } catch (e) { print("catch error =》 ${e}"); } }
deadline:2020-01-30 size:1
一次授权的log打印:
接口返回交易的hash,拿到hash就代表授权成功了
https://github.com/youwallet/wallet/issues/63
授权之前需要获取密码,给用户提示:
为了便于后续兑换,需要您授权youwallet代理。youwallet只会在你授权的情况下才会执行交易,请放心授权!
调用下面的函数完成授权,每个钱包在进行第一次买入和卖出时,需要对当前买入和卖出的token做一次授权,第二次开始就不需要授权了