# Crowdloan Server
Used to get referral bonus for Acala crowdloan.
Server Endpoint:
- Testnet: https://crowdloan.aca-dev.network
- Polkadot: https://crowdloan.aca-api.network
Testnet relaychain RPC endpoint: [wss://karura-test-node.laminar.codes/polkadot](wss://karura-test-node.laminar.codes/polkadot). You can get the token from the test account.
ParaID:
- Testnet: 2001
- Polkadot: 2000
----
### ==GET== `/statement`
Get declaration statement. Normally it is constant. When calling `/sign`, the user's signature for the statement must be passed in.
#### Parameters
No parameters
#### Default response
```
Status: 200 OK
```
```json
{
"paraId": 2000, // Acala PARA_ID
"statementMsgHash": "0x15c1cc7c49ee6f5ce8e02a2f8ff22481160ac85783644140f969f7accac2adf4",
"statement": "I hereby agree to the terms of the statement whose SHA-256 multihash is QmSfG9pSE3eaQzFDQ1S421nj6sKJxFE8AYefwojg1Rkt2W. (This may be found at the URL: https://acala.network/acala/terms)",
"proxyAddress": "12CnY6b89bFfTbM6Wh3cdFvHAfxxsDUQHHXtT2Ui7SQzxBrn"
}
```
#### Code samples
Shell
```bash
curl 'https://crowdloan.aca-dev.network/statement'
```
Javascript
```javascript
await axios.get(`https://crowdloan.aca-dev.network/statement`);
```
### ==GET== `/referral/:referral`
Check if the referral code is valid.
#### Parameters
| Name | Type | In | Required |Description |
| :-- | --: |:--:| :--: | :--: |
| referral | string | path | true | The referral code being checked. It must be a hex starting with 0x, all lowercase. |
#### Default response
```
Status: 200 OK
```
```json
{
"referral": "0x95cf56355c22b33b781981c2010e2d0abd2d4209d5cc30b5d7f41aa66926befb",
"result": true // If the referral code is invalid, the result will be false.
}
```
#### Code samples
Shell
```bash
curl 'https://crowdloan.aca-dev.network/referral/0x95cf56355c22b33b781981c2010e2d0abd2d4209d5cc30b5d7f41aa66926befb'
```
Javascript
```javascript
await axios.get(`https://crowdloan.aca-dev.network/referral/0x95cf56355c22b33b781981c2010e2d0abd2d4209d5cc30b5d7f41aa66926befb`);
```
### ==Post== `/contribute`
This api will submit the user's referral code and the signature of the terms.
**Note**:
In order for the referral code to be correctly applied, it must be posted to API server before the `crowdloan.contribute` transaction is sent. Otherwise the referral code will not be applied correctly.
You need to post `/contribute` for each contribution to correctly apply the referral code for all of the contributions.
#### Parameters
| Name | Type | In | Required |Description |
| :-- | --: |:--:| :--: | :--: |
| address | string | body | true | Address of the contributor. |
| amount | string | body | true | Amount of contribution. Must be an integer and have no decimals. For example 1 DOT = '10000000000'. **This is the intended amount. It can be different from the actual contribution amount.** |
| signature | string | body | true | Signature of the contributor's statement. |
| referral | string | body | false | The referral code for this contribution. |
| email | string | body | false | The email address of the contributor. |
| receiveEmail | boolean | body | false | Flag to receive mail or not |
#### Rate Limit
Up to two requests are allowed within 1 minute for the same ip
#### Authorization
Authorization via jwt, please contact acala to get token.
#### Default response
```
Status: 200 OK
```
```json
{
"result": true,
"address": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"email": "testEmail@gmail.com",
"referral": "0xec495d2d087bcfe8062c6ec85c90bf4a2ccd05d21978c0f2de7c5fb3cf1fa542",
"amount": "50000000000" // 5 DOT
}
```
#### Code samples
Shell
```bash
curl \
-X POST \
--H 'Authorization: Bearer {{Authorization Token}}' \
-H "Content-Type: application/json" 'https://crowdloan.aca-dev.network/contribute' \
-d '{
"address": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"amount": "50000000000",
"email": "testEmail@gmail.com",
"referral": "0xec495d2d087bcfe8062c6ec85c90bf4a2ccd05d21978c0f2de7c5fb3cf1fa542",
"signature": "0xa200a1dcb772da329600abd4d9e11f3f1c3911f3e41ed56f111ce26c98da7f15f22ff85b3fa6736b31bace596426cd1aa22a8815f46346e0239e98d8bb739882"
}'
```
Javascript
```javascript
const result = await axios.get(`https://crowdloan.aca-dev.network/statement`);
const address = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
const statementSignature = await signer.signRaw({
address: address,
type: 'bytes',
data: result.data.statement,
})
const token = '.....'
await axios.post(`https://crowdloan.aca-dev.network/contribute`, {
"address": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"amount": "10000000000",
"email": "testEmail@gmail.com",
"referral": "0xec495d2d087bcfe8062c6ec85c90bf4a2ccd05d21978c0f2de7c5fb3cf1fa542",
"signature": toHex(statementSignature)
}, {
headers: {
'Authorization': `Bearer ${token}`
}
});
```
### ==Post== `/transfer`
This api is used to record the emails of people who submit contributions via the Liquid Crowdloan DOT.
**Note**:
This api is similar to the `/contribute` api, but does not require the signature field to be passed.
#### Parameters
| Name | Type | In | Required |Description |
| :-- | --: |:--:| :--: | :--: |
| address | string | body | true | Address of the contributor. |
| amount | string | body | true | Amount of contribution. Must be an integer and have no decimals. For example 1 DOT = '10000000000'. **This is the intended amount. It can be different from the actual contribution amount.** |
| referral | string | body | false | The referral code for this contribution. |
| email | string | body | false | The email address of the contributor. |
| receiveEmail | boolean | body | false | Flag to receive mail or not |
#### Rate Limit
Up to two requests are allowed within 1 minute for the same ip
#### Authorization
Authorization via jwt, please contact acala to get token.
#### Default response
```
Status: 200 OK
```
```json
{
"result": true,
"address": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"email": "testEmail@gmail.com",
"referral": "0xec495d2d087bcfe8062c6ec85c90bf4a2ccd05d21978c0f2de7c5fb3cf1fa542",
"amount": "50000000000" // 5 DOT
}
```
#### Code samples
Shell
```bash
curl \
-X POST \
--H 'Authorization: Bearer {{Authorization Token}}' \
-H "Content-Type: application/json" 'https://crowdloan.aca-dev.network/contribute' \
-d '{
"address": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"amount": "50000000000",
"email": "testEmail@gmail.com",
"referral": "0xec495d2d087bcfe8062c6ec85c90bf4a2ccd05d21978c0f2de7c5fb3cf1fa542"
}'
```
Javascript
```javascript
const result = await axios.get(`https://crowdloan.aca-dev.network/statement`);
const proxyAddress = result.data.proxyAddress;
const statement = result.data.statement;
const address = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
const referral =
"0xec495d2d087bcfe8062c6ec85c90bf4a2ccd05d21978c0f2de7c5fb3cf1fa542";
const email = "testEmail@gmail.com";
const amount = "10000000000";
const token = ".....";
await axios.post(
`https://crowdloan.aca-dev.network/transfer`,
{
address: address,
amount: amount,
email: email,
referral: referral,
},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
const txs = [
api.tx.balances.transfer(proxyAddress, amount),
api.tx.system.remarkWithEvent(statement),
api.tx.system.remarkWithEvent(`referrer:${referral}`), // this is optional
];
api.tx.utility.batchAll(txs).signAndSend(signer);
```