Setup Fee Delegation
Fee delegation is mandatory if you want to use this kit with social login.
You can learn more about what Fee Delegation is and what it is used for in this section.
To allow your app to use the fee delegation service, you will need to pass a FEE_DELEGATION_URL argument to the VeChainKit Provider.
FEE_DELEGATION_URL
You need to set this parameter in your VeChainKitProvider
wrapper.
You need one per environment.
To obtain one, you can deploy your own custom solution or use vechain.energy.
Option 1: Create your own
You can deploy this as a microservice (through Lambda, Cloudflare, etc.) or as an endpoint of your backend.
import { Address, HDKey, Transaction, Secp256k1, Hex } from '@vechain/sdk-core';
// the default signer is a solo node seeded account
const DEFAULT_SIGNER = 'denial kitchen pet squirrel other broom bar gas better priority spoil cross'
export async function onRequestPost({ request, env }): Promise<Response> {
const body = await request.json()
console.log('Incoming request', body);
const signerWallet = HDKey.fromMnemonic((env.SIGNER_MNEMONIC ?? DEFAULT_SIGNER).split(' '), HDKey.VET_DERIVATION_PATH).deriveChild(0);
if (!signerWallet.publicKey || !signerWallet.privateKey) { throw new Error('Could not load signing wallet') }
const signerAddress = Address.ofPublicKey(signerWallet.publicKey)
const transactionToSign = Transaction.decode(
Buffer.from(body.raw.slice(2), 'hex'),
false
);
const transactionHash = transactionToSign.getSignatureHash(Address.of(body.origin))
const signature = Secp256k1.sign(transactionHash.bytes, signerWallet.privateKey)
return new Response(JSON.stringify({
signature: Hex.of(signature).toString(),
address: signerAddress.toString()
}), {
status: 200,
headers: {
'Content-Type': 'application/json',
'access-control-allow-origin': '*'
}
})
}
Option 2: use vechain.energy

Last updated
Was this helpful?