contract interaction scripts
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,6 +10,7 @@ docs/src
|
|||||||
node_modules/
|
node_modules/
|
||||||
coverage/
|
coverage/
|
||||||
lint/
|
lint/
|
||||||
|
script/
|
||||||
|
|
||||||
# VIM
|
# VIM
|
||||||
*.swo
|
*.swo
|
||||||
|
|||||||
@@ -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 = {
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user