1 What is Moveflow
MoveFlow is a crypto-asset streaming payment protocol built on top of the Move ecosystem that enables instant, seamless and uninterrupted payment flows.
1.1 Enabling Crypto Payments
MoveFlow has a wide range of application areas, including real-time payroll payments, token airdrops and unlocking, subscription and pay-per-use models, and more.
- Real-time payroll payments: Streaming payments can help companies manage their cash flow more smoothly by enabling employees to receive their paychecks in real time.
- Token Airdrops and Unlocks: During the process of unlocking project tokens, streaming payments can be used to set up an installment release schedule that allows investors to receive tokens on an ongoing basis. Once a stream payment is created, it cannot be changed, which reduces the risk of investors experiencing sudden withdrawals.
- Subscription and pay-per-use models: instead of paying a monthly fee, users pay when they use the service and stop paying when they no longer use it, avoiding unnecessary losses.
1.2 DeFi infrastructure
Streaming Payments can also be used as an infrastructure for DeFi development, bringing more interesting products and applications to DeFi. Based on the Move ecosystem, the Resource of the right to receive and the right to send can be NFT-ized and used as a valuable asset in more DeFi domains.
2 Introduction and Installation of Moveflow SDK
2.1 Introduction to Moveflow SDK
Moveflow SDK mainly serves third-party Dapp application development, independent developers, front-end and other objects. User objects can easily and quickly interact with the contract without having to consider the underlying contract implementation.
Moveflow SDK provides interactive interfaces and query interfaces for streaming payment, the two types of interfaces cooperate with each other to complete all streaming payment related operations.
The list of interaction interfaces is as follows:
- create
- withdraw
- pause
- resume
- close
- extend
The list of query interfaces is as follows:
- getStreamById
- withdrawable
- incoming
- outgoing
2.2 Installation of Moveflow SDK
Install the Moveflow SDK using yarn.
yarn add @moveflow/sdk.js
After importing the file in the code, you can create thesdk
Example.
import { SDK,TESTNET_CONFIG } from '@moveflow/sdk.js' ;
const sdk = new SDK(TESTNET_CONFIG);
3 Interactive interface analysis and use of streaming payments
3.1 Creating streams
This interface creates a payment stream and returns the result of the transaction.
const payload = sdk.stream.create({
name : 'test', remark : 'test', {
comment : 'test',
recipientAddr: '0x20f0cbe21cb340fe56500e0889cad03f8a9e54a33e3c4acfc24ce2bdfabc4180',
depositAmount: 1,
startTime: start_time,
stopTime: stop_time,
coinType: CoinsMapping.
APTOS, interval: 1, canPause: true, coinType: CoinsMapping.
canPause: true, closeable: true, coinType: CoinsMapping.
stopTime: stop_time, interval: 1, canPause: true, closeable: true,
recipientModifiable: true,
})
const txid = await SignAndSubmitTransaction(payload)
The parameters to be entered are:
- name: The name of the payment stream.
- remark: Description of the payment flow.
- recipientAddr: address of the recipient of the payment stream.
- depositAmount: The total number of Coins deposited.
- startTime: start time of the payment stream, in seconds.
- stopTime: the end time of the payment stream, in seconds.
- coinType: the currency of the payment stream, default is APT.
- interval: interval between payment cycles, default is 1 second.
- canPause: if or not the payment stream supports pause, default is true.
- closeable: if or not the payment flow supports closeable, default is true.
- recipientModifiable: if or not the payment stream supports modifying the recipient's address, default is false.
3.2 Extracting Coins from Payment Streams
The recipient of a payment stream withdraws Coins from a payment stream. the number of Coins that can be withdrawn is counted from the time of the last withdrawal to the current time, and the recipient gets the corresponding number of Coin withdrawal privileges for each full withdrawal cycle.const payload = sdk.stream.withdraw({
id: 30.
coinType: AptosCoin.
})
const response = await SignAndSubmitTransaction(payload)
The parameters to be entered are:
- id: Id of the payment stream.
- coinType: the currency of the payment stream, default is APT.
Get the Id of the payment stream
The receiver needs to specify the payment flow id when extracting Coins from the payment flow, the payment flow id is a unique identifier of a payment flow. moveflow SDK has a separate interface to help get the required payment flow id.
Query all input payment streams of the recipient: by means of the address parameter, query all payment stream Id's for which the address is the recipient.(see 4.3 for details)
Query all output payment streams of the sender: by means of the address parameter, query all payment stream Id's for which the address is the sender.(see 4.4 for details)
3.3 Closing the payment stream
This interface audits the interface call permissions and only the sender of the payment stream can close this payment stream. After closing the payment stream, the receiver will be subject to its withdrawable Coin and the remaining Coin will be returned to the sender.
const payload = sdk.stream.close({ id: 29 })
const txid = await SignAndSubmitTransaction(payload)
The parameters to be entered are:
- id: Id of the payment stream.
3.4 Suspension of payment streams
This interface can pause a payment stream, during which the recipient does not accumulate withdrawable Coins.
const payload = sdk.stream.pause({
id: 29, coinType: AptosCoin, {
coinType: AptosCoin, })
})
const txid = await SignAndSubmitTransaction(payload)
The parameters to be entered are:
- id: Id of the payment stream.
- coinType: the currency of the payment stream, default is APT.
3.5 Restoration of payment flows
This interface corresponds to a paused payment stream, which can be resumed in a paused state. After resumption the receiver can accumulate withdrawable Coins as normal.
const payload = sdk.stream.resume({
id: 29, coinType: AptosCoin, {
coinType: AptosCoin, }))
})
const txid = await SignAndSubmitTransaction(payload)
The parameters to be entered are:
- id: Id of the payment stream.
- coinType: the currency of the payment stream, default is APT.
3.6 Extended Payment Streams
If the sender of a payment stream needs to add a new number of tokens with the original payment parameters, it can extend the end of the original payment stream through this interface without creating a new payment stream.
const payload = sdk.stream.extend({
id: 30,
extraAmount: 300,
stopTime: '1635724800',
coinType: AptosCoin, }))
})
const txid = await SignAndSubmitTransaction(payload)
The parameters to be entered are:
- id: Id of the payment stream.
- extraAmount: The number of tokens that need extra support.
- stopTime: the new end time of the payment stream, you need to deposit a certain amount of tokens to continue the payment stream.
- coinType: the currency of the payment stream, default is APT.
4 Parsing and using the query interface for streaming payments
4.1 Querying payment flow information
Gets information about the payment stream by the specified payment stream id.
const id = 30
const streams = await sdk.stream.getStreamById(id)
console.log("streams:", streams)
Payment stream information is included:
- status: The status is used for payment stream filtering and is categorized into the following seven types: Scheduled/Canceled/Streaming/Completed/Paused/Unknown/All
- createTime: the time the payment stream was created
- depositAmount: the amount of Coin deposited in the payment stream
- streamId: id of the payment stream
- interval: payment period in s
- lastWithdrawTime: the last time the Coin was withdrawn
- ratePerInterval: the number of Coins paid per cycle
- recipientId: recipient address
- remainingAmount: The amount of Coins left in the payment stream, the difference between this amount and depositAmount is the amount of Coins that have been withdrawn.
- senderId: sender address
- startTime: start time
- stopTime: end time
- withdrawnAmount: and the amount withdrawn
- pauseInfo: the pause information of the payment flow, including pause status, pause start time, and pause time.
- name: name of the payment stream
- streamedAmount: the amount that has been streamed, the number of tokens that can be withdrawn from the start of the payment stream until now
- withdrawableAmount: the amount that the receiver can withdraw at the current point in time, equal to streamedAmount minus withdrawnAmount
- escrowAddress: agent vault address
The payment flow information structure is defined as follows:
interface StreamInfo {
status: StreamStatus,
depositAmount: string, streamId: string, streamInfo { status: StreamStatus
streamId: string, interval: string, StreamInfo { status: StreamStatus
stopTime: string,
withdrawnAmount: string, pauseInfo: {{pauseInfo
pauseInfo: {
accPausedTime: string, pauseAt: string, withdrawnAmount: string, pauseInfo: {
paused: boolean, {
}, name: string, // stream's name
name: string, // stream's name
streamedAmount: string, withdrawableAmount: string, // stream's name
withdrawableAmount: string, }, name: string, // stream's name
streamedAmount: string, withdrawableAmount: string, escrowAddress: string, }
}
4.2 Querying the number of withdrawable Coins for a payment stream
Queries the number of Coins that can be withdrawn by the payment stream, that is, the number of Coins that have been sent by the payment stream up to the current point in time minus the number of Coins that have been withdrawn by the receiver.
const id = 30
const res = await sdk.stream.withdrawable(_id)
console.log("withdrawable res:", res)
4.3 Input streams for querying an address
Queries information about all payment streams for which an address is the recipient, using that address as an input parameter.
const address = `0x20f0cbe21cb340fe56500e0889cad03f8a9e54a33e3c4acfc24ce2bdfabc4180`
const res = await sdk.stream.getIncomingStreams(address)
console.log("getIncomingStreams res:", res)
4.4 Querying the output stream of an address
Queries information about all payment streams for which an address is the sender, using that address as an input parameter.
const address = `0x20f0cbe21cb340fe56500e0889cad03f8a9e54a33e3c4acfc24ce2bdfabc4180`
const res = await sdk.stream.getOutgoingStreams(address)
console.log("getOutgoingStreams res:", res)
5 Demo
You can experience the demo presentation:
https://moveflow-aptos-sdk-demo.vercel.app/
Demo source code:
https://github.com/Move-Flow/sdk.js/tree/lyb/aptos-sdk/examples/demo
6 Summary
Currently the Moveflow SDK is version 1.0 and only supports basic interaction with APTOS-based contracts. The next step will be to provide a more convenient and easy-to-use interface. There are still a number of shortcomings, welcome your valuable comments.
All of the above content is reproduced from the Internet, does not represent the position of AptosNews, is not investment advice, investment risk, the market need to be cautious, such as infringement, please contact the administrator to delete.