TransferFromWithData
Withdraw Pluri allowance from another address and send the amount to another address, sending metadata alongside the transaction.
Method: PluriContract.transferFromWithData(type 1, type 2, type 3, type 4)
Types
String - Address of wallet or contract that the allowance originated from. Example: "0X4E90a36B45879F5baE71B57Ad525e817aFA54890"
String - Address of recipient to send Pluri allowance to. Can be a wallet address or a smart contract address. Example: "0X959FD7Ef9089B7142B6B908Dc3A8af7Aa8ff0FA1"
BigInt - The amount of Pluri to send. Example: 4n
Hex string - Convert the desired data to send as metadata from utf8 to bytes, then convert the bytes to a hex string. Example: "0X7b2248656c6c6f223a22576f726c64227d" originates from hexlify(toUtf8Bytes(JSON.stringify({"Hello","World"}))
// In this example let's pretend you're 0x959FD7Ef9089B7142B6B908Dc3A8af7Aa8ff0FA1 and
// 0x4E90a36B45879F5baE71B57Ad525e817aFA54890 gave you 1n alloance of Pluri. You will
// be transffering it to your wallet.
let allowanceGiverAddress = '0x4E90a36B45879F5baE71B57Ad525e817aFA54890'
let recieverAddress = '0x959FD7Ef9089B7142B6B908Dc3A8af7Aa8ff0FA1'
let data = {"Hello","World"}
let amount = 1n
//Web3.js 4.8 Example
let metadata = web3.utils.utf8ToHex(data);
// Check user whom inititated the transaction has enough to pay the Pluri tax + chosen application fee
const balance = await PluriContract.methods.balanceOf(recieverAddress).call();
if(balance >= (100000000000n + amount)){
PluriContract.methods.transferWithData(allowanceGiverAddress, recieverAddress, amount, metadata).send({ from: recieverAddress })
}
//Ethers.js 6.12.1 Example
let metadata = hexlify(toUtf8Bytes(JSON.stringify({"Hello","World"}))
// Check if the user has enought to pay the Pluri tax + chosen application fee
const balance = await PluriContract.balanceOf(recieverAddress)
if(balance >= (100000000000n + amount)){
PluriContract.transferWithData(allowanceGiverAddress, recieverAddress, amount, metadata)
}
Last updated