bitofme
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

bitofme

npm package to access bitofme smart contracts written in typescript

Install module

npm install bitofme

Register a test ENS Name (only for ganache/rinkeby regions. Wont work with mainnet)

const ensName = "atestname";
await bitofme.registerENSName(ensName);

Setup ENSName for BitOfMe Rental

import {BitOfMeService, SubdomainCreationRule} from 'bitofme';
 
const bitofme = new BitOfMeService("rinkeby");
const ensName = "atestname";
const referralWallet = "0xYourAddressToReceiveCommissions";
const referralFeePPK = 20; //Parts per Kilo. For 1%, enter 10. For 1.5% enter 15. 2% is 20
await bitofme.createMasterAgreementStep1(ensName, SubdomainCreationRule.DeedOwnerOnly, referralWallet, referralFeePPK); //creates the contract
await bitofme.createMasterAgreementStep2(ensName); //grants ENS name ownership

Register a subdomain

const ensName = "atestname";
const subdomainName = "mysubdomain";
const receipientWallet = "0xWalletToReceiveFunds";
const adminWallet = "0xWalletThatCanInitiateRefunds";
const encryptionKeys = bitofme.generateKeyPair();
//Input fields separated by pipe. Optional fields enclosed by []. Dropdown questions end with the options in () separated by /
const inputFields = "name|[address]|can we send you email?(yes/no)";
const maxAllowedPayment = 1000;
const fiatCurrency = "usd";
const rentalContractAddress = await bitofme.createRentalAgreement(ensName, subdomainName, receipientWallet, adminWallet, encryptionKeys.publicKey, inputFields, maxAllowedPayment, fiatCurrency); //creates the contract
console.log("rentalContractAddres", rentalContractAddress);
 

Initiate payment

const ensFullName = "mano.invoice.eth";
const plainMessage = "Jack Frost|123 Main Street, TX|fake@email.com|y";
const amount = 100.0;
const currencyCode = "usd";
const gasPrices = await bitofme.gasPriceEstimate();
const gasPriceGWeiForFastConfirmation = gasPrices.fastGWei;
const depositStatus = await bitofme.deposit(ensFullName, plainMessage, amount, currencyCode, gasPriceGWeiForFastConfirmation);
console.log(depositStatus);

Output:

true

Get encoded data for given input (to use with ledger nano s, trezor)

const ensFullName = "mano.invoice.eth";
const plainMessage = "Jack Frost|123 Main Street, TX|fake@email.com|y";
const amount = 100.0;
const currencyCode = "usd";
const encodedData = await bitofme.encodeInputs(ensFullName, plainMessage, amount, currencyCode);
console.log(encodedData);

Output:

'0x53839ece0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000025800000000000000000000000000000000000000000000000000000000000000c23033333365656335383364303461353563653061626139646266623034303335653863366465346635303165636339623236633038666135303161356563313530376235336237316363653864646131623032346633663863373061303465643633306566666337383435363833313534626263623935626231323433343366376562633130643336613763366235323763366537666566386534316463653737396665616664653738366632626333303664323239663534613331646665303238000000000000000000000000000000000000000000000000000000000000'

Utility Functions

Generate encryption keypair

import {BitOfMeService} from 'bitofme';
 
const bitofme = new BitOfMeService("rinkeby");
const keyPair = bitofme.generateKeyPair();
 
console.log(keyPair); //Warning: Never print private key to console!

Output:

{publicKey: '022f7148edd46fb3ef945ff4974b3c8213b713f2ec12ae2d1bb82aeb67dffdfc36', privateKey: '0x6782433bb0d4dee50218531af18a089d54
78180a04f71a3d559a042c706a3c8c'}

Encrypt/Decrypt messages

let plainMessage = "hello world";
 
let encryptedMessage = bitofme.encrypt(plainMessage, keyPair.publicKey);
let decryptedMessage = bitofme.decrypt(encryptedMessage, keyPair.privateKey);
console.log('encryptedMessage', encryptedMessage);

Output:

'encryptedMessage', '0333eec583d04a55ce0aba9dbfb04035e8c6de4f501ecc9b26c08fa501a5ec1507b53b71cce8dda1b024f3f8c70a04ed634c1e3366ce9301e648350b127f2798df61183693301f566dda6718229c3a0967f1438bb98696f1a1b7160d7499e60e55'

Get selected Account at the injected provider (if Metamask not installed or locked, this will be "")

let selectedAccount = await bitofme.selectedAccount();
console.log("selectedAccount", selectedAccount);

Output:

Selcted account', '0x627306090abab3a6e1400e9345bc60c78a8bef57'

Get conversion rate

const rate = await bitofme.conversionRate("usd");
console.log(rate);

Output:

630.25

Get gas price estimates

const priceEstimate = await bitofme.gasPriceEstimate();
console.log(priceEstimate);

Output:

{safeLowGWei: 8, fastGWei: 14, fastestGWei: 20, averageGWei: 9, speed: 0.9967071778740859, safeLowWait: 9.3, averageWait: 5.8, fastWait: 0.5, fastestWait: 0.5}

Readme

Keywords

Package Sidebar

Install

npm i bitofme

Weekly Downloads

9

Version

1.0.7

License

ISC

Unpacked Size

1.67 MB

Total Files

43

Last publish

Collaborators

  • manosamy