what is the difference between these two ethers.js functions [duplicate] - solidity

Can somebody please point me to the documentation (official or otherwise ) that explains the function ethers.getContractAt():
the original context of this is as follows:
vrfCoordinator = await ethers.getContractAt('VRFCoordinatorMock', VRFCoordinatorMock.address, signer)
and the full code can be found here...
https://github.com/PatrickAlphaC/all-on-chain-generated-nft/blob/main/deploy/02_Deploy_RandomSVG.js
In the absence of such documentation, an explanation would be much appreciated. Thank you!

The getContractAt() function is part of the hardhat-ethers plugin for Hardhat, expanding the ethers object.
It's not a part of the core Ethers package, so it's not included in their documentation.
Hardhat docs mentioning the plugin: https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers

Basically, it is doing the same thing, that attach do but in one line. i.e you can actually interact with an already deployed contract.
For reference below is the code if you are using attach
let xyzContract = await hre.ethers.getContractFactory("Name of the contract");
let xyzContractInstance = xyzContract.attach('Address of the contract');
You can accomplish the same thing in one line via getContractAt() when using hardhat
let xyzContractInstance = await hre.ethers.getContractAt(
"Contract Address",
deployed contract address
);

Related

Set custom timeout to Bluetooth-le write with Quasar-Framework/Capacitor

I'm using the Bluetooth-LE community plugin in a Quasar/Capacitor project.
Since version 1.7.0, we can make timeouts configurable. But how? I need help with the syntax. Can someone give me a fonctionnal example with a custom timeout.
Thank you.
I was also looking for that information. Haven't found any details on the documention but the file 'definitions.d.ts' inside the Bluetooth-LE module.
Try this :
const writeFlag = await BleClient.write(
device.deviceId,
SERV_SYSTEM_SETTINGS,
CHAR_RTC,
dvDateTime,
{timeout:(10000)} // <---- this is what you need
);

Redis: Cannot perform full-text search operations

I got error saying "ReplyError: Car:index: no such index". I am indexing by "description". As you can see on the terminal part contains all the needed info and I am not sure what is causing the problem. Help is welcome.
I've been trying to follow Fireship tutorial on Redis, copied his code https://fireship.io/lessons/redis-nextjs/
In Redis-om version 0.3.6, you can add following code in your API:
export async function createIndex() {
await connect();
const repository = client.fetchRepository(schema);
await repository.createIndex();
}
And Also ensure you only create index once ONLY.
It will work after you created an index.
As Guy Royse mentioned in the comments - The problem is solved by calling createIndex API.

What is the equivalent for Auth.updateUserAttributes in amplify_auth_cognito

Link 1.
What is the equivalent for
const user = await Auth.currentAuthenticatedUser();
const result = await Auth.updateUserAttributes(user, {
'custom:favorite_flavor': 'Strawberry'
});
in Flutter
amplify_core: '<1.0.0'
amplify_auth_cognito: '<1.0.0'
Took a look and found the simple answer that the exact copy over does not exists as i'm sure you have realized at this point.
The link:
https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/ will fail to give you any comparable Flutter etc... pages & if you try it will return "Flutter is not supported on this page. Please select one of the following: Javascript."
Unfortunately, Javascript is not supported in android/IOS though there was some stuff out there to partially work with it https://medium.com/flutter-community/using-javascript-code-in-flutter-web-903de54a2000.
Hopefully this answer will become obsolete over time as more work is put into the needed functionality.

How to update deployed Ethereum smart contract with ABI only through console (Truffle)

I need to update value on deployed contract ( I dont have sol neither it has been deployed on my platform )
I want to update param with setter in contract and call getter to see changed value .. always default value comes back!
here is the code Im using :
new web3.eth.Contract(HelloWorld.abi,'0x085Ab4C596535FFCE5B520D277f1C01236a656CB').methods.setMessage('Hi').call()
=> Result {}
then call :
new web3.eth.Contract(HelloWorld.abi,'0x085Ab4C596535FFCE5B520D277f1C01236a656CB').methods.getMessage().call()
=>
'hello world10' 🤔
Im using Truffle console:
truffle console --network ropsten
one comment if I use :
HelloWorld.deployed().then(instance => instance.setMessage('new Hi').call())
then call:
HelloWorld.deployed().then(instance => instance.getMessage.call()).then(result => message = result)
then I got expected value .. but I don't have deployed contract. neither sol. all what I have part ABI
Is it wrong with my calls that should be async .. or I need to redeploy contract ?
Im still new in this crypto-world 🙂
welcome to the "crypto-world" as you named it.
I've got a bit lost on your question but what you want is to deploy a contract with an initial message and then change that message using setMessage method, all through the console.
First thing you are doing wrong is calling the "setMessage" method using .call(). When you want to change something in the blockchain, you will send a transaction, and to send a transaction you need to specify an account. The correct method should be .send({ from: "you-account-address" }).
In order to simplify a bit, let me just show a few lines that you can use and then explain
$ > truffle console --network ropsten
$ (truffle) > helloInstance = await HelloWorld.deployed()
$ (truffle) > await helloInstance.getMessage()
$ (truffle) > await helloInstance.setMessage("new Hi", { from: "you-account-address" })
So, basically, all calls are async. First, you call HelloWorld.deployed() because when you deployed the contracts with truffle, truffle created a folder named "build" where it saved the contracts with all the necessary data, that's why you don't need to specify the address neither the abi. This is totally different from using web3.js in which you need to specify both.
Then, you can just call the methods.
You can find more detailed information here https://www.trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts

How do I utilize a named instance within the ObjectFactory.Initialize call for StructureMap?

I am trying to do the following bootstrapping:
x.For(Of IErrorLogger).Use(Of ErrorLogger.SQLErrorLogger)().
Ctor(Of IErrorLogger)("backupErrorLogger").Is(ObjectFactory.GetNamedInstance(Of IErrorLogger)("Disk"))
x.For(Of IErrorLogger).Add(
Function()
Return New ErrorLogger.DiskErrorLogger(
CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))
End Function).Named("Disk")
But it shows this error:
StructureMap Exception Code: 200
Could not find an Instance named "Disk" for PluginType Logging.IErrorLogger
I sort of understand why this is happening.. the question is, how do I utilize a named instance within the registry? Maybe something like lazy initialization for the ctor argument for the SQLErrorLogger? I am not sure how to make it happen.
Thanks in advance for any help you can provide.
I found the correct way to do it in the latest version (2.6.1) of StructureMap:
x.For(Of IErrorLogger).Use(Of ErrorLogger.SQLErrorLogger)().
Ctor(Of IErrorLogger)("backupErrorLogger").Is(
Function(c) c.ConstructedBy(Function() ObjectFactory.GetNamedInstance(Of IErrorLogger)("Disk"))
)
x.For(Of IErrorLogger).Add(Function() _
New ErrorLogger.DiskErrorLogger(
CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))
).Named("Disk")
Notice for the Is method of Ctor, we need to provide a func(IContext), and use the IContext.ConstructedBy(Func()) to call ObjectFactory.Get... to successfully register the IErrorLogger in this case.
This is the only way to do it as far as I know. The other Icontext methods such as IsThis and Instance will only work with already registered type.
Your problem is that you are trying to access the Container before it's configured. In order to make structuremap evaluate the object resolution after the configuration you need to provide a lambda to the Is function. The lambda will be evaluated when trying to resolve the type registered.
x.[For](Of ILogger)().Add(Of SqlLogger)().Ctor(Of ILogger)("backupErrorLogger")_
.[Is](Function(context) context.GetInstance(Of ILogger)("Disk"))
x.[For](Of ILogger)().Add(Of DiskLogger)().Ctor(Of String)("errorFileName")_
.[Is](CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))_
.Named("Disk")
Disclaimer: I'm not completely up-to-date with the lambda syntax in VB.NET, but I hope I got it right.
Edit:
The working C# version of this I tried myself before posting was this:
ObjectFactory.Initialize(i =>
{
i.For<ILogger>().Add<SqlLogger>()
.Ctor<ILogger>("backup").Is(
c => c.GetInstance<ILogger>("disk"))
.Named("sql");
i.For<ILogger>().Add<DiskLogger>().Named("disk");
});
var logger = ObjectFactory.GetNamedInstance<ILogger>("sql");