web3 contract method isn't being called - ethereum

I have the following fragment of code that calls a contract method using web3 and for some reason when Metamask opens up and I click confirm to send the transaction, nothing happens. Metamask just keeps loading and says transaction approved. Also, the callback function isn't being executed. Why is this happening?
contractInstance.buy(price, seller, {
from: web3.eth.accounts[0],
value: price
}, (err, txHash) => {
//do something
})

Related

chrome.scripting.executeScript woes with async functions

I have an MV3 chrome extension on Chrome 106. I want to run an async method with executeScript like this:
async function doSomeWork() {
console.log("starting");
await chrome.runtime.sendMessage({foo: 'bar1'}); // call arbitrary await method
console.log("weird, this is never seen");
// ...do some more work
}
async function doit() {
await chrome.scripting.executeScript({target: {tabId: tab.id}, func: doSomeWork});
}
The documentation seems to imply this should work:
If the resulting value of the script execution is a promise, Chrome
will wait for the promise to settle and return the resulting value.
https://developer.chrome.com/docs/extensions/reference/scripting/#promises
However, the function never continues executing after the first await call. The second log message doesn't show up on the console. The sendMessage works, though.
Am I completely misreading the documentation?
A complete example is available in this git repo: https://github.com/stickfigure/chrome-extension-test/blob/master/src/app.tsx

Ethereum smart contract returns "Fail with error 'AssetContractShared#_requireMintable: ONLY_CREATOR_ALLOWED' " on rinkeby network

I'm trying to test a smart contract function on the rinkeby test network, which migrates multiple tokens to the new contract. I.e. I want to burn ERC-721 tokens (send them to a burn address), which are stored on the Opensea contract, and then remint it on the new contract.
Everything worked fine when I tested the function on a local etherum network fork (with ganache-cli) but on the rinkeby network I get the following error:
errors.js:87 Uncaught (in promise) Error: Transaction has been reverted by the EVM:
{
"blockHash": "0x1b6f3907c56626ed6e66a090fdc5c4e14723fa4be11137227c5fcb20f89a7c8c",
"blockNumber": 9780743,
"contractAddress": null,
"cumulativeGasUsed": 823380,
"effectiveGasPrice": "0x9502f90a",
"from": "0x4e3a2cd1904ba26f9bbcd196802dceec94cf97fd",
"gasUsed": 204890,
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": false,
"to": "0x33a7bbd2f44c012ee19c0e0a9190bb6ba555ffb4",
"transactionHash": "0x8e2cbd9bc333fd56788b51e21568be02a62548468f43ac86859766655818dce1",
"transactionIndex": 6,
"type": "0x2",
"events": {}
}
at Object.TransactionError (errors.js:87)
at Object.TransactionRevertedWithoutReasonError (errors.js:98)
at index.js:395
On Etherscan.io I get this additional error message under 'Status':
Fail with error 'AssetContractShared#_requireMintable: ONLY_CREATOR_ALLOWED'
Here is the smart contract function I'm calling. It works fine when I remove the for loop with the Opensea(openseaSharedAddress).safeTransferFrom(msg.sender, burnAddress, oldIds[j], 1, ""); function
function batchMigration(uint256[] memory oldIds, uint256[] memory newIds, bytes32[] memory leaves, bytes32[][] memory proofs) external {
for (uint i = 0; i < oldIds.length; i++) {
// Don't allow reminting
require(!_exists(newIds[i]), "Token already minted");
// Verify that (oldId, newId) correspond to the Merkle leaf
require(keccak256(abi.encodePacked(oldIds[i], newIds[i])) == leaves[i], "Ids don't match Merkle leaf");
// Verify that (oldId, newId) is a valid pair in the Merkle tree
//require(verify(merkleRoot, leaves[i], proofs[i]), "Not a valid element in the Merkle tree");
// Verify that msg.sender is the owner of the old token
require(Opensea(openseaSharedAddress).balanceOf(msg.sender, oldIds[i]), "Only token owner can mintAndBurn");
}
for (uint j = 0; j < oldIds.length; j++) {
Opensea(openseaSharedAddress).safeTransferFrom(msg.sender, burnAddress, oldIds[j], 1, "");
}
}
And here web3 part where I call the batch migration function:
await smartContract.methods
.batchMigration(oldIds, newIds, leaves, proofs)
.send({
from: walletAddress, //accounts[0]
gasLimit: 6721975,
}).on('transactionHash', function (hash) {
console.log(hash)
});
Before I'm calling the batch migration function I'm setting ApprovalForAll, so this shouldn't be the problem:
await openseaContract.methods.setApprovalForAll(SMART_CONTRACT_ADDRESS, true).send({
from: walletAddress,
});
Has anyone an idea why this error occurs?
Thanks
I was having the same problem and after testing a bit, I could find a solution.
As I've just posted here https://ethereum.stackexchange.com/questions/111077/error-execution-reverted-assetcontractsharedcreatoronly-only-creator-allowed, the contract is calling the minting function before transferring the token. Calling the minting function leads to the call to a modifier, that itself checks the tokenOwner.
The solution is to check if the token has been minted and mint it, before it can be transferred by the other address (that has been approved).
test the balance of the token
if it has no balance, mint it first (from the transferring account)
then you can setApprovalForAll
then the transfer should work

blockchain tutorial Error: The send transactions "from" field must be defined

I am following a blockchain tutorial from dappuniversity.
When I create the task in the line
await App.todoList.createTask(content)
from line
https://github.com/dappuniversity/eth-todo-list/blob/e3ed9a2cefb581c09730250c56c9d30a19cc63c8/src/app.js#L115
I get the following error :
Uncaught (in promise) Error: The send transactions "from" field must be defined!
at Method.inputTransactionFormatter (truffle-contract.js:50747)
at truffle-contract.js:51228
at Array.map (<anonymous>)
at Method.formatInput (truffle-contract.js:51226)
at Method.toPayload (truffle-contract.js:51261)
at Eth.send [as sendTransaction] (truffle-contract.js:51551)
Do I need to define a 'from' field somewhere?
With the latest dependencies, none of the above answers were working for me.
I had to edit the loadAccount method:
loadAccount: async () => {
// Set the current blockchain account
const accounts = await web3.eth.getAccounts();
App.account = accounts[0];
},
then pass the App's account to the createTask method: await App.todoList.createTask(content, { from: App.account })
I was running into issues with the above answer which appears due to recent Metamask updates and that moving from web3.currentProvider to window.ethereum
I was able to make this work using
await App.todoList.createTask(content, {from: App.account})
I am using the latest truffle/contract. I needed to specify the from account in my createTask method like the following:
await App.todoList.createTask(content, { from: web3.eth.defaultAccount})
This worked.
Same happened to me on Remix while interacting with the contract deployed on Rinkeby. I chose injected web3 for the environment, But account field was empty.
It happended because I rejected the connection to metamask first and then did not get any other request to connect with metamask. So I refreshed remix, locked and unlocked metamask. It sent request to connect to metamask

Authenticating on github using featherjs results in a strange behavior

I'm trying to authenticate using github.
I configured properly the callback, successRedirect and failureRedirect.
The successRedirect page is called. In this page I try to call the authenticate function.
client.authenticate({
strategy: 'github'
})
The promise resolve with a token but when I try to access a secured service, it returns an error. Then If I try to retry to access a second time to the service, it works.
Can someone explain me or provide me a working example.
My code:
const hello = client.service('hello');
function getVal(iter) {
console.log("Iter " + iter)
hello.get(1, {}).then((data) => {
console.log('User is logged');
console.dir(data)
}, (error) => {
console.dir(error)
getVal(iter + 1)
})
}
client.authenticate({
strategy: 'github'
}).then((token) => {
console.dir(token)
getVal(0)
}, (error) => console.dir(error));
In the logs I see that the first call to the service fails with an authentication error but not the second while I'm supposed to be logged (because it's in the configured success redirection)
My logs:
Object { accessToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2…" }
Iter 0
{
className: "not-authenticated"
code: 401
……
}
Iter 1
User is logged
{…}
The oAuth2 client usage API shows that instead of calling authenticate you just have to link the user to /auth/github to kick of the oAuth flow:
Login With GitHub

What does d3js.csv.get() do?

I'm learning d3js. I came across an example for extracting CSV values here. I'm quoting the code:
d3.csv("path/to/file.csv")
.row(function(d) { return {key: d.key, value: +d.value}; })
.get(function(error, rows) { console.log(rows); });
From the description, I get that .row() is the accessor here. But the role of the .get() is not clear to me. When is this function called, and for what purpose ? Thanks.
The .get() is a function of the underlying AJAX request -- it sends the request and establishes the callback. From the documentation:
xhr.get([callback])
Issues this request using the GET method. If a callback is specified, it will be invoked asynchronously when the request is done or errors; the callback is invoked with two arguments: the error, if any, and the response value.