api
api copied to clipboard
How to add custom parameters to an transaction with API, such as to api.tx.balances.transfer
I want to implement payment function(dot、ksm),but I don't know how to add custom parameters to an transaction with API, such as to api.tx.balances.transfer, thanks.
such as: name and duration params
server.post<{ Body: { name: string, to: string, duration: string } }>("/worker/sendDot", async (request, reply) => {
let { name, to, duration } = request.body
const keyring = new Keyring({ type: 'sr25519' });
const alice = keyring.addFromUri('//Alice');
console.log('alice.address========', alice.address);
const cost = 1;
const txHash = await api.tx.balances
.transfer(to, cost)
.signAndSend(alice);
return { txHash: txHash }
});
substrate doesn't have the concept of random attributes on an extrinsic. Best you can do id send a batch with a transfer and a remark.
基板没有外部随机属性的概念。最好你可以发送一个带有转移和备注的批次。
I see a issue: https://github.com/polkadot-js/api/issues/3363
So I try:
const txHash = api.tx.utility.batchAll([
api.tx.balances.transfer(to, price),
api.tx.system.remark([name, duration])
]).signAndSend(alice)
use batch
or batchAll
is error:
Cannot read properties of undefined (reading 'batchAll')
I try:
const hash = await Promise.all([
api.tx.balances.transfer(polkaPnsAddr, amount * 1e10).signAndSend(alice),
api.tx.system.remark('i am a remark')
])
is ok
This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.