Custom connector

Initializing with a custom connector

Initialize the library using an a custom connector object is useful when the developer does not have the private key of the account but to a library that handles it.
Javascript & Node
1
const defire = Defire({
2
connector: myCustomConnector,
3
address: "0x41186AE17A2a11B7259D8c60b40AFd0256b9DdC7"
4
}, { network: 'rinkeby' });
Copied!
Method parameters
mainAccount required object :
    connector required Connector object (Ethereum API custom object)
    address required string (Ethereum address of the main account to use)
Params to load the main account from a private key
options optional object
Configuration options for Defire Platform.

Connector object

Field / Method
Description
send(params) => object
Method to submit JSON-RPC request. Returns response object.
sign(string) => { v, r, s}
Method to sign. Returns signature.

Example:

Node
1
const ethUtils = require("ethereumjs-utils");
2
3
//Main account
4
const address = "0x41186AE17A2a11B7259D8c60b40AFd0256b9DdC7";
5
const pk = "4759582d5d163f2c269575b62d11abd99403166b036e7f828a2b3afcaa67d6a8";
6
//Provider URL
7
const provider = "https://rinkeby.infura.io/v3/16a004343234ffb464f22567147";
8
//Custom connector
9
const myCustomConnector = {
10
sign: async (msgHash) => {
11
const msgBuff = Buffer.from(ethUtils.stripHexPrefix(msgHash), "hex");
12
const sig = ethUtils.ecsign(
13
msgBuff,
14
Buffer.from(pk, "hex")
15
);
16
return sig;
17
},
18
19
send: async (params) => {
20
let response = await fetch(provider, {
21
method: "POST",
22
body: JSON.stringify(params),
23
headers: {
24
Accept: "application/json",
25
"Content-Type": "application/json",
26
},
27
});
28
let data = await response.json();
29
if (data.error) {
30
throw data.error.message;
31
}
32
return data.result;
33
},
34
};
35
36
const defire = Defire({
37
connector: myCustomConnector,
38
address: address
39
}, { network: 'rinkeby' });
Copied!
Last modified 1yr ago