Credit Token
About Crediting Token
You can use the credit functionality if you change your opinion about a trade you made. For example, if you want to buy Token XY with 100 SMR, but later in the cooldown phase, if you decide you want to buy less, then you can credit yourself 30 SMR, and after the cooldown phase, you will get 70 SMR worth of XY token.
Example
To credit a token, you must call credit on dataset(Dataset.TOKEN). credit takes an object of type Build5Request<CreditTokenRequest> as parameter.
const response = await https(origin)
.project(SoonaverseApiKey[origin])
.dataset(Dataset.TOKEN)
.credit({
address: address.bech32,
signature: signature.signature,
publicKey: {
hex: signature.publicKey,
network: Network.RMS,
},
body: {
amount: 1000000,
token: 'tokenId',
},
});
credit returns an oject of type Transaction.
Full How-To Code
import { Dataset, Network } from '@build-5/interfaces';
import { Build5, SoonaverseApiKey, https } from '@build-5/sdk';
import { address } from '../../utils/secret';
import { walletSign } from '../../utils/utils';
async function main() {
const origin = Build5.TEST;
try {
const member = await https(origin)
.project(SoonaverseApiKey[Build5.TEST])
.dataset(Dataset.MEMBER)
.id(address.bech32)
.get();
const signature = await walletSign(member.uid, address);
const response = await https(origin)
.project(SoonaverseApiKey[origin])
.dataset(Dataset.TOKEN)
.credit({
address: address.bech32,
signature: signature.signature,
publicKey: {
hex: signature.publicKey,
network: Network.RMS,
},
body: {
amount: 1000000,
token: 'tokenId',
},
});
console.log(response);
} catch (e) {
console.log(e);
return;
}
}
main().then(() => process.exit());