Created
March 8, 2024 17:58
-
-
Save sungkhum/c745ccb6b6e2d2e80858f5ebf2c85cde to your computer and use it in GitHub Desktop.
DeSo Protocol JS Snippet for Transferring DAO Token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOT WORKING CODE - just a snippet to get the general idea | |
import { | |
identity, transferDeSoToken | |
} from "deso-protocol"; | |
try { | |
// Permission checks and setup | |
if (!identity.hasPermissions({ | |
TransactionCountLimitMap: { | |
NEW_MESSAGE: "UNLIMITED" | |
}, | |
DAOCoinOperationLimitMap: { | |
BC1YLiXpwSpaUt3TmsXH1cEgr3fh8S9fLKaFfj6SHTqgxHMRUC4oQEk: { | |
transfer: "UNLIMITED", | |
} | |
} | |
})) { | |
await identity.requestPermissions({ | |
GlobalDESOLimit: 10000000, // 0.01 DESO | |
TransactionCountLimitMap: { | |
NEW_MESSAGE: "UNLIMITED" | |
}, | |
DAOCoinOperationLimitMap: { | |
BC1YLiXpwSpaUt3TmsXH1cEgr3fh8S9fLKaFfj6SHTqgxHMRUC4oQEk: { | |
transfer: "UNLIMITED", | |
} | |
} | |
}); | |
} | |
const Enums = { | |
values: { | |
NANO_VALUE: 1e9, // 1 billion, representing the nano scale | |
HEX_PREFIX: '0x' | |
} | |
}; | |
const firstAmount = 1.0 * Enums.values.NANO_VALUE * Enums.values.NANO_VALUE; // Convert to "nano-nanos" | |
const amountNanos = new BigNumber(firstAmount); // Convert to BigNumber for precise arithmetic | |
const hexAmount = amountNanos.toString(16); // Convert BigNumber to a hex string | |
const finalAmount = Enums.values.HEX_PREFIX + hexAmount; // Prepare the final amount with hex prefix | |
transferDeSoToken({ | |
ProfilePublicKeyBase58CheckOrUsername: 'BC1YLiXpwSpaUt3TmsXH1cEgr3fh8S9fLKaFfj6SHTqgxHMRUC4oQEk', | |
ReceiverPublicKeyBase58CheckOrUsername: 'BC1YLhmQDtYfMf95YRUKU15dMeWiAkMpY7i14KDYzc1k5iQ3jfA5sod', | |
DAOCoinToTransferNanos: finalAmount, | |
SenderPublicKeyBase58Check: currentUser.PublicKeyBase58Check | |
}).then(async (response) => { | |
console.log('Transfer successful:', response); | |
// Proceed with the next steps only if the transfer is successful | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment