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:
parent
ae8ba51c84
commit
787e4d6fef
|
|
@ -28,6 +28,7 @@
|
||||||
"@middy/http-json-body-parser": "^4.2.7",
|
"@middy/http-json-body-parser": "^4.2.7",
|
||||||
"@middy/http-response-serializer": "^4.2.8",
|
"@middy/http-response-serializer": "^4.2.8",
|
||||||
"aws-sdk": "^2.1342.0",
|
"aws-sdk": "^2.1342.0",
|
||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0",
|
||||||
|
"web3": "^1.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { APIGatewayProxyResult } from 'aws-lambda';
|
||||||
import { formatJSONResponse } from '@libs/api-gateway';
|
import { formatJSONResponse } from '@libs/api-gateway';
|
||||||
|
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
import { nfaContract } from '@libs/nfa-contract';
|
||||||
|
|
||||||
export const submitBuildInfo = async (): Promise<APIGatewayProxyResult> => {
|
export const submitBuildInfo = async (): Promise<APIGatewayProxyResult> => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -11,6 +12,15 @@ export const submitBuildInfo = async (): Promise<APIGatewayProxyResult> => {
|
||||||
createdAt: new Date().toISOString(),
|
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({
|
return formatJSONResponse({
|
||||||
buildInfo,
|
buildInfo,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -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);
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"extends": "../tsconfig.base.json",
|
"extends": "../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
"lib": ["ESNext"],
|
"lib": ["ESNext"],
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
|
|
|
||||||
1926
serverless/yarn.lock
1926
serverless/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue