diff --git a/README.md b/README.md
index 3793be93..3d54919c 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Lighthouse
+# Lighthouse
Lighthouse is a permanent decentralized file storage protocol that allows the ability to pay once and store forever. While traditionally, users need to repeatedly keep track and pay for their storage after every fixed amount of time, Lighthouse manages this for them and makes sure that user files are stored forever. The aim is to move users from a rent-based cost model where they are renting their own files on cloud storage to a permanent ownership model. It is built on top of IPFS, Filecoin, and Polygon. It uses the existing miner network and storage capacity of the filecoin network.
diff --git a/package-lock.json b/package-lock.json
index a4011e6b..2d89720c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@lighthouse-web3/sdk",
- "version": "0.2.9",
+ "version": "0.3.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@lighthouse-web3/sdk",
- "version": "0.2.9",
+ "version": "0.3.0",
"license": "MIT",
"dependencies": {
"@lighthouse-web3/kavach": "^0.1.4",
diff --git a/package.json b/package.json
index 96ec1fa6..85c9fb4a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@lighthouse-web3/sdk",
- "version": "0.2.9",
+ "version": "0.3.0",
"description": "NPM package and CLI tool to interact with lighthouse protocol",
"main": "./dist/Lighthouse/index.js",
"types": "./dist/Lighthouse/index.d.ts",
diff --git a/src/Commands/index.ts b/src/Commands/index.ts
index 118c0441..d995a0cf 100644
--- a/src/Commands/index.ts
+++ b/src/Commands/index.ts
@@ -72,7 +72,7 @@ Command.prototype.helpInformation = function (context: any) {
}
widgets.addHelpText('before', 'Welcome to lighthouse-web3')
-widgets.version('0.2.9')
+widgets.version('0.3.0')
widgets
.command('wallet')
diff --git a/src/Lighthouse/payPerDeal/fund/browser.ts b/src/Lighthouse/payPerDeal/fund/browser.ts
index 79368f90..44319628 100644
--- a/src/Lighthouse/payPerDeal/fund/browser.ts
+++ b/src/Lighthouse/payPerDeal/fund/browser.ts
@@ -12,11 +12,18 @@ export default async (amount: number, network: string, token: string) => {
}
//@ts-ignore
const provider = new ethers.BrowserProvider((window as any).ethereum)
+ const getFeeData=await provider.getFeeData()
const signer = await provider.getSigner()
if(token.toLowerCase()==="native") {
+ const gasEstimate = await signer.estimateGas({
+ to: config.lighthouse_contract_address,
+ value: amount,
+ })
const tx = await signer.sendTransaction({
- to: config.lighthouse_contract_address,
- value: amount,
+ to: config.lighthouse_contract_address,
+ value: amount,
+ gasLimit: gasEstimate,
+ gasPrice: getFeeData.gasPrice,
})
await tx.wait()
return tx
@@ -24,9 +31,27 @@ export default async (amount: number, network: string, token: string) => {
const tokenAddress = config[`${token.toLowerCase()}_contract_address`]
const paymentContract = new ethers.Contract(config.lighthouse_contract_address, lighthuseContract, signer)
const erc20Contract = new ethers.Contract(tokenAddress, erc20, signer)
- const approvalTx = await erc20Contract.approve(config.lighthouse_contract_address, amount)
+ const approvalData = erc20Contract.interface.encodeFunctionData("approve", [config.lighthouse_contract_address, amount]);
+ const approvalTxObject = {
+ to: tokenAddress,
+ data: approvalData,
+ }
+ const gasEstimateForApproval = await signer.estimateGas(approvalTxObject);
+ const approvalTx = await erc20Contract.approve(config.lighthouse_contract_address, amount, {
+ gasLimit: gasEstimateForApproval,
+ gasPrice: getFeeData.gasPrice,
+ })
await approvalTx.wait()
- const tx = await paymentContract.receiveToken(amount, tokenAddress)
+ const transferData = paymentContract.interface.encodeFunctionData("receiveToken", [amount, tokenAddress])
+ const transferTxObject = {
+ to: config.lighthouse_contract_address,
+ data: transferData,
+ }
+ const gasEstimateForTransfer = await signer.estimateGas(transferTxObject)
+ const tx = await paymentContract.receiveToken(amount, tokenAddress, {
+ gasLimit: gasEstimateForTransfer,
+ gasPrice: getFeeData.gasPrice,
+ })
await tx.wait()
return tx
}
diff --git a/src/Lighthouse/payPerDeal/fund/node.ts b/src/Lighthouse/payPerDeal/fund/node.ts
index 57542ecf..842cb266 100644
--- a/src/Lighthouse/payPerDeal/fund/node.ts
+++ b/src/Lighthouse/payPerDeal/fund/node.ts
@@ -14,11 +14,18 @@ export default async (amount: number, network: string, token: string, privateKey
throw new Error("Unsupported Network!!!")
}
const provider = new ethers.JsonRpcProvider(config.rpc)
+ const getFeeData=await provider.getFeeData()
const signer = new ethers.Wallet(privateKey, provider)
if(token.toLowerCase()==="native") {
+ const gasEstimate = await signer.estimateGas({
+ to: config.lighthouse_contract_address,
+ value: amount,
+ })
const tx = await signer.sendTransaction({
to: config.lighthouse_contract_address,
value: amount,
+ gasLimit: gasEstimate,
+ gasPrice: getFeeData.gasPrice,
})
await tx.wait()
return tx
@@ -26,9 +33,27 @@ export default async (amount: number, network: string, token: string, privateKey
const tokenAddress = config[`${token.toLowerCase()}_contract_address`]
const paymentContract = new ethers.Contract(config.lighthouse_contract_address, lighthuseContract, signer)
const erc20Contract = new ethers.Contract(tokenAddress, erc20, signer)
- const approvalTx = await erc20Contract.approve(config.lighthouse_contract_address, amount)
+ const approvalData = erc20Contract.interface.encodeFunctionData("approve", [config.lighthouse_contract_address, amount])
+ const approvalTxObject = {
+ to: tokenAddress,
+ data: approvalData,
+ }
+ const gasEstimateForApproval = await signer.estimateGas(approvalTxObject)
+ const approvalTx = await erc20Contract.approve(config.lighthouse_contract_address, amount, {
+ gasLimit: gasEstimateForApproval,
+ gasPrice: getFeeData.gasPrice,
+ })
await approvalTx.wait()
- const tx = await paymentContract.receiveToken(amount, tokenAddress)
+ const transferData = paymentContract.interface.encodeFunctionData("receiveToken", [amount, tokenAddress])
+ const transferTxObject = {
+ to: config.lighthouse_contract_address,
+ data: transferData,
+ }
+ const gasEstimateForTransfer = await signer.estimateGas(transferTxObject)
+ const tx = await paymentContract.receiveToken(amount, tokenAddress, {
+ gasLimit: gasEstimateForTransfer,
+ gasPrice: getFeeData.gasPrice,
+ })
await tx.wait()
return tx
}
diff --git a/src/lighthouse.config.ts b/src/lighthouse.config.ts
index 38a1dfac..7dc28ebf 100644
--- a/src/lighthouse.config.ts
+++ b/src/lighthouse.config.ts
@@ -56,9 +56,9 @@ const defaultConfig = {
},
filecoin: {
symbol: 'FIL',
- rpc: 'https://mainnet.optimism.io',
+ rpc: 'https://api.node.glif.io',
scan: 'https://filfox.info/en/message/',
- chain_id: '10',
+ chain_id: '314',
lighthouse_contract_address: '0x9297A1eD441eA63257e933DCC335EE4D1E562C37',
usdc_contract_address: '0xEB466342C4d449BC9f53A865D5Cb90586f405215',
usdc_contract_decimal: 6,