|
| 1 | +# MesonTo |
| 2 | + |
| 3 | +The blockchain world has entered a period of multi-chain coexistence. For web3 app developers, they often encounter a problem: they need to deploy smart contracts on a specific chain, but this will greatly limit them to attract assets and users on other chains. |
| 4 | + |
| 5 | +*MesonTo* has provided a solution for those web3 developers. [Meson](https://meson.fi) is a safe, costless and instant cross-chain protocol for stablecoins. MesonTo is an integratable sdk supported meson cross-chain protocol. With MesonTo, web3 applications can allow their users to transfer stablecoins from any chain directly to their smart contracts. |
| 6 | + |
| 7 | +Get a feel for how MesonTo works with this [demo](https://demo.meson.to). |
| 8 | + |
| 9 | +## How to integrate MesonTo |
| 10 | + |
| 11 | +### Frontend |
| 12 | + |
| 13 | +Add MesonTo to your frontend project through `npm i -S @mesonfi/to` or `yarn add @mesonfi/to`. Then import `MesonTo` by |
| 14 | + |
| 15 | +```js |
| 16 | +import MesonTo from '@mesonfi/to' |
| 17 | +``` |
| 18 | + |
| 19 | +You can also add it directly to the html file |
| 20 | + |
| 21 | +```html |
| 22 | +<script src="./meson-to.js"></script> |
| 23 | +``` |
| 24 | + |
| 25 | +Once the script is loaded, you will be able to use `MesonTo` globally. |
| 26 | + |
| 27 | +To open the popup of MesonTo for cross-chain transfer, run |
| 28 | + |
| 29 | +```js |
| 30 | +const appId = 'example' |
| 31 | +const meson2 = new MesonTo(window) |
| 32 | +meson2.open(appId) |
| 33 | + .then(() => { |
| 34 | + // on popup closed; doesn't mean a cross-chain transfer is completed |
| 35 | + }) |
| 36 | + |
| 37 | +meson2.onCompleted(data => { |
| 38 | + // when a cross-chain transfer is successful |
| 39 | + console.log(data) |
| 40 | +}) |
| 41 | +``` |
| 42 | + |
| 43 | +There are complete examples of how to use MesonTo in the `examples` folder. |
| 44 | + |
| 45 | +### Smart contract |
| 46 | + |
| 47 | +The cross-chain'ed stablecoin will be transferred to the app contract from meson's contract. In order to accept the transfer correctly, your app contract needs to implement the `transferWithBeneficiary` method. |
| 48 | + |
| 49 | +```solidity |
| 50 | +function transferWithBeneficiary(address token, uint256 amount, address beneficiary, uint64 data) external returns (bool); |
| 51 | +``` |
| 52 | + |
| 53 | +This will allow the app contract to obtain depositing tokens from meson's contract, but transfer the corresponding benefits (purchased NFTs, exchanged tokens, etc) to the user's address. |
| 54 | + |
| 55 | +See an example in `contracts/SampleAppContract.sol`. |
| 56 | + |
| 57 | +## Submit app information |
| 58 | + |
| 59 | +In order to keep users' funds safe, we need to confirm that your contract has correctly supported `transferWithBeneficiary`. Otherwise, users' cross-chain assets may be stuck and cannot be withdrawn. |
| 60 | + |
| 61 | +Once `transferWithBeneficiary` is supported, you can [contact us]() to add your app to the MesonTo. Please have the following information ready |
| 62 | + |
| 63 | +- App name |
| 64 | +- Prefered appId (popup will open at https://meson.to/{appId}) |
| 65 | +- App URL (need to open popup from it in *release* mode) |
| 66 | +- App icon (w144 x h144) |
| 67 | +- App logo (height 144, width <= 1080) |
| 68 | +- Smart contract info (deployed chain, supported types of stablecoins, contract address) |
| 69 | +- A short paragraph informs the user of the effect of the cross-chain transfer and guides the user to complete the operation |
| 70 | + |
| 71 | +We will review and input your app's information within 24 hours. After that, you can use `meson2.open(yourAppId)` to finish cross-chain transfers for your own app! |
| 72 | + |
| 73 | +## Dev mode & release mode |
| 74 | + |
| 75 | +In dev mode, MesonTo popup can be opened from any hostname, but it only allows cross-chain transfers under $5. Note that dev mode also runs on mainnet. |
| 76 | + |
| 77 | +After the app is launched, please switch to release mode. In release mode, MesonTo can only be opened from your app URL. |
0 commit comments