Giter VIP home page Giter VIP logo

mvcbridge-sdk's Introduction

[email protected]

Usage

This is the sdk for sending request to mvcbridge, follow these steps to transform your asset through mvcbridge.

  1. Build and send on-chain transaction using your own wallet client instance(ie. metalet, metamask). Save the transaction hash.
  2. Use this sdk to generate a transfer request and sign the request content.
  3. Send the signed request to mvcbridge server.

Example

you can refer to test/sdk-test.ts for a demo.

import {MvcBridgeSdk} from 'mvcbridge-sdk';
import {OrderApi} from "./api";

// 1. Build and send on-chain transaction using your own wallet client instance(ie. metalet, metamask). Save the transaction hash.
// todo: build and send on-chain transaction(ie. metalet, metamask)

// 2. Use this sdk to generate a transfer request and sign the request content.
// change this for prod env
const basePath = BASE_PATH;
// read wif from env
const wif = process.env.WIF;

const orderApi = new OrderApi(undefined, basePath);
// leaving signature empty for now
const registerRequest: OrderRegisterRequest = {
    // token amount
    amount: "100000",
    // your source address
    fromAddress: "0x0e7d22a52bab804d8509b06e2d982cddff7d5e8f",
    fromChain: "eth",
    fromTokenName: "usdt",
    // this is your target address
    toAddress: "mvMPwt1318WxF8gRFT3wGQ7XJuENF97dyF",
    toChain: "mvc",
    toTokenName: "usdt",
    // the txid from previous transaction
    txid: "0xdca3acde1db3254789493e4e5341471b32cb3407b3ca30daa3c634e87d1518f5"
}
// assemble the message
const message = SignatureHelper.getSigningMessageFromOrder(registerRequest);
console.log(message)
// sign the message
// if your source chain is eth (ie using metamask), please sign the message using personal_sign
// don't forget the prefix
// const signature = SIGNATURE_FROM_ETH_WALLET;
// https://docs.metamask.io/guide/signing-data.html
// if your source chain is mvc (ie using metalet), you can use this sdk to sign the message
// set the signature
const signature = SignatureHelper.signMessageBitcoin(message, wif, "testnet");
console.log(signature);
registerRequest.signature = signature;

// call the api
orderApi.orderRegisterPost(registerRequest).then((response) => {
    console.log(response);
}).catch((error) => {
    // ignore
});

Openapi generator

This generator creates TypeScript/JavaScript client that utilizes axios. The generated Node module can be used in the following environments:

Environment

  • Node.js
  • Webpack
  • Browserify

Language level

  • ES5 - you must have a Promises/A+ library installed
  • ES6

Module system

  • CommonJS
  • ES6 module system

It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via package.json. (Reference)

Building

To build and compile the typescript sources to javascript use:

npm install
npm run build

Publishing

First build the package then run npm publish

Consuming

navigate to the folder of your consuming project and run one of the following commands.

published:

npm install [email protected] --save

unPublished (not recommended):

npm install PATH_TO_GENERATED_PACKAGE --save

mvcbridge-sdk's People

Contributors

kakeimei avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.