forked from fireblocks/fireblocks-defi-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
erc1155.ts
55 lines (40 loc) · 1.78 KB
/
erc1155.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
import * as fs from "fs";
import {BridgeParams, Chain, ERC1155, FireblocksSDK} from "fireblocks-defi-sdk";
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 you Fireblocks Api Seacret 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
}
// Initialize ERC721 Token with Fireblocks Bridge parameters
const erc1155 = new ERC1155(bridgeParams);
const RECEIVER_ADDRESS = '';
const TOKEN_ID = 1;
/** Read/Write Examples **/
// Perform a read balanceOf action
const balance = await erc1155.balanceOf(TOKEN_ID);
console.log('balanceOf response', balance);
// Perform write setApprovalForAll action
const setApprovalForAllResult = await erc1155.setApprovalForAll(RECEIVER_ADDRESS, true);
console.log('setApprovalForAll response', setApprovalForAllResult);
}()).catch(err => {
console.log("error", err);
process.exit(1);
});