-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
USDC: @celo/connect + web3js demo #3
Conversation
🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎ To accept the risk, merge this PR and you will not be notified again.
Next stepsWhat is protestware?This package is a joke, parody, or includes undocumented or hidden behavior unrelated to its primary function. Consider that consuming this package my come along with functionality unrelated to its primary purpose. What is an install script?Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts. Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead. What's wrong with native code?Contains native code which could be a vector to obscure malicious code, and generally decrease the likelihood of reproducible or reliable installs. Ensure that native code bindings are expected. Consumers may consider pure JS and functionally similar alternatives to avoid the challenges and risks associated with native code bindings. Take a deeper look at the dependencyTake a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev. Remove the packageIf you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency. Mark a package as acceptable riskTo ignore an alert, reply with a comment starting with
|
Tested: Works as expected Transaction: https://alfajores.celoscan.io/tx/0x7c3d89e1c89affe40837a85292ac363a7a7d47fe856199f2c8978d314be51826
- implement gas estimation - adjust send amount based on ERC20 decimals
Decent progress on the USDC demo front. Currently, I'm blocked on an example that exclusively uses Generic ERC20 transfers (type: EIP1559) work well (example transaction implemented in 0c5a0b7), but I couldn't yet work out how to correctly pass a |
Unfortunately, transaction is still EIP1559 and not CIP64. For example: https://alfajores.celoscan.io/tx/0x3f8881bcf2c15e30b18d4e465d3865224071a5ee21e8f701dc6be377794d00dc
copy/paste insight from @aaronmgdr
|
I'm wondering what purpose the export interface ReadOnlyWallet {
getAccounts: () => Address[];
removeAccount: (address: Address) => void;
hasAccount: (address?: Address) => boolean;
signTransaction: (txParams: CeloTx) => Promise<EncodedTransaction>;
signTypedData: (address: Address, typedData: EIP712TypedData) => Promise<string>;
signPersonalMessage: (address: Address, data: string) => Promise<string>;
decrypt: (address: Address, ciphertext: Buffer) => Promise<Buffer>;
computeSharedSecret: (address: Address, publicKey: string) => Promise<Buffer>;
} Source: connect > wallet.ts Why is it called "ReadOnly" if you can sign a transaction with a class that implements it? The /**
* Connection is a Class for connecting to Celo, sending Transactions, etc
* @param web3 an instance of web3
* @optional wallet a child class of {@link WalletBase}
* @optional handleRevert sets handleRevert on the web3.eth instance passed in
*/
export class Connection {
// ...
constructor(readonly web3: Web3, public wallet?: ReadOnlyWallet, handleRevert = true) {
// ...
// TODO: Add this line with the wallets separation completed
// this.wallet = _wallet ?? new LocalWallet()
this.config.from = web3.eth.defaultAccount ?? undefined Source: connect > connection.ts Also curious how |
Wondering if
Source: https://docs.web3js.org/guides/wallet/local_wallet/ It's not obvious where web3.js stops and Celo-specific constructs start (e.g. |
while web3 has wallets. you must use the celo wallets to get the signing happening -- see the wallets directory in the sdks folder of developertooling repo. |
_wallet i think comes from the params above (which is now just wallet) LocalWallet would be imported from @celo/wallet-local |
yeah i cant answer that one. seems like it should be have a better name |
Thanks, this helped a lot. I used At the moment, the script is stuck and doesn't timeout or complete. I'll debug that next |
(for future reference) export type TransactionTypes = 'eip1559' | 'celo-legacy' | 'cip42' | 'cip64' Source: connect > types.ts const transactionReceipt = await connection
.sendTransaction({
from: sender,
to: CONTRACT_ADDRESS,
gas: 51925, // TODO: implement gas estimation
maxPriorityFeePerGas: web3.utils.toWei("10", "gwei"),
maxFeePerGas: web3.utils.toWei("10", "gwei"),
feeCurrency: "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1", // cUSD fee currency
data: transactionObject.encodeABI(),
+ type: 'cip64'
}) The error is: $ yarn ts-node web3.ts
yarn run v1.22.19
$ /Users/arthur/Documents/celo-org/feecurrency/node_modules/.bin/ts-node web3.ts
Initiating fee currency transaction...
/Users/arthur/Documents/celo-org/feecurrency/node_modules/web3-eth-accounts/src/common/utils.ts:344
throw new Error(
^
Error: Cannot convert string to Uint8Array. only supports 0x-prefixed hex strings and this string was given: cip64
at toUint8Array (/Users/arthur/Documents/celo-org/feecurrency/node_modules/web3-eth-accounts/src/common/utils.ts:344:10)
at Function.typeToInt (/Users/arthur/Documents/celo-org/feecurrency/node_modules/web3-eth-accounts/src/tx/transactionFactory.ts:43:48)
at Function.fromTxData (/Users/arthur/Documents/celo-org/feecurrency/node_modules/web3-eth-accounts/src/tx/transactionFactory.ts:68:37)
at /Users/arthur/Documents/celo-org/feecurrency/node_modules/web3-eth/src/utils/prepare_transaction_for_signing.ts:145:28
at Generator.next (<anonymous>)
at fulfilled (/Users/arthur/Documents/celo-org/feecurrency/node_modules/web3-eth/lib/commonjs/utils/prepare_transaction_for_signing.js:21:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Might be a different reason, but keeping track of this here in case. |
This fixes a bug with gas estimation. The `@celo/connect` library is calling a method from web3js. ```ts estimateGas = async ( tx: CeloTx, gasEstimator: (tx: CeloTx) => Promise<number> = this.web3.eth.estimateGas, caller: (tx: CeloTx) => Promise<string> = this.web3.eth.call ): Promise<number> ``` Source: https://github.com/celo-org/developer-tooling/blob/a884b24a242829a9425580e0b75f40526228838f/packages/sdk/connect/src/connection.ts#L358 Because of the version mismatch, the call fails silently.
- gas estimation is done automatically - with web3js@1.10, ERC20 ABI has to be of type `AbiItem[]`
Hint: Learnt that prepending a Node.js command with For example: $ DEBUG=* yarn ts-node web3.ts |
With the updated script, |
Adds CIP64 transaction demo using:
Related