-
Notifications
You must be signed in to change notification settings - Fork 18
Integrating DAPP
hashmesan edited this page Aug 26, 2021
·
5 revisions
The SmartVault wallet provides generalized function call to interact with any other smart contract without modifying the wallet code itself. This method is called "multi-call". Multiple calls can be made on behalf of the wallet via the submitTransaction relayer call. This means you can focus on building your app without worrying how it will be integrated with SmartVault. We showcased how it works with Uniswap in the example below.
Let's build a simple script to swap ONE for VIPER coin using the swapETHForExactTokens
.
- Get the tokens
const WONE = WETH[ChainId.HARMONY_TESTNET]
const VIPER = new Token(ChainId.HARMONY_TESTNET, '0x11F477aE5f42335928fC94601a8A81ec77b27b2b', 18, 'VIPER', 'Viper')
const pairData = await Fetcher.fetchPairData(WONE, VIPER, anotherProvider)
- Get the smartvault contracct
const walletFile = "/home/hashmesan/.smartvault/testnet0/.smartvault-one1yczfrtqqjsk93hwau3rwecfghj73yssjndl72c-hashmesan03.crazy.one"
var client = new SmartVault(config.CONFIG["testnet0"]);
client.loadFromLocal(walletFile);
var smartWallet = client.harmonyClient.getContract(client.walletData.walletAddress);
var receiveAddress = client.walletData.walletAddress;
- Compose the multicall
const path = [WONE.address, VIPER.address];
const deadline = parseInt(new Date().getTime()/1000)+2000;
var data = uniswapContract.methods.swapETHForExactTokens(amountIn, path, receiveAddress, timestamp).encodeABI()
var methodData = smartWallet.methods.multiCall([{to: uniswapContract.options.address, value: web3utils.toWei("2.5"), data: data}]).encodeABI()
- Submit the transaction
var res = await client.submitTransaction(methodData)
Full code at https://github.com/hashmesan/harmony-totp/blob/7d0b3ecf03da48ad04d6abb05515af1976e58ea1/lib/test/uniswap_test.js