-
Notifications
You must be signed in to change notification settings - Fork 31
/
custom-token.ts
60 lines (43 loc) · 1.98 KB
/
custom-token.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as fs from "fs";
import {BridgeParams, Chain, CustomToken, FireblocksSDK} from "fireblocks-defi-sdk";
import {ABIStructure} from "../../dist/types/abi";
const CHAIN = Chain.KOVAN;
const CONTRACT_ADDRESS = "";
const FIREBLOCKS_API_SECRET_PATH = '../../../fireblocks.key';
const FIREBLOCKS_API_KEY_PATH = '../../api-client-key.txt';
/**
* Following example describes how to crate a ERC721 token connection, and
* perform read and write actions using Fireblocks infrastructure.
*/
(async function () {
/** Fireblocks Initialization **/
// Read file containing your Fireblocks Api Secret Key
const apiSecret = fs.readFileSync(FIREBLOCKS_API_SECRET_PATH, "utf8");
// Read file containing you Fireblocks Api Key
const apiKey = fs.readFileSync(FIREBLOCKS_API_KEY_PATH, "utf8");
// Initialize Fireblocks SDK
const fireblocksApiClient: FireblocksSDK = new FireblocksSDK(apiSecret, apiKey, process.env.FIREBLOCKS_API_BASE_URL);
// Build Bridge parameters to you Fireblocks account.
const bridgeParams: BridgeParams = {
fireblocksApiClient,
vaultAccountId: process.env.FIREBLOCKS_SOURCE_VAULT_ACCOUNT || "0",
contractAddress: CONTRACT_ADDRESS,
chain: CHAIN
}
const READ_ABI: ABIStructure = [] // you can also use await Utils.fetchABI(CONTRACT_ABI_ADDRESS)
// Initialize Custom Token with Fireblocks Bridge parameters
const customToken = new CustomToken(bridgeParams, READ_ABI);
/** Read/Write Examples **/
const FROM_ADDRESS = '';
const TO_ADDRESS = '';
const TOKEN_ID = 0;
// Perform read via balanceOf
const balanceOf = await customToken.callReadFunction('balanceOf');
console.log('balanceOf response', balanceOf);
// Perform write via transferFrom
const transferFrom = await customToken.callWriteFunction('transferFrom', FROM_ADDRESS, TO_ADDRESS, TOKEN_ID);
console.log('transferFrom response', transferFrom);
}()).catch(err => {
console.log("error", err);
process.exit(1);
});