use truffle contracts in dapp and scripts
This commit is contained in:
parent
9f4a48e282
commit
8978ae31e2
|
@ -11,4 +11,5 @@ embarkArtifacts
|
|||
node_modules
|
||||
yarn-error.log
|
||||
/src/react-app-env.d.ts
|
||||
/scripts/contracts
|
||||
/client/src/react-app-env.d.ts
|
||||
/client/src/contracts
|
||||
|
|
16
Makefile
16
Makefile
|
@ -1,19 +1,17 @@
|
|||
-include .env
|
||||
|
||||
CONTRACTS_PATH="./contracts"
|
||||
# CONTRACTS_PATH="./contracts"
|
||||
RELAYER_CONTRACTS_PATH=$$(realpath ./scripts/contracts-build)
|
||||
RELAYER_DOCKER_FILE="./_assets/Dockerfile.relayer"
|
||||
RELAYER_DOCKER_IMAGE="redeem-relayer"
|
||||
RELAYER_DOCKER_CONTAINER_NAME="redeem-relayer"
|
||||
RELAYER_CONTRACTS_PATH=$$(realpath ./scripts/contracts)
|
||||
CONTAINER_KEYSTORES_PATH="/usr/keystores"
|
||||
|
||||
build-relayer-contracts:
|
||||
rm -rf $(RELAYER_CONTRACTS_PATH); \
|
||||
yarn run solcjs -o $(RELAYER_CONTRACTS_PATH) --bin --abi $$(find $(CONTRACTS_PATH) -name *.sol); \
|
||||
for fileName in $$(ls $(RELAYER_CONTRACTS_PATH)); do \
|
||||
newName=$${fileName##*_}; \
|
||||
mv $(RELAYER_CONTRACTS_PATH)/$${fileName} $(RELAYER_CONTRACTS_PATH)/$${newName}; \
|
||||
done;
|
||||
compile-contracts:
|
||||
truffle compile
|
||||
|
||||
deploy-contracts: compile-contracts
|
||||
truffle deploy
|
||||
|
||||
check-relayer-env-variables:
|
||||
ifndef ENDPOINT
|
||||
|
|
|
@ -40,28 +40,14 @@
|
|||
"solc": "^0.6.10",
|
||||
"typeface-roboto": "^0.0.75",
|
||||
"typescript": "^3.8.3",
|
||||
"web3": "^1.2.7",
|
||||
"web3-eth": "1.2.7"
|
||||
"web3": "^1.2.11",
|
||||
"web3-eth": "1.2.11"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/classnames": "^2.2.10",
|
||||
"embark": "^5.3.0-nightly.7",
|
||||
"embark-geth": "^5.3.0-nightly.7",
|
||||
"embark-graph": "^5.3.0-nightly.7",
|
||||
"embark-ipfs": "^5.3.0-nightly.7",
|
||||
"embark-parity": "^5.3.0-nightly.7",
|
||||
"embark-profiler": "^5.3.0-nightly.7",
|
||||
"embark-swarm": "^5.3.0-nightly.7",
|
||||
"embark-whisper-geth": "^5.3.0-nightly.7",
|
||||
"embarkjs": "^5.3.0-nightly.6",
|
||||
"embarkjs-ens": "^5.3.0-nightly.6",
|
||||
"embarkjs-ipfs": "^5.3.0-nightly.4",
|
||||
"embarkjs-swarm": "^5.3.0-nightly.4",
|
||||
"embarkjs-web3": "^5.3.0-nightly.4",
|
||||
"embarkjs-whisper": "^5.3.0-nightly.4"
|
||||
"@types/classnames": "^2.2.10"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
|
|
|
@ -95,6 +95,7 @@ export const redeem = (bucketAddress: string, recipientAddress: string, cleanCod
|
|||
}
|
||||
|
||||
dispatch(redeeming());
|
||||
|
||||
const state = getState();
|
||||
const web3Type = state.web3.type;
|
||||
|
||||
|
@ -128,7 +129,6 @@ export const redeem = (bucketAddress: string, recipientAddress: string, cleanCod
|
|||
}
|
||||
|
||||
dispatch<any>(sendTransaction(account, bucket, bucketAddress, message, sig));
|
||||
|
||||
}).catch((err: any) => {
|
||||
console.error("sign redeem error reason:", err.reason);
|
||||
console.error("sign redeem error:", err);
|
||||
|
@ -202,8 +202,7 @@ const signWithWeb3 = (signer: string, data: any): Promise<SignRedeemResponse> =>
|
|||
|
||||
const signWithKeycard = (data: any): Promise<SignRedeemResponse> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
(window as any).ethereum.send("keycard_signTypedData", JSON.stringify(data)).then((resp: any) => {
|
||||
const sig = resp.result;
|
||||
(window as any).ethereum.send("keycard_signTypedData", JSON.stringify(data)).then((sig: any) => {
|
||||
const signer = recoverTypedSignature({
|
||||
data,
|
||||
sig
|
||||
|
@ -219,6 +218,7 @@ const signWithKeycard = (data: any): Promise<SignRedeemResponse> => {
|
|||
const sendTransaction = (account: string, bucket: any, bucketAddress: string, message: RedeemMessage, sig: string) => {
|
||||
return (dispatch: Dispatch, getState: () => RootState) => {
|
||||
bucket.methods.relayerURI().call().then((uri: string) => {
|
||||
dispatch(debug(`relayer URI: ${uri}`));
|
||||
if (uri === "") {
|
||||
dispatch<any>(sendEthTransaction(account, bucket, message, sig));
|
||||
} else {
|
||||
|
|
|
@ -1,14 +1,27 @@
|
|||
import { RootState } from '../reducers';
|
||||
import ERC20BucketFactory from '../embarkArtifacts/contracts/ERC20BucketFactory';
|
||||
import NFTBucketFactory from '../embarkArtifacts/contracts/NFTBucketFactory';
|
||||
import ERC20Bucket from '../embarkArtifacts/contracts/ERC20Bucket';
|
||||
import Bucket from '../embarkArtifacts/contracts/Bucket';
|
||||
import IERC20Detailed from '../embarkArtifacts/contracts/IERC20Detailed';
|
||||
import IERC721Metadata from '../embarkArtifacts/contracts/IERC721Metadata';
|
||||
import ERC20BucketFactory from '../contracts/ERC20BucketFactory.json';
|
||||
import NFTBucketFactory from '../contracts/NFTBucketFactory.json';
|
||||
import ERC20Bucket from '../contracts/ERC20Bucket.json';
|
||||
import Bucket from '../contracts/Bucket.json';
|
||||
import IERC20Detailed from '../contracts/IERC20Detailed.json';
|
||||
import IERC721Metadata from '../contracts/IERC721Metadata.json';
|
||||
import { config } from "../config";
|
||||
import { Dispatch } from 'redux';
|
||||
import { ZERO_ADDRESS } from "../utils";
|
||||
import { debug } from "./debug";
|
||||
import { AbiItem } from "web3-utils";
|
||||
|
||||
interface ContractSpecs {
|
||||
networks: {
|
||||
[id: string]: {
|
||||
address: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const contractAddress = (specs: ContractSpecs, networkID: string | number): string => {
|
||||
return specs.networks[networkID.toString()].address;
|
||||
}
|
||||
|
||||
export const ERROR_REDEEMABLE_NOT_FOUND = "ERROR_REDEEMABLE_NOT_FOUND";
|
||||
export interface ErrRedeemableNotFound {
|
||||
|
@ -166,21 +179,22 @@ export const tokenMetadataLoaded = (tokenAddress: string, recipient: string, met
|
|||
});
|
||||
|
||||
export const newBucketContract = (address: string) => {
|
||||
const bucketAbi = Bucket.options.jsonInterface;
|
||||
const bucketAbi = Bucket.abi as AbiItem[];
|
||||
const bucket = new config.web3!.eth.Contract(bucketAbi, address);
|
||||
return bucket;
|
||||
}
|
||||
|
||||
export const newERC20BucketContract = (address: string) => {
|
||||
const bucketAbi = ERC20Bucket.options.jsonInterface;
|
||||
const bucketAbi = ERC20Bucket.abi as AbiItem[];
|
||||
const bucket = new config.web3!.eth.Contract(bucketAbi, address);
|
||||
return bucket;
|
||||
}
|
||||
|
||||
export const loadRedeemable = (bucketAddress: string, recipientAddress: string) => {
|
||||
return async (dispatch: Dispatch, getState: () => RootState) => {
|
||||
dispatch(debug(`erc20 factory address: ${ERC20BucketFactory.address}`));
|
||||
dispatch(debug(`nft factory address: ${NFTBucketFactory.address}`));
|
||||
const networkID = getState().web3.networkID!;
|
||||
dispatch(debug(`erc20 factory address: ${contractAddress(ERC20BucketFactory, networkID)}`));
|
||||
dispatch(debug(`nft factory address: ${contractAddress(NFTBucketFactory, networkID)}`));
|
||||
dispatch(debug(`bucket address: ${bucketAddress}`));
|
||||
dispatch(debug(`recipient address: ${recipientAddress}`));
|
||||
dispatch(loadingRedeemable(bucketAddress, recipientAddress));
|
||||
|
@ -232,7 +246,7 @@ export const loadToken = (bucket: any, data: string, recipient: string) => {
|
|||
export const loadERC20Token = (bucket: any, data: string, recipient: string) => {
|
||||
return (dispatch: Dispatch, getState: () => RootState) => {
|
||||
bucket.methods.tokenAddress().call().then(async (address: string) => {
|
||||
const erc20Abi = IERC20Detailed.options.jsonInterface;
|
||||
const erc20Abi = IERC20Detailed.abi as AbiItem[];
|
||||
const erc20 = new config.web3!.eth.Contract(erc20Abi, address);
|
||||
dispatch(loadingToken(address));
|
||||
|
||||
|
@ -251,7 +265,7 @@ export const loadERC20Token = (bucket: any, data: string, recipient: string) =>
|
|||
export const loadNFTToken = (bucket: any, data: string, recipient: string) => {
|
||||
return (dispatch: Dispatch, getState: () => RootState) => {
|
||||
bucket.methods.tokenAddress().call().then(async (address: string) => {
|
||||
const nftAbi = IERC721Metadata.options.jsonInterface;
|
||||
const nftAbi = IERC721Metadata.abi as AbiItem[];
|
||||
const nft = new config.web3!.eth.Contract(nftAbi, address);
|
||||
dispatch(loadingToken(address));
|
||||
|
||||
|
|
|
@ -6,8 +6,11 @@ import {
|
|||
import { RootState } from '../reducers';
|
||||
import { debug } from "./debug";
|
||||
|
||||
export const VALID_NETWORK_NAME = "Ropsten";
|
||||
export const VALID_NETWORK_ID = 3;
|
||||
export const VALID_NETWORK_NAME = "Ganache";
|
||||
export const VALID_NETWORK_ID = 5777;
|
||||
|
||||
// export const VALID_NETWORK_NAME = "Ropsten";
|
||||
// export const VALID_NETWORK_ID = 3;
|
||||
|
||||
// export const VALID_NETWORK_NAME = "Goerli";
|
||||
// export const VALID_NETWORK_ID = 5;
|
||||
|
|
8668
client/yarn.lock
8668
client/yarn.lock
File diff suppressed because it is too large
Load Diff
|
@ -8,6 +8,9 @@
|
|||
"express": "^4.17.1",
|
||||
"minimist": "^1.2.5",
|
||||
"morgan": "^1.10.0",
|
||||
"solc": "0.5.16",
|
||||
"web3": "^1.2.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const CONTRACTS_PATH="./contracts";
|
||||
const CONTRACTS_PATH="./client/src/contracts";
|
||||
|
||||
module.exports.loadContractFile = (fileName) => {
|
||||
let content = fs.readFileSync(path.join(__dirname, CONTRACTS_PATH, fileName), "utf-8");
|
||||
let content = fs.readFileSync(path.join(__dirname, "../", CONTRACTS_PATH, `${fileName}.json`), "utf-8");
|
||||
return content;
|
||||
};
|
||||
|
||||
module.exports.loadContractCode = (contractName) => {
|
||||
return this.loadContractFile(`${contractName}.bin`);
|
||||
const content = this.loadContractFile(contractName);
|
||||
const obj = JSON.parse(content);
|
||||
return obj.bytecode;
|
||||
};
|
||||
|
||||
module.exports.loadContract = (web3, contractName) => {
|
||||
let content = this.loadContractFile(`${contractName}.abi`);
|
||||
let abi = JSON.parse(content);
|
||||
return new web3.eth.Contract(abi);
|
||||
let content = this.loadContractFile(contractName);
|
||||
const obj = JSON.parse(content);
|
||||
return new web3.eth.Contract(obj.abi);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue