-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made private keys optional in Accounts. Added a ContractLoader so you…
… can get a reference to an already deployed contract. Made EOS Manager more configurable so you can connect to other endpoints and chains.
- Loading branch information
1 parent
bdebc8d
commit 8adf7ce
Showing
6 changed files
with
111 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Contract } from './contract'; | ||
import { Account } from '../accounts'; | ||
import { EOSManager } from '../eosManager'; | ||
|
||
/** | ||
* Provides a set of methods to create contract references for already existing contracts | ||
*/ | ||
export class ContractLoader { | ||
/** | ||
* Loads a contract instance for a contract which is already deployed to the blockchain. | ||
* | ||
* ```typescript | ||
* ContractLoader.at<MyContractTypeDef>('mycontract'); | ||
* ``` | ||
* @author Kevin Brown <github.com/thekevinbrown> | ||
* @param accountName The account name where the contract is already deployed. | ||
* @returns Contract instance | ||
*/ | ||
public static async at<T extends Contract>(account: Account) { | ||
// Load the ABI from the blockchain. | ||
const { abi } = await EOSManager.rpc.get_abi(account.name); | ||
|
||
if (!abi) throw new Error(`Could not load ABI for contract at '${account.name}'.`); | ||
|
||
// Fetch the contract actions and types | ||
const { actions, types } = await EOSManager.api.getContract(account.name); | ||
|
||
// Return our newly deployed contract instance | ||
return new Contract({ | ||
eos: EOSManager.api, | ||
account, | ||
abi, | ||
actions, | ||
types, | ||
}) as T; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './contract'; | ||
export * from './contractDeployer'; | ||
export * from './contractLoader'; | ||
export * from './tableRowsResult'; | ||
export * from './typeGenerator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters