contract interaction scripts

This commit is contained in:
mingda
2020-06-27 18:01:18 +08:00
parent ee88b6c358
commit 44d1f28606
3 changed files with 7 additions and 6 deletions

1
.gitignore vendored
View File

@@ -10,6 +10,7 @@ docs/src
node_modules/ node_modules/
coverage/ coverage/
lint/ lint/
script/
# VIM # VIM
*.swo *.swo

View File

@@ -35,7 +35,7 @@ interface ContractJson {
byteCode: string; byteCode: string;
} }
function _getContractJSON(contractName: string): ContractJson { export function getContractJSON(contractName: string): ContractJson {
switch (contractName) { switch (contractName) {
case DODO_CONTRACT_NAME: case DODO_CONTRACT_NAME:
return { return {
@@ -85,22 +85,22 @@ function _getContractJSON(contractName: string): ContractJson {
} }
export function getContractWithAddress(contractName: string, address: string) { export function getContractWithAddress(contractName: string, address: string) {
var Json = _getContractJSON(contractName) var Json = getContractJSON(contractName)
var web3 = getDefaultWeb3() var web3 = getDefaultWeb3()
return new web3.eth.Contract(Json.abi, address) return new web3.eth.Contract(Json.abi, address)
} }
export function getDepolyedContract(contractName: string): Contract { export function getDepolyedContract(contractName: string): Contract {
var Json = _getContractJSON(contractName) var Json = getContractJSON(contractName)
var networkId = process.env.NETWORK_ID var networkId = process.env.NETWORK_ID
var deployedAddress = _getContractJSON(contractName).networks[networkId].address var deployedAddress = getContractJSON(contractName).networks[networkId].address
var web3 = getDefaultWeb3() var web3 = getDefaultWeb3()
return new web3.eth.Contract(Json.abi, deployedAddress) return new web3.eth.Contract(Json.abi, deployedAddress)
} }
export async function newContract(contractName: string, args: any[] = []): Promise<Contract> { export async function newContract(contractName: string, args: any[] = []): Promise<Contract> {
var web3 = getDefaultWeb3() var web3 = getDefaultWeb3()
var Json = _getContractJSON(contractName) var Json = getContractJSON(contractName)
var contract = new web3.eth.Contract(Json.abi) var contract = new web3.eth.Contract(Json.abi)
var adminAccount = (await web3.eth.getAccounts())[0] var adminAccount = (await web3.eth.getAccounts())[0]
let parameter = { let parameter = {

View File

@@ -15,7 +15,7 @@
"typeRoots": ["node_modules/@types"], "typeRoots": ["node_modules/@types"],
"types": ["node", "mocha", "chai"] "types": ["node", "mocha", "chai"]
}, },
"include": ["src", "test"], "include": ["src", "test", "script"],
"exclude": ["scripts/**/*", "build/**/*", "migrations/**/*"], "exclude": ["scripts/**/*", "build/**/*", "migrations/**/*"],
"compileOnSave": true "compileOnSave": true
} }