Contributing to Open Cadence is easy! And we’d love for you to share your work with the community so that we can keep on benefiting from each others work and keep creating amazing projects on Flow!
In order to contribute, we’ve tried to make it as easy as possible to add an example to the website. We provide you the format for submitting a pull-request to this GitHub repo so that your example can be added. We’ll go over the format for submitting your example in the following section!
https://github.com/onflow/open-cadence
In order to submit an example to the Open Cadence GitHub, you will need to submit a pull request in line with the following format in order to get it merged to the site. The format is as follows.
Navigate to the ‘modules’ folder in the ‘src’ folder in the repository
Here you will see all of the examples that are available on open cadence, and you can start to get an idea of how you will structure your folders to be approved
Add a new folder in the ‘modules’ folder with the name of your Cadence example
In your newly created folder, create an ‘index.js’ file as well as two folders, one named ‘cadence’ and one named ‘description’
Within the ‘cadence’ folder you will have four files with the following names
In each of these folders, you will input the text for the necessary parts of the contract and explanation that is needed. You can see in the example below how each const is created
export const contract = `pub resource interface Provider {
// withdraw
//
// Function that subtracts tokens from the owner's Vault
// and returns a Vault resource (@Vault) with the removed tokens.
//
// The function's access level is public, but this isn't a problem
// because even the public functions are not fully public at first.
// anyone in the network can call them, but only if the owner grants
// them access by publishing a resource that exposes the withdraw
// function.
//
pub fun withdraw(amount: UFix64): @Vault {
post {
// 'result' refers to the return value of the function
result.balance == UFix64(amount):
"Withdrawal amount must be the same as the balance of the withdrawn Vault"
}
}
}
`