This is the π² Payment π° System Smart Contract for Freelancer Website.
- Install
node
andyarn
- Install
ts-node
as global command - Confirm the solana wallet preparation:
/home/---/.config/solana/id.json
in test case
- Main script source for all functionality is here:
/cli/script.ts
- Program account types are declared here:
/cli/types.ts
- Idl to make the JS binding easy is here:
/cli/freelancer.ts
Able to test the script functions working in this way.
- Change commands properly in the main functions of the
script.ts
file to call the other functions - Confirm the
ANCHOR_WALLET
environment variable of thets-node
script inpackage.json
- Run
yarn ts-node
First of all, you have to git clone in your PC.
In the folder freelancer
, in the terminal
-
yarn
-
anchor build
In the last sentence you can see:
To deploy this program:
$ solana program deploy /home/.../freelancer/target/deploy/freelancer.so
The program address will default to this keypair (override with --program-id):
/home/.../freelancer/target/deploy/freelancer-keypair.json
-
solana-keygen pubkey /home/.../freelancer/target/deploy/freelancer-keypair.json
-
You can get the pubkey of the
program ID : ex."5N...x6k"
-
Please add this pubkey to the lib.rs
line 14: declare_id!("5N...x6k");
-
Please add this pubkey to the Anchor.toml
line 4: freelancer = "5N...x6k"
-
Please add this pubkey to the types.ts
line 6: export const PAYMENT_PROGRAM_ID = new PublicKey("5N...x6k");
-
anchor build
again -
solana program deploy /home/.../freelancer/target/deploy/freelancer.so
Then, you can enjoy this program π
The Project Rep can create the project with several milestones, the function createProject
/**
* @dev Create the project by rep
* @param milestones Show how many milestones in the project
* @param milestoneAmount Milestone amounts as array
* @param milestoneDate Milestone date as array
* @param createTime The project's create time which is stored in BE
*/
export const createProject = async (
milestones: number,
milestoneAmount: number[],
milestoneDate: number[],
createTime: number
)
The Project Rep can escrow the funds for the specific milestone, the function createEscrow
/**
* @dev Escrow funds for `milestone`
* @param milestone The milestone to escrow funds
* @param createTime This project's create time which is stored in BE
*/
export const createEscrow = async (
milestone: number,
createTime: number
)
The Project Rep can edit the milestone schedule, the function createEdit
/**
* @dev Edit the milestones of the project
* @param startMilestone The start milestone to edit
* @param newMilestones The whole milestones to newly set
* @param createTime This project's create time which is stored in BE
* @param milestoneAmount New milestone amounts to be changed
* @param milestoneDate New milestone date to be changed
*/
export const createEdit = async (
startMilestone: number,
newMilestones: number,
createTime: number,
milestoneAmount: number[],
milestoneDate: number[],
)
The Project Rep / Admin / Freelancer (2 weeks after finished the task) can release the funds to the freelancer, the function createRelease
/**
* @dev Release funds to the completed milestone
* @param milestone The completed milestone to be released
* @param creator The creator's address of this project which is stored in BE
* @param createTime This project's create time which is stored in BE
*/
export const createRelease = async (
milestone: number,
creator: PublicKey,
createTime: number,
)
The freelancer can accept the project which is created by a proejct Rep, the function createAccept
/**
* @dev Accept the project
* @param creator The creator's address of this project which is stored in BE
* @param createTime This project's create time which is stored in BE
*/
export const createAccept = async (
creator: PublicKey,
createTime: number,
)
The freelancer mark as complete after he has done the project, call the function createMark
/**
* Mark as complete
* @param milestone The milestone to mark as complete
* @param creator The creator's address of this project which is stored in BE
* @param createTime This project's create time which is stored in BE
*/
export const createMark = async (
milestone: number,
creator: PublicKey,
createTime: number,
)
Flow(create -> accept -> escrow -> mark as complete -> release)
- Decommand the line 46: and
yarn ts-node
- Command the line 46, decommand the line 53: and
yarn free
- Command the line 53, decommand the line 47: and
yarn ts-node
- Command the line 47, decommand the line 54: and
yarn free
- Command the line 54, decommand the line 49: and
yarn ts-node
Here ts-node
is for Project Rep's wallet integration and perform the project Rep's functions,
and free
is for freelancer's wallet integration and perform the freelancer's functions.
yarn ts-node: "export ANCHOR_WALLET=/home/ubuntu.../keypair.json && ts-node ./cli/script.ts"
yarn free: "export ANCHOR_WALLET=/home/ubuntu.../keypair.json && ts-node ./cli/script.ts"