const MultiSenderWidget = () => { State.init({ tokenContract: "", recipients: "", amounts: "", newRecipient: "", newAmount: "", csvInput: "", isConnected: true, // Assuming the user is already connected }); const accountId = context.accountId; const handleMultiSend = async () => { const recipientArray = State.recipients .split(",") .map((item) => item.trim()); const amountArray = State.amounts .split(",") .map((item) => NearAPI.utils.format.parseNearAmount(item.trim())); const multisenderContract = new NearAPI.Contract( context.account, "multisender.youraccount.testnet", // replace with your contract's account { viewMethods: [], changeMethods: ["multisend"], } ); try { await multisenderContract.multisend( { token_contract: State.tokenContract, recipients: recipientArray, amounts: amountArray, }, "300000000000000", // gas limit "1" // deposit, in yoctoNEAR ); } catch (error) { console.error("Error during multisend:", error); } }; const addRecipient = () => { const recipients = State.recipients ? `${State.recipients},${State.newRecipient}` : State.newRecipient; const amounts = State.amounts ? `${State.amounts},${State.newAmount}` : State.newAmount; State.update({ recipients, amounts, newRecipient: "", newAmount: "" }); }; const handleCSVInput = () => { const rows = State.csvInput.split(";"); let recipients = ""; let amounts = ""; rows.forEach((row) => { const [recipient, amount] = row.split(",").map((item) => item.trim()); recipients = recipients ? `${recipients},${recipient}` : recipient; amounts = amounts ? `${amounts},${amount}` : amount; }); State.update({ recipients, amounts, csvInput: "" }); }; return ( <div> <h1>NEAR Social Multisender</h1> <div> <label>Token Contract:</label> <input type="text" value={State.tokenContract} onChange={(e) => State.update({ tokenContract: e.target.value })} /> </div> <div> <label>Add Individual Recipient:</label> <input type="text" placeholder="Wallet" value={State.newRecipient} onChange={(e) => State.update({ newRecipient: e.target.value })} /> <input type="text" placeholder="Amount" value={State.newAmount} onChange={(e) => State.update({ newAmount: e.target.value })} /> <button onClick={addRecipient}>Add Recipient</button> </div> <div> <label>Or Add via CSV:</label> <textarea placeholder="wallet1, amount1; wallet2, amount2; ..." value={State.csvInput} onChange={(e) => State.update({ csvInput: e.target.value })} /> <button onClick={handleCSVInput}>Process CSV Input</button> </div> <div> <button onClick={handleMultiSend}>Send Tokens</button> </div> <div> <h3>CSV Template:</h3> <p>wallet1, amount1; wallet2, amount2; ...</p> </div> </div> ); }; return <MultiSenderWidget />;