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
const defire = Defire({
connector: myCustomConnector,
address: "0x41186AE17A2a11B7259D8c60b40AFd0256b9DdC7"
}, { network: 'rinkeby' });
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
const ethUtils = require("ethereumjs-utils");
//Main account
const address = "0x41186AE17A2a11B7259D8c60b40AFd0256b9DdC7";
const pk = "4759582d5d163f2c269575b62d11abd99403166b036e7f828a2b3afcaa67d6a8";
//Provider URL
const provider = "https://rinkeby.infura.io/v3/16a004343234ffb464f22567147";
//Custom connector
const myCustomConnector = {
sign: async (msgHash) => {
const msgBuff = Buffer.from(ethUtils.stripHexPrefix(msgHash), "hex");
const sig = ethUtils.ecsign(
msgBuff,
Buffer.from(pk, "hex")
);
return sig;
},
send: async (params) => {
let response = await fetch(provider, {
method: "POST",
body: JSON.stringify(params),
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
let data = await response.json();
if (data.error) {
throw data.error.message;
}
return data.result;
},
};
const defire = Defire({
connector: myCustomConnector,
address: address
}, { network: 'rinkeby' });
Last modified 2yr ago