feat: create smart contract helper for serverless (#232)

* feat: add log decoder helper and import web3.

* feat: create the web3 helper and install the package. update ts config to use JSONs in the helper script.

* feat: use nfaContract in submitBuildInfo handler.

* refactor: make the setTokenBuild params self-explanatory.

* docs: comment the placeholder.
This commit is contained in:
Shredder 2023-04-27 13:47:35 +03:30 committed by GitHub
parent ae8ba51c84
commit 787e4d6fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1937 additions and 21 deletions

View File

@ -28,6 +28,7 @@
"@middy/http-json-body-parser": "^4.2.7",
"@middy/http-response-serializer": "^4.2.8",
"aws-sdk": "^2.1342.0",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"web3": "^1.9.0"
}
}

View File

@ -2,6 +2,7 @@ import { APIGatewayProxyResult } from 'aws-lambda';
import { formatJSONResponse } from '@libs/api-gateway';
import { v4 } from 'uuid';
import { nfaContract } from '@libs/nfa-contract';
export const submitBuildInfo = async (): Promise<APIGatewayProxyResult> => {
try {
@ -11,6 +12,15 @@ export const submitBuildInfo = async (): Promise<APIGatewayProxyResult> => {
createdAt: new Date().toISOString(),
};
// place holder call
nfaContract.methods
.setTokenBuild(1, 'hash', 'repo')
.call((err: string | undefined, res: any) => {
if (err) throw new Error(err);
console.log('result');
console.log(res);
});
return formatJSONResponse({
buildInfo,
});

View File

@ -0,0 +1,8 @@
var Web3 = require('web3');
var web3 = new Web3(Web3.givenProvider || "ws://localhost:17895");
export const logDecoder = (eventFieldsABI: { indexed: boolean; internalType: string; name: string; type: string; }[], data: string, topics: string[]) => {
return web3.eth.abi.decodeLog(eventFieldsABI, data, topics);
};

View File

@ -0,0 +1,9 @@
import Web3 from 'web3';
import * as abiFile from '../../../contracts/deployments/goerli/FleekERC721.json';
const contract_address = abiFile.address;
const abi = abiFile.abi as any;
const web3 = new Web3('https://rpc.goerli.mudit.blog');
export const nfaContract = new web3.eth.Contract(abi, contract_address);

View File

@ -1,6 +1,8 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"esModuleInterop": true,
"resolveJsonModule": true,
"lib": ["ESNext"],
"moduleResolution": "node",
"noUnusedLocals": true,

File diff suppressed because it is too large Load Diff