Skip to content

Commit dd0dafd

Browse files
committedDec 6, 2022
implemented success
0 parents  commit dd0dafd

13 files changed

+35066
-0
lines changed
 

‎.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules
2+
.env
3+
coverage
4+
coverage.json
5+
typechain
6+
typechain-types
7+
/client/conn.js
8+
/client/img6.jpg
9+
10+
#Hardhat files
11+
cache
12+
artifacts
13+

‎README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Sample Hardhat Project
2+
3+
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.
4+
5+
Try running some of the following tasks:
6+
7+
```shell
8+
npx hardhat help
9+
npx hardhat test
10+
REPORT_GAS=true npx hardhat test
11+
npx hardhat node
12+
npx hardhat run scripts/deploy.ts
13+
```

‎client/contracts/file.dbg.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"_format": "hh-sol-dbg-1",
3+
"buildInfo": "../../build-info/a480fab96d04ec0665559c9326edc220.json"
4+
}

‎client/contracts/file.json

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"_format": "hh-sol-artifact-1",
3+
"contractName": "file",
4+
"sourceName": "contracts/file.sol",
5+
"abi": [
6+
{
7+
"inputs": [],
8+
"name": "modelCount",
9+
"outputs": [
10+
{
11+
"internalType": "uint256",
12+
"name": "",
13+
"type": "uint256"
14+
}
15+
],
16+
"stateMutability": "view",
17+
"type": "function"
18+
},
19+
{
20+
"inputs": [
21+
{
22+
"internalType": "address",
23+
"name": "",
24+
"type": "address"
25+
}
26+
],
27+
"name": "models",
28+
"outputs": [
29+
{
30+
"internalType": "string",
31+
"name": "modelHash",
32+
"type": "string"
33+
},
34+
{
35+
"internalType": "uint256",
36+
"name": "fileSize",
37+
"type": "uint256"
38+
},
39+
{
40+
"internalType": "address payable",
41+
"name": "node",
42+
"type": "address"
43+
}
44+
],
45+
"stateMutability": "view",
46+
"type": "function"
47+
},
48+
{
49+
"inputs": [
50+
{
51+
"internalType": "string",
52+
"name": "_modelHash",
53+
"type": "string"
54+
},
55+
{
56+
"internalType": "uint256",
57+
"name": "_modelSize",
58+
"type": "uint256"
59+
}
60+
],
61+
"name": "uploadModel",
62+
"outputs": [],
63+
"stateMutability": "nonpayable",
64+
"type": "function"
65+
}
66+
],
67+
"bytecode": "0x60806040526000805534801561001457600080fd5b506109dd806100246000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806354917f8314610046578063923f5a5914610078578063c6a645fe14610094575b600080fd5b610060600480360381019061005b9190610345565b6100b2565b60405161006f9392919061043c565b60405180910390f35b610092600480360381019061008d91906105db565b610184565b005b61009c6102cd565b6040516100a99190610637565b60405180910390f35b60016020528060005260406000206000915090508060000180546100d590610681565b80601f016020809104026020016040519081016040528092919081815260200182805461010190610681565b801561014e5780601f106101235761010080835404028352916020019161014e565b820191906000526020600020905b81548152906001019060200180831161013157829003601f168201915b5050505050908060010154908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905083565b600082511161019257600080fd5b600073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16036101cb57600080fd5b600081116101d857600080fd5b6000808154809291906101ea906106e1565b919050555060405180606001604052808381526020018281526020013373ffffffffffffffffffffffffffffffffffffffff16815250600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082015181600001908161027491906108d5565b506020820151816001015560408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055509050505050565b60005481565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610312826102e7565b9050919050565b61032281610307565b811461032d57600080fd5b50565b60008135905061033f81610319565b92915050565b60006020828403121561035b5761035a6102dd565b5b600061036984828501610330565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103ac578082015181840152602081019050610391565b60008484015250505050565b6000601f19601f8301169050919050565b60006103d482610372565b6103de818561037d565b93506103ee81856020860161038e565b6103f7816103b8565b840191505092915050565b6000819050919050565b61041581610402565b82525050565b6000610426826102e7565b9050919050565b6104368161041b565b82525050565b6000606082019050818103600083015261045681866103c9565b9050610465602083018561040c565b610472604083018461042d565b949350505050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6104bc826103b8565b810181811067ffffffffffffffff821117156104db576104da610484565b5b80604052505050565b60006104ee6102d3565b90506104fa82826104b3565b919050565b600067ffffffffffffffff82111561051a57610519610484565b5b610523826103b8565b9050602081019050919050565b82818337600083830152505050565b600061055261054d846104ff565b6104e4565b90508281526020810184848401111561056e5761056d61047f565b5b610579848285610530565b509392505050565b600082601f8301126105965761059561047a565b5b81356105a684826020860161053f565b91505092915050565b6105b881610402565b81146105c357600080fd5b50565b6000813590506105d5816105af565b92915050565b600080604083850312156105f2576105f16102dd565b5b600083013567ffffffffffffffff8111156106105761060f6102e2565b5b61061c85828601610581565b925050602061062d858286016105c6565b9150509250929050565b600060208201905061064c600083018461040c565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061069957607f821691505b6020821081036106ac576106ab610652565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006106ec82610402565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361071e5761071d6106b2565b5b600182019050919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b60006008830261078b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8261074e565b610795868361074e565b95508019841693508086168417925050509392505050565b6000819050919050565b60006107d26107cd6107c884610402565b6107ad565b610402565b9050919050565b6000819050919050565b6107ec836107b7565b6108006107f8826107d9565b84845461075b565b825550505050565b600090565b610815610808565b6108208184846107e3565b505050565b5b818110156108445761083960008261080d565b600181019050610826565b5050565b601f8211156108895761085a81610729565b6108638461073e565b81016020851015610872578190505b61088661087e8561073e565b830182610825565b50505b505050565b600082821c905092915050565b60006108ac6000198460080261088e565b1980831691505092915050565b60006108c5838361089b565b9150826002028217905092915050565b6108de82610372565b67ffffffffffffffff8111156108f7576108f6610484565b5b6109018254610681565b61090c828285610848565b600060209050601f83116001811461093f576000841561092d578287015190505b61093785826108b9565b86555061099f565b601f19841661094d86610729565b60005b8281101561097557848901518255600182019150602085019450602081019050610950565b86831015610992578489015161098e601f89168261089b565b8355505b6001600288020188555050505b50505050505056fea2646970667358221220e44475f7aaa46c12f20ccedab9992913a78a291fca9a19dab8126d65e1702c2e64736f6c63430008110033",
68+
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c806354917f8314610046578063923f5a5914610078578063c6a645fe14610094575b600080fd5b610060600480360381019061005b9190610345565b6100b2565b60405161006f9392919061043c565b60405180910390f35b610092600480360381019061008d91906105db565b610184565b005b61009c6102cd565b6040516100a99190610637565b60405180910390f35b60016020528060005260406000206000915090508060000180546100d590610681565b80601f016020809104026020016040519081016040528092919081815260200182805461010190610681565b801561014e5780601f106101235761010080835404028352916020019161014e565b820191906000526020600020905b81548152906001019060200180831161013157829003601f168201915b5050505050908060010154908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905083565b600082511161019257600080fd5b600073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16036101cb57600080fd5b600081116101d857600080fd5b6000808154809291906101ea906106e1565b919050555060405180606001604052808381526020018281526020013373ffffffffffffffffffffffffffffffffffffffff16815250600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082015181600001908161027491906108d5565b506020820151816001015560408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055509050505050565b60005481565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610312826102e7565b9050919050565b61032281610307565b811461032d57600080fd5b50565b60008135905061033f81610319565b92915050565b60006020828403121561035b5761035a6102dd565b5b600061036984828501610330565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103ac578082015181840152602081019050610391565b60008484015250505050565b6000601f19601f8301169050919050565b60006103d482610372565b6103de818561037d565b93506103ee81856020860161038e565b6103f7816103b8565b840191505092915050565b6000819050919050565b61041581610402565b82525050565b6000610426826102e7565b9050919050565b6104368161041b565b82525050565b6000606082019050818103600083015261045681866103c9565b9050610465602083018561040c565b610472604083018461042d565b949350505050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6104bc826103b8565b810181811067ffffffffffffffff821117156104db576104da610484565b5b80604052505050565b60006104ee6102d3565b90506104fa82826104b3565b919050565b600067ffffffffffffffff82111561051a57610519610484565b5b610523826103b8565b9050602081019050919050565b82818337600083830152505050565b600061055261054d846104ff565b6104e4565b90508281526020810184848401111561056e5761056d61047f565b5b610579848285610530565b509392505050565b600082601f8301126105965761059561047a565b5b81356105a684826020860161053f565b91505092915050565b6105b881610402565b81146105c357600080fd5b50565b6000813590506105d5816105af565b92915050565b600080604083850312156105f2576105f16102dd565b5b600083013567ffffffffffffffff8111156106105761060f6102e2565b5b61061c85828601610581565b925050602061062d858286016105c6565b9150509250929050565b600060208201905061064c600083018461040c565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061069957607f821691505b6020821081036106ac576106ab610652565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006106ec82610402565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361071e5761071d6106b2565b5b600182019050919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b60006008830261078b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8261074e565b610795868361074e565b95508019841693508086168417925050509392505050565b6000819050919050565b60006107d26107cd6107c884610402565b6107ad565b610402565b9050919050565b6000819050919050565b6107ec836107b7565b6108006107f8826107d9565b84845461075b565b825550505050565b600090565b610815610808565b6108208184846107e3565b505050565b5b818110156108445761083960008261080d565b600181019050610826565b5050565b601f8211156108895761085a81610729565b6108638461073e565b81016020851015610872578190505b61088661087e8561073e565b830182610825565b50505b505050565b600082821c905092915050565b60006108ac6000198460080261088e565b1980831691505092915050565b60006108c5838361089b565b9150826002028217905092915050565b6108de82610372565b67ffffffffffffffff8111156108f7576108f6610484565b5b6109018254610681565b61090c828285610848565b600060209050601f83116001811461093f576000841561092d578287015190505b61093785826108b9565b86555061099f565b601f19841661094d86610729565b60005b8281101561097557848901518255600182019150602085019450602081019050610950565b86831015610992578489015161098e601f89168261089b565b8355505b6001600288020188555050505b50505050505056fea2646970667358221220e44475f7aaa46c12f20ccedab9992913a78a291fca9a19dab8126d65e1702c2e64736f6c63430008110033",
69+
"linkReferences": {},
70+
"deployedLinkReferences": {}
71+
}

‎client/getUID.js

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
const { ethers } = require("ethers");
2+
const HDWalletProvider = require("@truffle/hdwallet-provider");
3+
4+
// Get the EOA and provider from you choice of your wallet.
5+
const pkey = "pkey";
6+
const polygonRPC = "https://rpc-mumbai.maticvigil.com/";
7+
const main = async () => {
8+
let provider = new HDWalletProvider(pkey, polygonRPC);
9+
const walletProvider = new ethers.providers.Web3Provider(provider);
10+
11+
const fileInterface = new ethers.utils.Interface([
12+
{
13+
inputs: [
14+
{
15+
internalType: "address payable",
16+
name: "viewerNode",
17+
type: "address",
18+
},
19+
],
20+
name: "fetchModel",
21+
outputs: [
22+
{
23+
internalType: "string",
24+
name: "",
25+
type: "string",
26+
},
27+
],
28+
stateMutability: "view",
29+
type: "function",
30+
},
31+
{
32+
inputs: [],
33+
name: "modelCount",
34+
outputs: [
35+
{
36+
internalType: "uint256",
37+
name: "",
38+
type: "uint256",
39+
},
40+
],
41+
stateMutability: "view",
42+
type: "function",
43+
},
44+
{
45+
inputs: [
46+
{
47+
internalType: "address",
48+
name: "",
49+
type: "address",
50+
},
51+
],
52+
name: "models",
53+
outputs: [
54+
{
55+
internalType: "string",
56+
name: "modelHash",
57+
type: "string",
58+
},
59+
{
60+
internalType: "uint256",
61+
name: "fileSize",
62+
type: "uint256",
63+
},
64+
{
65+
internalType: "address payable",
66+
name: "node",
67+
type: "address",
68+
},
69+
],
70+
stateMutability: "view",
71+
type: "function",
72+
},
73+
{
74+
inputs: [
75+
{
76+
internalType: "string",
77+
name: "_modelHash",
78+
type: "string",
79+
},
80+
{
81+
internalType: "uint256",
82+
name: "_modelSize",
83+
type: "uint256",
84+
},
85+
{
86+
internalType: "address payable",
87+
name: "callerNode",
88+
type: "address",
89+
},
90+
],
91+
name: "uploadModel",
92+
outputs: [],
93+
stateMutability: "nonpayable",
94+
type: "function",
95+
},
96+
]);
97+
98+
const fileContract = new ethers.Contract(
99+
"",
100+
fileInterface,
101+
walletProvider
102+
);
103+
104+
let fetchedHash = await fileContract.fetchModel(
105+
""
106+
);
107+
console.log("Fetched Hash", fetchedHash);
108+
};
109+
main();

‎client/retrieve.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Decrypt file nodejs
2+
const {ethers} = require("ethers");
3+
const fs = require("fs");
4+
const lighthouse = require('@lighthouse-web3/sdk');
5+
6+
const sign_auth_message = async(publicKey, privateKey) =>{
7+
const provider = new ethers.providers.JsonRpcProvider();
8+
const signer = new ethers.Wallet(privateKey, provider);
9+
const messageRequested = (await lighthouse.getAuthMessage(publicKey)).data.message
10+
const signedMessage = await signer.signMessage(messageRequested);
11+
return(signedMessage)
12+
}
13+
14+
const decrypt = async() =>{
15+
const cid = "cid";
16+
const publicKey = "";
17+
const privateKey = "";
18+
19+
// Get file encryption key
20+
const signed_message = await sign_auth_message(publicKey, privateKey);
21+
const fileEncryptionKey = await lighthouse.fetchEncryptionKey(
22+
cid,
23+
publicKey,
24+
signed_message
25+
);
26+
27+
console.log(fileEncryptionKey.data.key);
28+
29+
// Decrypt File
30+
const decrypted = await lighthouse.decryptFile(
31+
cid,
32+
fileEncryptionKey.data.key
33+
);
34+
console.log(decrypted);
35+
36+
// Save File
37+
fs.createWriteStream("fileName.jpg").write(Buffer.from(decrypted))
38+
}
39+
40+
decrypt()

‎client/upload.js

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
require("dotenv").config();
2+
const { ethers } = require("ethers");
3+
const lighthouse = require('@lighthouse-web3/sdk');
4+
const { ChainId } = require("@biconomy/core-types");
5+
const HDWalletProvider = require("@truffle/hdwallet-provider");
6+
const SmartAccount = require("@biconomy/smart-account").default;
7+
8+
const sign_auth_message = async(publicKey, privateKey) =>{
9+
const provider = new ethers.providers.JsonRpcProvider();
10+
const signer = new ethers.Wallet(privateKey, provider);
11+
const messageRequested = (await lighthouse.getAuthMessage(publicKey)).data.message;
12+
const signedMessage = await signer.signMessage(messageRequested);
13+
return(signedMessage)
14+
}
15+
16+
const deployEncrypted = async() =>{
17+
const path = ""; //Give absolute path
18+
const apiKey = "";
19+
const publicKey = "";
20+
const privateKey = "";
21+
const signed_message = await sign_auth_message(publicKey, privateKey);
22+
23+
const response = await lighthouse.uploadEncrypted(
24+
path,
25+
apiKey,
26+
publicKey,
27+
signed_message
28+
);
29+
return response.data.Hash
30+
}
31+
32+
const pkey = "";
33+
const polygonRPC = "https://rpc-mumbai.maticvigil.com/";
34+
35+
const main = async () => {
36+
const Model_Hash = await deployEncrypted();
37+
console.log(Model_Hash)
38+
let provider = new HDWalletProvider(pkey, polygonRPC);
39+
const walletProvider = new ethers.providers.Web3Provider(provider);
40+
let options = {
41+
activeNetworkId: ChainId.POLYGON_MUMBAI,
42+
supportedNetworksIds: [ChainId.POLYGON_MUMBAI],
43+
networkConfig: [
44+
{
45+
chainId: ChainId.POLYGON_MUMBAI,
46+
dappAPIKey: "",
47+
},
48+
],
49+
};
50+
51+
let smartAccount = new SmartAccount(walletProvider, options);
52+
smartAccount = await smartAccount.init();
53+
54+
// Transaction subscription
55+
56+
smartAccount.on("txHashGenerated", (response) => {
57+
console.log("txHashGenerated event received via emitter", response);
58+
});
59+
60+
smartAccount.on("txMined", (response) => {
61+
console.log("txMined event received via emitter", response);
62+
});
63+
64+
smartAccount.on("error", (response) => {
65+
console.log("error event received via emitter", response);
66+
});
67+
68+
const fileInterface = new ethers.utils.Interface([
69+
{
70+
inputs: [
71+
{
72+
internalType: "address payable",
73+
name: "viewerNode",
74+
type: "address",
75+
},
76+
],
77+
name: "fetchModel",
78+
outputs: [
79+
{
80+
internalType: "string",
81+
name: "",
82+
type: "string",
83+
},
84+
],
85+
stateMutability: "view",
86+
type: "function",
87+
},
88+
{
89+
inputs: [],
90+
name: "modelCount",
91+
outputs: [
92+
{
93+
internalType: "uint256",
94+
name: "",
95+
type: "uint256",
96+
},
97+
],
98+
stateMutability: "view",
99+
type: "function",
100+
},
101+
{
102+
inputs: [
103+
{
104+
internalType: "address",
105+
name: "",
106+
type: "address",
107+
},
108+
],
109+
name: "models",
110+
outputs: [
111+
{
112+
internalType: "string",
113+
name: "modelHash",
114+
type: "string",
115+
},
116+
{
117+
internalType: "uint256",
118+
name: "fileSize",
119+
type: "uint256",
120+
},
121+
{
122+
internalType: "address payable",
123+
name: "node",
124+
type: "address",
125+
},
126+
],
127+
stateMutability: "view",
128+
type: "function",
129+
},
130+
{
131+
inputs: [
132+
{
133+
internalType: "string",
134+
name: "_modelHash",
135+
type: "string",
136+
},
137+
{
138+
internalType: "uint256",
139+
name: "_modelSize",
140+
type: "uint256",
141+
},
142+
{
143+
internalType: "address payable",
144+
name: "callerNode",
145+
type: "address",
146+
},
147+
],
148+
name: "uploadModel",
149+
outputs: [],
150+
stateMutability: "nonpayable",
151+
type: "function",
152+
},
153+
]);
154+
155+
console.log(Model_Hash)
156+
157+
const data = fileInterface.encodeFunctionData("uploadModel", [
158+
Model_Hash,
159+
1000,
160+
"",
161+
]);
162+
163+
const tx1 = {
164+
to: "",
165+
data: data,
166+
// value can also be added for example ethers.utils.parseEther("1")
167+
};
168+
169+
// Gasless
170+
const txResponse = await smartAccount.sendGasLessTransaction({
171+
transaction: tx1,
172+
});
173+
};
174+
main();

‎contracts/file.sol

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.9;
3+
4+
contract file {
5+
uint256 public modelCount = 0;
6+
7+
mapping(address => Model) public models;
8+
9+
struct Model {
10+
string modelHash;
11+
uint256 fileSize;
12+
address payable node;
13+
}
14+
15+
function uploadModel(string memory _modelHash, uint256 _modelSize,address payable callerNode) public {
16+
require(bytes(_modelHash).length > 0);
17+
require(msg.sender != address(0));
18+
require(_modelSize > 0);
19+
modelCount++;
20+
models[callerNode] = Model(_modelHash, _modelSize,callerNode);
21+
}
22+
23+
function fetchModel(address payable viewerNode) public view returns (string memory) {
24+
return models[viewerNode].modelHash;
25+
}
26+
}

‎hardhat.config.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { HardhatUserConfig } from "hardhat/config";
2+
import "@nomicfoundation/hardhat-toolbox";
3+
import dotenv from "dotenv";
4+
dotenv.config();
5+
6+
const config: HardhatUserConfig = {
7+
solidity: "0.8.17",
8+
defaultNetwork: "polygon_mumbai",
9+
networks: {
10+
polygon_mumbai: {
11+
url: `${process.env.API_URL}`,
12+
accounts: [`0x${process.env.PRIVATE_KEY}`],
13+
},
14+
},
15+
};
16+
17+
export default config;

‎package-lock.json

+34,553
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"devDependencies": {
3+
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
4+
"hardhat": "^2.12.2"
5+
},
6+
"dependencies": {
7+
"@biconomy/smart-account": "^0.0.4",
8+
"@lighthouse-web3/sdk": "^0.1.9",
9+
"@truffle/hdwallet-provider": "^2.1.2",
10+
"dotenv": "^16.0.3",
11+
"ethers": "^5.7.2",
12+
"fs": "^0.0.1-security"
13+
}
14+
}

‎scripts/deploy.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ethers } from "hardhat";
2+
3+
async function main() {
4+
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
5+
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
6+
const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
7+
8+
const File = await ethers.getContractFactory("file");
9+
const file = await File.deploy();
10+
11+
await file.deployed();
12+
13+
console.log(`File with 1 ETH and unlock timestamp ${unlockTime} deployed to ${file.address}`);
14+
}
15+
16+
// We recommend this pattern to be able to use async/await everywhere
17+
// and properly handle errors.
18+
main().catch((error) => {
19+
console.error(error);
20+
process.exitCode = 1;
21+
});

‎tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2020",
4+
"module": "commonjs",
5+
"esModuleInterop": true,
6+
"forceConsistentCasingInFileNames": true,
7+
"strict": true,
8+
"skipLibCheck": true,
9+
"resolveJsonModule": true,
10+
}
11+
}

0 commit comments

Comments
 (0)
Please sign in to comment.