contract interaction
unknown
typescript
a year ago
1.2 kB
9
Indexable
Never
import { Wallet, Contract, Web3Provider, Provider } from "zksync-web3"; import { ethers } from "ethers"; import contractABI from './abi.js'; // This needs to be extracted/extrapolated const provider = new Provider('https://mainnet.era.zksync.io'); // This is an example of code we would need. Of course the method call and inputs would vary depending on the type of tx (eg: swap, bridge, stake etc..) async function execute(privateKey: string, amount: string) { const wallet = new Wallet(privateKey).connect(provider); const contract = new Contract( '0xXXX', // -> This can easily be found in the tx contractABI, wallet ); const parsedEthers = ethers.utils.parseEther(amount); // We wanna be able to inject this parameter const gasLimit = 600000; const feeInGas = await contract.estimateGas.swap_out( '0xXX', 1101, '0xXX', parsedEthers, gasLimit, { gasLimit: gasLimit, value: parsedEthers } ); await contract.swap_out( '0xXX', 1101, '0xXX', parsedEthers, feeInGas, { gasLimit: feeInGas, value: parsedEthers } ) }