The Zap class binding for the Zap Oracle smart contract. Exposes state changing functionalities including staking, mining, and disputing.
- Zap
-
new Zap(chainId: number, signer: Signer): Zap
-
- Defined in zap.ts:19
Constructor
-
The network chain ID Zap is associated with
-
The signer of transactions
chainId: number
- Defined in zap.ts:11
signer: Signer
- Defined in zap.ts:12
-
addTip(id: number, value: number): Promise<any>
-
- Defined in zap.ts:76
Add a tip to Request value within the Oracle
-
The ID of the request to add the tip to
-
The amount of tip to add
The Promise transaction object
-
approveSpending(value: number): Promise<any>
-
- Defined in zap.ts:35
Approves the ZapMaster contract as the signer. This is required before and transfer of funds.
-
The amount to be approved
The Promise bool of success
-
dispute(_requestId: string, _timestamp: string, _minerId: string): Promise<any>
-
- Defined in zap.ts:88
Begins a new dispute of specified request, timestamp, and miner.
-
The ID of the request to dispute
-
The timestamp of the request
-
The index ID of the miner of block to dispute
The Promise transaction object
-
requestWithdraw(): Promise<any>
-
- Defined in zap.ts:58
Initiates the request for withdraw of the stake and Oracle rewards. Must wait 7 days until withdrawl can be made.
The Promise transaction object
-
stake(): Promise<any>
-
- Defined in zap.ts:50
Desposits the Oracle stake. Ensure the signer has the stake balance and approves the ZapMaster.
The Promise transaction object
-
tallyVotes(disputeId: number): Promise<any>
-
- Defined in zap.ts:107
Tallies the votes made for a dispute
-
The Id of the dispute to resolve
The Promise transaction object
-
vote(disputeId: number, vote: boolean): Promise<any>
-
- Defined in zap.ts:98
Votes for or against a dispute.
-
The Id of the dispute to resolve
-
The boolean vote value
The Promise transaction object
-
withdraw(): Promise<any>
-
- Defined in zap.ts:66
Withdraws the stake and Oracle rewards. Signer must have requested for withdraw 7 days prior.
The Promise transaction object
For this example, we are using chainId 4 and a Rinkeby provider node. The chainId and provider node can be replaced with the other available chainId's supported by Zap.
// Requires dotenv to allow the reading of environment variables
require("dotenv").config();
// Rinkeby chainId
const rinkebyChainId = 4;
// Requires the Zap class
const { Zap } = require('@zapprotocol/oracle-sdk');
// Requires the ethers.js library
const ethers = require("ethers");
// Infura Rinkeby URL
const testnetUrl = `https://rinkeby.infura.io/v3/${process.env.PROJECT_ID}`;
// Creates the instance for the Rinkeby testnet provider
const provider = new ethers.providers.JsonRpcProvider(
testnetUrl,
rinkebyChainId
);
// Creates the signer instance with the users private key and provider
const signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
// Creates the Zap class instance on the Rinkeby testnet with the signer connected
const zap = new Zap(rinkebyChainId, signer);
const main = async () => {
let tx = await zap.stake();
};
main();